Skip to content

The agent that grows with you

test(auth): rotate the real certifi package in the Nous credential test

kshitijk4poor82a8cef840b5
diff --git a/tests/hermes_cli/test_auth_nous_provider.py b/tests/hermes_cli/test_auth_nous_provider.py
index 556aa4ecfc9..76721008612 100644
--- a/tests/hermes_cli/test_auth_nous_provider.py
+++ b/tests/hermes_cli/test_auth_nous_provider.py
@@ -84,43 +84,11 @@ class TestResolveVerifyFallback:
assert result is False
-def _rotate_certifi_out_from_under_the_process(tmp_path: Path, monkeypatch) -> None:
- """Import certifi from ``env-a``, then delete the directory it lives in.
-
- The package manager's environment rotation without a package manager: the replacement
- ``env-b`` is what the next lookup finds, exactly as the new install generation would be.
- """
- import importlib
- import shutil
- import sys
-
- import certifi as real_certifi
-
- bundle = Path(real_certifi.where()).read_bytes()
- for name in ("env-a", "env-b"):
- package = tmp_path / name / "certifi"
- package.mkdir(parents=True)
- (package / "__init__.py").write_text(
- "import os\n\n\ndef where():\n"
- " return os.path.join(os.path.dirname(__file__), 'cacert.pem')\n")
- (package / "cacert.pem").write_bytes(bundle)
- monkeypatch.syspath_prepend(str(tmp_path / "env-b"))
- monkeypatch.syspath_prepend(str(tmp_path / "env-a"))
- monkeypatch.delitem(sys.modules, "certifi", raising=False)
- importlib.invalidate_caches()
- stand_in = importlib.import_module("certifi")
- monkeypatch.setitem(sys.modules, "certifi", stand_in)
- assert Path(stand_in.where()).parent == tmp_path / "env-a" / "certifi"
- shutil.rmtree(tmp_path / "env-a")
- assert not Path(stand_in.where()).exists()
-
-
class TestDefaultVerifyAfterAnInstallRotation:
"""The Nous credential exchange can be the first TLS client a long-lived gateway builds
after the package manager replaced the environment certifi was imported from (#137255).
- On macOS that stand pinned ``certifi.where()`` directly, so it kept handing over the
- deleted bundle and every credential refresh failed until the gateway was restarted.
+ It must never hand httpx a bundle path that no longer exists.
"""
@pytest.mark.platforms("macos")
@@ -131,16 +99,17 @@ class TestDefaultVerifyAfterAnInstallRotation:
for var in ("HERMES_CA_BUNDLE", "SSL_CERT_FILE", "REQUESTS_CA_BUNDLE"):
monkeypatch.delenv(var, raising=False)
- _rotate_certifi_out_from_under_the_process(tmp_path, monkeypatch)
+ from tests.agent.test_ssl_verify import _rotated_certifi
+
+ _rotated_certifi(tmp_path, monkeypatch, replacement=True)
verify = _resolve_verify(auth_state={"tls": {"insecure": False}})
- # Nothing in the process points at the deleted environment any more, and the value
- # handed to httpx builds a client (it raised FileNotFoundError before the fix).
+ # Nothing in the process points at the deleted environment, and httpx builds a client.
import certifi
assert Path(certifi.where()).is_file()
- with httpx.Client(verify=verify) as client: # the construction that raised before the fix
+ with httpx.Client(verify=verify) as client:
from typing import Any, cast
transport = cast(Any, client._transport)