From 3c01e17559f6f41bffddb5eec927229553465961 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 4 Nov 2026 19:37:28 -0500 Subject: [PATCH] test(6838): give the test request its socket peer the way Quart reads it 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 --- tests/test_proxy.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_proxy.py b/tests/test_proxy.py index 63905783..366cc641 100644 --- a/tests/test_proxy.py +++ b/tests/test_proxy.py @@ -50,9 +50,10 @@ def _app() -> Quart: 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( - "/", headers=headers or {}, scheme=scheme, - scope_base={"client": (PEER, 40000)}, + "/", headers={"Remote-Addr": PEER, **(headers or {})}, scheme=scheme, ) @@ -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): monkeypatch.setattr(Config, "TRUSTED_PROXY_HOPS", 1) - headers = [("X-Forwarded-For", FORGED), ("X-Forwarded-For", CLIENT)] - async with _app().test_request_context( - "/", headers=headers, scope_base={"client": (PEER, 40000)}, - ): + headers = [("Remote-Addr", PEER), ("X-Forwarded-For", FORGED), ("X-Forwarded-For", CLIENT)] + async with _app().test_request_context("/", headers=headers): assert client_ip() == CLIENT