Skip to content

The agent that grows with you

test(ssl): assert the platform_ssl_context contract in the ssl_verify tests

kshitijk4poore11be46b84dc
diff --git a/tests/agent/test_ssl_verify.py b/tests/agent/test_ssl_verify.py
index 983a0f1b252..41f3d1b7994 100644
--- a/tests/agent/test_ssl_verify.py
+++ b/tests/agent/test_ssl_verify.py
@@ -28,14 +28,27 @@ def test_missing_explicit_bundle_falls_back_to_the_platform_store(tmp_path, capl
def test_missing_bundle_under_a_cert_env_var_shares_the_platform_context(tmp_path, monkeypatch):
"""With SSL_CERT_FILE exported the platform store is handed over as one
shared context (httpx would otherwise read the env var itself); a missing
- bundle must land on that same object, not a second pool."""
+ bundle must land on that same object, not a second pool. The long-lived
+ clients' platform_ssl_context() honours the bundle ON TOP of the platform
+ store (as httpx verify=True did), cached once."""
+ import ssl
+
import certifi
+ from agent import ssl_verify
+
+ monkeypatch.setattr(ssl_verify, "_CA_CONTEXTS", {})
monkeypatch.setenv("SSL_CERT_FILE", certifi.where())
platform = resolve_httpx_verify()
assert platform is not True
assert resolve_httpx_verify(ca_bundle=str(tmp_path / "nope.pem")) is platform
+ bundle_ctx = ssl_verify.platform_ssl_context()
+ assert bundle_ctx is ssl_verify.platform_ssl_context()
+ assert bundle_ctx is not platform
+ assert type(bundle_ctx) is ssl.SSLContext # truststore-injected: bundle + OS store
+ assert getattr(bundle_ctx, "_ctx", bundle_ctx).cert_store_stats()["x509_ca"] > 0
+
@pytest.mark.parametrize("value", [False, "false", "0", "no", "off", "FALSE"])
def test_insecure_disables_verification(value):
diff --git a/tests/gateway/test_telegram_closewait_limits.py b/tests/gateway/test_telegram_closewait_limits.py
index adbf8d5205f..89583b84b6a 100644
--- a/tests/gateway/test_telegram_closewait_limits.py
+++ b/tests/gateway/test_telegram_closewait_limits.py
@@ -176,18 +176,6 @@ def test_all_ptb_clients_share_the_platform_ssl_context(monkeypatch):
pass
assert seen.get("verify") is shared
- # An SSL_CERT_FILE bundle is honoured ON TOP of the platform store (as httpx
- # verify=True did) and still cached once.
- import certifi
- from agent import ssl_verify
- monkeypatch.setattr(ssl_verify, "_CA_CONTEXTS", {})
- monkeypatch.setenv("SSL_CERT_FILE", certifi.where())
- bundle_ctx = ssl_verify.platform_ssl_context()
- assert bundle_ctx is ssl_verify.platform_ssl_context()
- assert bundle_ctx is not ssl_verify._shared_context(None)
- assert type(bundle_ctx) is ssl.SSLContext # truststore-injected: bundle + OS store
- assert bundle_ctx._ctx.cert_store_stats()["x509_ca"] > 0
-
def test_proxy_branch_general_pool_has_tight_keepalive(monkeypatch):
"""The proxy path the #31599 reporter hit must wire tuned limits."""