test(6838): give the test request its socket peer the way Quart reads it
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 12s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 1m38s
CI & Build / integration (push) Successful in 2m16s
CI & Build / Build & push image (push) Successful in 38s

Quart takes remote_addr from a Remote-Addr header its ASGI layer writes from
the scope (replacing any the client sent). A test request context does not
read scope_base for it, so the two socket-peer tests saw an empty address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-04 19:37:28 -05:00
co-authored by Claude Opus 5.5
parent dbd6d5b8b5
commit 3c01e17559
+5 -6
View File
@@ -50,9 +50,10 @@ def _app() -> Quart:
def _context(app, headers=None, scheme="http"): def _context(app, headers=None, scheme="http"):
# Quart's ASGI layer writes the socket peer into a Remote-Addr header,
# replacing any the client sent; a test request context takes it as given.
return app.test_request_context( return app.test_request_context(
"/", headers=headers or {}, scheme=scheme, "/", headers={"Remote-Addr": PEER, **(headers or {})}, scheme=scheme,
scope_base={"client": (PEER, 40000)},
) )
@@ -76,10 +77,8 @@ async def test_no_header_reads_the_socket_peer(monkeypatch):
async def test_a_header_sent_twice_is_read_as_one_chain(monkeypatch): async def test_a_header_sent_twice_is_read_as_one_chain(monkeypatch):
monkeypatch.setattr(Config, "TRUSTED_PROXY_HOPS", 1) monkeypatch.setattr(Config, "TRUSTED_PROXY_HOPS", 1)
headers = [("X-Forwarded-For", FORGED), ("X-Forwarded-For", CLIENT)] headers = [("Remote-Addr", PEER), ("X-Forwarded-For", FORGED), ("X-Forwarded-For", CLIENT)]
async with _app().test_request_context( async with _app().test_request_context("/", headers=headers):
"/", headers=headers, scope_base={"client": (PEER, 40000)},
):
assert client_ip() == CLIENT assert client_ip() == CLIENT