Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(warehouse-sources): name the blank ssh tunnel field (#103478)

posthog[bot]8dae9a865340
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/mixins.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/mixins.py
index 1a8c5929069e..62981210b5eb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/mixins.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/mixins.py
@@ -659,10 +659,20 @@ class SSHTunnelMixin:
def ssh_tunnel_is_valid(self, config, team_id: int) -> tuple[bool, str | None]:
if hasattr(config, "ssh_tunnel") and config.ssh_tunnel and config.ssh_tunnel.enabled:
- if config.ssh_tunnel.host:
- is_host_valid, host_errors = _is_host_safe(config.ssh_tunnel.host, team_id)
- if not is_host_valid:
- return False, f"SSH tunnel host not allowed: {host_errors}"
+ # `SSHTunnel.from_config` asserts on host, port and auth type. A bare `AssertionError`
+ # has no message, so the caller can only show generic invalid-credentials copy.
+ if not config.ssh_tunnel.host:
+ return False, "SSH tunnel host is required"
+
+ is_host_valid, host_errors = _is_host_safe(config.ssh_tunnel.host, team_id)
+ if not is_host_valid:
+ return False, f"SSH tunnel host not allowed: {host_errors}"
+
+ if not config.ssh_tunnel.port:
+ return False, "SSH tunnel port is required"
+
+ if not config.ssh_tunnel.auth.type:
+ return False, "SSH tunnel authentication type is required"
ssh_tunnel = SSHTunnel.from_config(config.ssh_tunnel)
is_auth_valid, auth_errors = ssh_tunnel.is_auth_valid()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test_mixins.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test_mixins.py
index f2f819035b8b..bbbdba9457b0 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test_mixins.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test_mixins.py
@@ -1,5 +1,5 @@
import socket
-from dataclasses import dataclass
+from dataclasses import dataclass, field
import pytest
from unittest import mock
@@ -10,6 +10,7 @@ from django.test import SimpleTestCase, override_settings
from parameterized import parameterized
+from posthog.dataclasses import frozen
from posthog.models.integration import Integration
from posthog.temporal.common.errors import NonReportableError
@@ -306,11 +307,19 @@ class TestValidateDatabaseHostMixin(SimpleTestCase):
assert valid
-@dataclass
+@frozen
+class FakeSSHTunnelAuthConfig:
+ type: str | None = "password"
+ username: str | None = "user"
+ password: str | None = "pass"
+
+
+@frozen
class FakeSSHTunnelConfig:
enabled: bool
host: str
- port: int = 22
+ port: int | None = 22
+ auth: FakeSSHTunnelAuthConfig = field(default_factory=FakeSSHTunnelAuthConfig)
@dataclass
@@ -357,6 +366,23 @@ class TestSSHTunnelHostValidation(SimpleTestCase):
valid, _ = mixin.ssh_tunnel_is_valid(config, team_id=999)
assert not valid
+ # A blank field must not reach `SSHTunnel.from_config`, whose asserts raise a message-less
+ # `AssertionError` that the caller can only report as invalid credentials.
+ @parameterized.expand(
+ [
+ ("blank_host", {"host": ""}, "host is required"),
+ ("blank_port", {"port": None}, "port is required"),
+ ("blank_auth_type", {"auth": FakeSSHTunnelAuthConfig(type=None)}, "authentication type is required"),
+ ]
+ )
+ @override_settings(CLOUD_DEPLOYMENT="US")
+ def test_blank_tunnel_field_is_named(self, _name: str, overrides: dict, expected: str):
+ mixin = SSHTunnelMixin()
+ tunnel = FakeSSHTunnelConfig(**{"enabled": True, "host": "8.8.8.8", **overrides})
+ valid, error = mixin.ssh_tunnel_is_valid(FakeConfig(ssh_tunnel=tunnel), team_id=999)
+ assert not valid
+ assert expected in error # type: ignore
+
class TestConnectionOpenLogging(SimpleTestCase):
def test_direct_connection_logs_open_event(self):