Skip to content

Commit 9ca6c10

Browse files
committed
fix(cli): use system trust for public HTTPS
1 parent dbec5dd commit 9ca6c10

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/agentnet/cli/commands/diagnostics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import shutil
1010
import subprocess
1111
import sys
12+
import ssl
1213
import tempfile
1314
from datetime import UTC, datetime, timedelta
1415
from pathlib import Path
@@ -330,6 +331,7 @@ def command_status(args: argparse.Namespace) -> int:
330331
base_url=config.public_base_url,
331332
timeout=args.timeout,
332333
follow_redirects=False,
334+
verify=ssl.create_default_context(),
333335
) as client:
334336
health = client.get("/healthz")
335337
readiness = client.get("/readyz")

src/agentnet/cli/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import json
99
import os
1010
import secrets
11+
import ssl
1112
import stat
1213
from contextlib import contextmanager
1314
from pathlib import Path
@@ -479,9 +480,10 @@ def _public_json_request(
479480
headers={"Content-Type": "application/json"},
480481
timeout=timeout,
481482
follow_redirects=False,
483+
verify=ssl.create_default_context(),
482484
)
483485
except httpx.HTTPError as exc:
484-
raise SystemExit(f"AgentNet server request failed: {type(exc).__name__}") from exc
486+
raise SystemExit(f"AgentNet server request failed: {type(exc).__name__}: {exc}") from exc
485487
if response.status_code < 200 or response.status_code >= 300:
486488
raise SystemExit(f"AgentNet server rejected the request with HTTP {response.status_code}")
487489
try:

tests/cli/test_cli_diagnostics.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import os
55
import subprocess
6+
import ssl
67
from pathlib import Path
78
from types import SimpleNamespace
89

@@ -11,6 +12,7 @@
1112
from agentnet import __version__
1213
from agentnet import cli
1314
from agentnet.cli.commands import diagnostics
15+
from agentnet.cli import helpers
1416

1517

1618
def test_top_level_version_is_available(capsys: pytest.CaptureFixture[str]) -> None:
@@ -20,6 +22,30 @@ def test_top_level_version_is_available(capsys: pytest.CaptureFixture[str]) -> N
2022
assert stopped.value.code == 0
2123
assert capsys.readouterr().out == f"agentnet {__version__}\n"
2224

25+
def test_public_cli_requests_use_system_tls_context(
26+
monkeypatch: pytest.MonkeyPatch,
27+
) -> None:
28+
observed: dict[str, object] = {}
29+
30+
def request(method: str, url: str, **kwargs: object) -> SimpleNamespace:
31+
observed.update({"method": method, "url": url, **kwargs})
32+
return SimpleNamespace(status_code=200, json=lambda: {"status": "alive"})
33+
34+
monkeypatch.setattr(helpers.httpx, "request", request)
35+
36+
result = helpers._public_json_request(
37+
server="https://core.example",
38+
method="GET",
39+
path="/healthz",
40+
body={},
41+
)
42+
43+
context = observed["verify"]
44+
assert isinstance(context, ssl.SSLContext)
45+
assert context.check_hostname is True
46+
assert context.verify_mode == ssl.CERT_REQUIRED
47+
assert result == {"status": "alive"}
48+
2349
def test_verify_finds_source_root_after_module_moves(
2450
monkeypatch: pytest.MonkeyPatch,
2551
) -> None:

0 commit comments

Comments
 (0)