The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(dashboard-auth): type the forwarded-header regression tests
unsupportedpastels3fd7cc773111
diff --git a/tests/hermes_cli/test_dashboard_auth_native_flow.py b/tests/hermes_cli/test_dashboard_auth_native_flow.pyindex 63d4e0b6f62..564fbb4fbb6 100644--- a/tests/hermes_cli/test_dashboard_auth_native_flow.py+++ b/tests/hermes_cli/test_dashboard_auth_native_flow.py@@ -229,8 +229,8 @@ def _native_authorize_params(challenge, **overrides):@pytest.mark.parametrize("forwarded_template", ["198.51.100.{i}", ", 198.51.100.{i}"],ids=["rotated-address", "empty-first-hop"])def test_native_authorize_spoofed_forwarded_headers_cannot_bypass_pending_cap(- gated_client, forwarded_template,-):+ gated_client: TestClient, forwarded_template: str,+) -> None:# The public OAuth entry point must limit one peer before allocating the# global pending store, even when XFF rotates or has an empty first hop._verifier, challenge = _make_pkce()@@ -251,7 +251,7 @@ def test_native_authorize_spoofed_forwarded_headers_cannot_bypass_pending_cap(# Exhausting one peer's allowance must leave room for another real peer.other_client = TestClient(- web_server.app, base_url=gated_client.base_url,+ web_server.app, base_url=str(gated_client.base_url),client=("203.0.113.10", 50000), follow_redirects=False,)assert other_client.get("/auth/native/authorize", params=params).status_code == 302diff --git a/tests/hermes_cli/test_dashboard_auth_password_login.py b/tests/hermes_cli/test_dashboard_auth_password_login.pyindex 695850808f2..890f42b075f 100644--- a/tests/hermes_cli/test_dashboard_auth_password_login.py+++ b/tests/hermes_cli/test_dashboard_auth_password_login.py@@ -341,15 +341,15 @@ class TestRateLimit:ids=["direct", "loopback-proxy", "configured-proxy"],)def test_spoofed_x_forwarded_for_does_not_reset_rate_limit(- self, gated_app, peer, forwarded_suffix,- ):+ self: TestRateLimit, gated_app: TestClient, peer: str, forwarded_suffix: str,+ ) -> None:# X-Forwarded-For is attacker-controlled unless it came from a trusted# reverse proxy. Even behind an appending proxy, the client-supplied# first hop must not override Uvicorn's resolved client address.trusted = _dashboard_forwarded_allow_ips({"trusted_proxies": ["172.18.0.0/16"]})# Uvicorn and Starlette expose incompatible static ASGI type aliases.app = cast(Any, ProxyHeadersMiddleware(cast(Any, web_server.app), trusted_hosts=trusted))- client = TestClient(app, base_url=gated_app.base_url, client=(peer, 50000))+ client = TestClient(app, base_url=str(gated_app.base_url), client=(peer, 50000))for i in range(_PW_RATE_MAX_ATTEMPTS):resp = client.post("/auth/password-login",@@ -368,7 +368,7 @@ class TestRateLimit:# Another real client must retain its own budget, including when both# clients reach the dashboard through the same trusted proxy.other_peer = peer if forwarded_suffix else "203.0.113.10"- other_client = TestClient(app, base_url=gated_app.base_url, client=(other_peer, 50001))+ other_client = TestClient(app, base_url=str(gated_app.base_url), client=(other_peer, 50001))allowed = other_client.post("/auth/password-login",headers={"X-Forwarded-For": "203.0.113.10"},@@ -378,7 +378,7 @@ class TestRateLimit:@pytest.mark.parametrize("peer", [("203.0.113.7", 12345), None])-def test_client_ip_uses_asgi_peer_not_forwarded_header(peer):+def test_client_ip_uses_asgi_peer_not_forwarded_header(peer: tuple[str, int] | None) -> None:from fastapi import Requestfrom hermes_cli.dashboard_auth.request_utils import client_ip