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(apple-search-ads): keep the crypto library's PEM error out of the setup form (#94954)

Tom Owers1e7980d33109
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/apple_search_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/apple_search_ads.py
index 28ebe864904d..cb8bf1aa4456 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/apple_search_ads.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/apple_search_ads.py
@@ -122,9 +122,11 @@ def build_client_secret(credentials: AppleSearchAdsCredentials, *, issued_at: Op
headers={"alg": "ES256", "kid": credentials.key_id},
)
except (jwt.PyJWTError, ValueError, TypeError) as e:
+ # The cryptography backend's own text names its PEM framing internals and links its FAQ,
+ # neither of which helps someone in the setup form — keep it on the chained cause only.
raise AppleSearchAdsAuthError(
"Could not sign the Apple Ads client secret. The private key must be the unencrypted "
- f"EC (P-256) PEM generated for your Apple Ads API client: {e}"
+ "EC (P-256) PEM generated for your Apple Ads API client."
) from e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads.py
index 38b0adc4b863..f834c0f7032c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads.py
@@ -264,9 +264,17 @@ class TestAppleSearchAdsTransport:
]
)
def test_client_secret_rejects_an_unusable_private_key(self, _name: str, private_key: str) -> None:
- with pytest.raises(AppleSearchAdsAuthError):
+ with pytest.raises(AppleSearchAdsAuthError) as raised:
build_client_secret(_with_key(private_key))
+ # `validate_credentials` shows this string in the setup form, so it must not carry the
+ # crypto backend's own wording. The cause still has it for error tracking.
+ message = str(raised.value)
+ assert "unencrypted EC (P-256) PEM" in message
+ assert "cryptography.io" not in message
+ assert "PEM file" not in message
+ assert raised.value.__cause__ is not None
+
@parameterized.expand([(V5, "orgId=555"), (V1, "adAccountId=123456789")])
def test_requests_carry_the_bearer_token_and_the_versions_context_id(
self, api_version: str, expected_context: str