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
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:
+5
-6
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user