: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(tests): run source config checks without a database (#113626)
Raúl Negrón-Otero43274aac5980
diff --git a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt b/posthog/test/repo_invariants/database_free_test_classes_baseline.txtindex 9a56bbcc4d84..276839f7e2e3 100644--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt@@ -366,7 +366,6 @@ products/tasks/backend/tests/test_repository_readiness.py::TestSelectCandidatePaproducts/tasks/backend/tests/test_repository_readiness.py::TestShouldScanPathproducts/tasks/backend/tests/test_webhooks.py::TestAccountTypeproducts/warehouse_sources/backend/tests/api/test_external_data_source.py::TestGetOAuthIntegrationKinds-products/warehouse_sources/backend/tests/api/test_external_data_source.py::TestSensitiveFieldClassificationproducts/web_analytics/backend/hogql_queries/test/test_custom_bot_definitions.py::TestPatternsCompileproducts/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.py::TestComputeFiltersEligibilityHashproducts/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.py::TestComputeShapeCapKeydiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_source_catalog_invariants.py b/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_source_catalog_invariants.pyindex 411d3bb763ce..2a009f60f6da 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_source_catalog_invariants.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_source_catalog_invariants.py@@ -7,7 +7,16 @@ from django.conf import settingsfrom django.test import override_settingsimport products.warehouse_sources.backend.temporal.data_imports.sources._load_all # noqa: F401-from products.warehouse_sources.backend.facade.source_config import SourceFieldInputConfig+from products.warehouse_sources.backend.facade.source_config import (+ SourceFieldInputConfig,+ SourceFieldInputConfigType,+ SourceFieldSelectConfig,+ SourceFieldSwitchGroupConfig,+)+from products.warehouse_sources.backend.presentation.views.external_data_source.helpers import (+ get_nonsensitive_and_sensitive_field_names,+)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldTypefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.mixins import ValidateDatabaseHostMixinfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.registry import SourceRegistry@@ -258,3 +267,86 @@ def test_source_icon_file_exists(source_type):f"frontend/public. Every catalog tile for it would request a 404 and fall back to the "f"placeholder icon. Add the file, or correct the path.")+++def test_all_registered_sources_have_valid_classification() -> None:+ for source in ALL_SOURCES.values():+ config = source.get_source_config+ split = get_nonsensitive_and_sensitive_field_names(config.fields)++ overlap = split.nonsensitive & split.sensitive+ assert not overlap, f"{config.name}: fields in both sets: {overlap}"+++def test_password_typed_fields_must_be_marked_secret() -> None:+ def collect_password_fields_without_secret(fields: list[FieldType]) -> list[str]:+ offenders: list[str] = []+ for field in fields:+ if isinstance(field, SourceFieldInputConfig):+ if field.type == SourceFieldInputConfigType.PASSWORD and not field.secret:+ offenders.append(field.name)+ elif isinstance(field, SourceFieldSwitchGroupConfig):+ offenders.extend(collect_password_fields_without_secret(field.fields))+ elif isinstance(field, SourceFieldSelectConfig):+ for option in field.options:+ if option.fields:+ offenders.extend(collect_password_fields_without_secret(option.fields))+ return offenders++ all_offenders: dict[str, list[str]] = {}+ for source in ALL_SOURCES.values():+ config = source.get_source_config+ offenders = collect_password_fields_without_secret(config.fields)+ if offenders:+ all_offenders[config.name] = offenders++ assert not all_offenders, (+ f"PASSWORD-typed fields must also set secret=True to be redacted from API responses. "+ f"Offending fields: {all_offenders}"+ )+++def test_dynamic_classification_covers_old_hardcoded_allowlist() -> None:+ old_allowed = {+ "stripe_account_id",+ "database",+ "host",+ "port",+ "user",+ "schema",+ "ssh_tunnel",+ "using_ssl",+ "region",+ "site_name",+ "subdomain",+ "email_address",+ "hubspot_integration_id",+ "custom_properties",+ "account_id",+ "warehouse",+ "role",+ "dataset_id",+ "temporary-dataset",+ "dataset_project",+ "customer_id",+ "google_ads_integration_id",+ "is_mcc_account",+ "spreadsheet_url",+ "linkedin_ads_integration_id",+ "meta_ads_integration_id",+ "sync_lookback_days",+ "reddit_integration_id",+ "salesforce_integration_id",+ "repository",+ "shopify_store_id",+ "namespace",+ }++ all_nonsensitive: set[str] = set()+ for source in ALL_SOURCES.values():+ config = source.get_source_config+ split = get_nonsensitive_and_sensitive_field_names(config.fields)+ all_nonsensitive.update(split.nonsensitive)++ missing = old_allowed - all_nonsensitive+ assert not missing, f"Old allowlist fields not covered by dynamic classification: {missing}"diff --git a/products/warehouse_sources/backend/tests/api/test_external_data_source.py b/products/warehouse_sources/backend/tests/api/test_external_data_source.pyindex 5667708466ff..c32575a6fe85 100644--- a/products/warehouse_sources/backend/tests/api/test_external_data_source.py+++ b/products/warehouse_sources/backend/tests/api/test_external_data_source.py@@ -9853,7 +9853,6 @@ class TestCreateWebhook(APIBaseTest):# that a partial update which omits one required field is accepted while still# preserving the existing value on the HogFunction.from products.warehouse_sources.backend.facade.types import ExternalDataSourceType- from products.warehouse_sources.backend.temporal.data_imports.sources import SourceRegistryoriginal_source = SourceRegistry.get_source(ExternalDataSourceType("Stripe"))original_config = original_source.get_source_config@@ -9994,7 +9993,7 @@ class TestCreateWebhook(APIBaseTest):assert hog_function.inputs["source_id"]["value"] == str(source.pk)-class TestSensitiveFieldClassification(APIBaseTest):+class TestSensitiveFieldClassification(SimpleTestCase):def test_classifies_password_fields_as_sensitive(self):fields: list[FieldType] = [SourceFieldInputConfig(@@ -10247,94 +10246,6 @@ class TestSensitiveFieldClassification(APIBaseTest):assert result["temporary-dataset"]["temporary_dataset_id"] == "declared"assert "temporary_dataset" not in result- def test_all_registered_sources_have_valid_classification(self):- for source in SourceRegistry.get_all_sources().values():- config = source.get_source_config- split = get_nonsensitive_and_sensitive_field_names(config.fields)-- # No field should appear in both sets- overlap = split.nonsensitive & split.sensitive- assert not overlap, f"{config.name}: fields in both sets: {overlap}"-- def test_password_typed_fields_must_be_marked_secret(self):- """A field rendered as type=PASSWORD that is not also `secret=True` is a misconfiguration:- it would obscure on screen but still be returned in plain text from the API.- """-- def collect_password_fields_without_secret(fields: list[FieldType]) -> list[str]:- offenders: list[str] = []- for field in fields:- if isinstance(field, SourceFieldInputConfig):- if field.type == SourceFieldInputConfigType.PASSWORD and not field.secret:- offenders.append(field.name)- elif isinstance(field, SourceFieldSwitchGroupConfig):- offenders.extend(collect_password_fields_without_secret(field.fields))- elif isinstance(field, SourceFieldSelectConfig):- for option in field.options:- if option.fields:- offenders.extend(collect_password_fields_without_secret(option.fields))- return offenders-- all_offenders: dict[str, list[str]] = {}- for source in SourceRegistry.get_all_sources().values():- config = source.get_source_config- offenders = collect_password_fields_without_secret(config.fields)- if offenders:- all_offenders[config.name] = offenders-- assert not all_offenders, (- f"PASSWORD-typed fields must also set secret=True to be redacted from API responses. "- f"Offending fields: {all_offenders}"- )-- def test_dynamic_classification_covers_old_hardcoded_allowlist(self):- """Regression: all fields from the old hardcoded allowlist should be in the dynamic nonsensitive set."""-- old_allowed = {- "stripe_account_id",- "database",- "host",- "port",- "user",- "schema",- "ssh_tunnel",- "using_ssl",- "region",- "site_name",- "subdomain",- "email_address",- "hubspot_integration_id",- "custom_properties",- "account_id",- "warehouse",- "role",- "dataset_id",- "temporary-dataset",- "dataset_project",- "customer_id",- "google_ads_integration_id",- "is_mcc_account",- "spreadsheet_url",- "linkedin_ads_integration_id",- "meta_ads_integration_id",- "sync_lookback_days",- "reddit_integration_id",- "salesforce_integration_id",- "repository",- "shopify_store_id",- "namespace",- }-- # Collect all nonsensitive field names across all sources- all_nonsensitive: set[str] = set()- for source in SourceRegistry.get_all_sources().values():- config = source.get_source_config- split = get_nonsensitive_and_sensitive_field_names(config.fields)- all_nonsensitive.update(split.nonsensitive)-- missing = old_allowed - all_nonsensitive- assert not missing, f"Old allowlist fields not covered by dynamic classification: {missing}"-class TestWebhookInfo(APIBaseTest):def _create_stripe_source(self, job_inputs=None) -> ExternalDataSource: