b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
91 lines
3.5 KiB
Python
91 lines
3.5 KiB
Python
"""Tests for _resolve_requests_verify() env var precedence.
|
|
|
|
Verifies that custom provider `/models` fetches honour the three supported
|
|
CA bundle env vars (HERMES_CA_BUNDLE, REQUESTS_CA_BUNDLE, SSL_CERT_FILE)
|
|
in the documented priority order, and that non-existent paths are
|
|
skipped gracefully rather than breaking the request.
|
|
|
|
No filesystem or network I/O required — we use tmp_path to create real
|
|
CA bundle stand-in files and monkeypatch env vars.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
import pytest
|
|
|
|
from agent.model_metadata import _resolve_requests_verify
|
|
|
|
|
|
_CA_ENV_VARS = ("HERMES_CA_BUNDLE", "REQUESTS_CA_BUNDLE", "SSL_CERT_FILE")
|
|
|
|
|
|
@pytest.fixture
|
|
def clean_env(monkeypatch):
|
|
"""Clear all three SSL env vars so each test starts from a known state."""
|
|
for var in _CA_ENV_VARS:
|
|
monkeypatch.delenv(var, raising=False)
|
|
return monkeypatch
|
|
|
|
|
|
@pytest.fixture
|
|
def bundle_file(tmp_path: Path) -> str:
|
|
"""Create a placeholder CA bundle file and return its absolute path."""
|
|
path = tmp_path / "ca.pem"
|
|
path.write_text("-----BEGIN CERTIFICATE-----\nstub\n-----END CERTIFICATE-----\n")
|
|
return str(path)
|
|
|
|
|
|
class TestResolveRequestsVerify:
|
|
def test_no_env_returns_true(self, clean_env):
|
|
assert _resolve_requests_verify() is True
|
|
|
|
def test_hermes_ca_bundle_returns_path(self, clean_env, bundle_file):
|
|
clean_env.setenv("HERMES_CA_BUNDLE", bundle_file)
|
|
assert _resolve_requests_verify() == bundle_file
|
|
|
|
def test_requests_ca_bundle_returns_path(self, clean_env, bundle_file):
|
|
clean_env.setenv("REQUESTS_CA_BUNDLE", bundle_file)
|
|
assert _resolve_requests_verify() == bundle_file
|
|
|
|
def test_ssl_cert_file_returns_path(self, clean_env, bundle_file):
|
|
clean_env.setenv("SSL_CERT_FILE", bundle_file)
|
|
assert _resolve_requests_verify() == bundle_file
|
|
|
|
def test_priority_hermes_over_requests(self, clean_env, tmp_path, bundle_file):
|
|
other = tmp_path / "other.pem"
|
|
other.write_text("stub")
|
|
clean_env.setenv("HERMES_CA_BUNDLE", bundle_file)
|
|
clean_env.setenv("REQUESTS_CA_BUNDLE", str(other))
|
|
assert _resolve_requests_verify() == bundle_file
|
|
|
|
def test_priority_requests_over_ssl_cert_file(self, clean_env, tmp_path, bundle_file):
|
|
other = tmp_path / "other.pem"
|
|
other.write_text("stub")
|
|
clean_env.setenv("REQUESTS_CA_BUNDLE", bundle_file)
|
|
clean_env.setenv("SSL_CERT_FILE", str(other))
|
|
assert _resolve_requests_verify() == bundle_file
|
|
|
|
def test_nonexistent_path_falls_through(self, clean_env, tmp_path, bundle_file):
|
|
missing = tmp_path / "does_not_exist.pem"
|
|
clean_env.setenv("HERMES_CA_BUNDLE", str(missing))
|
|
clean_env.setenv("REQUESTS_CA_BUNDLE", bundle_file)
|
|
assert _resolve_requests_verify() == bundle_file
|
|
|
|
def test_all_nonexistent_returns_true(self, clean_env, tmp_path):
|
|
missing1 = tmp_path / "a.pem"
|
|
missing2 = tmp_path / "b.pem"
|
|
missing3 = tmp_path / "c.pem"
|
|
clean_env.setenv("HERMES_CA_BUNDLE", str(missing1))
|
|
clean_env.setenv("REQUESTS_CA_BUNDLE", str(missing2))
|
|
clean_env.setenv("SSL_CERT_FILE", str(missing3))
|
|
assert _resolve_requests_verify() is True
|
|
|
|
def test_empty_string_env_var_ignored(self, clean_env, bundle_file):
|
|
clean_env.setenv("HERMES_CA_BUNDLE", "")
|
|
clean_env.setenv("REQUESTS_CA_BUNDLE", bundle_file)
|
|
assert _resolve_requests_verify() == bundle_file
|