From bda66472bdf97cc059dee051c4baf0850e54793b Mon Sep 17 00:00:00 2001 From: Aarohi1Agarwal Date: Fri, 31 Jul 2026 21:52:11 +0530 Subject: [PATCH] Add WSGI tests for missing input and invalid content length --- tests/integration/test_wsgi_adapter.py | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/integration/test_wsgi_adapter.py b/tests/integration/test_wsgi_adapter.py index 4213700..245b142 100644 --- a/tests/integration/test_wsgi_adapter.py +++ b/tests/integration/test_wsgi_adapter.py @@ -268,6 +268,41 @@ async def echo(request: Request) -> bytes: assert stream.tell() == 3 +def test_wsgi_missing_input_returns_empty_body() -> None: + app = Quater() + + environ = base_environ(method="POST", path="/echo") + del environ["wsgi.input"] + + @app.post("/echo") + async def echo(request: Request) -> bytes: + return await request.body() + + status, _, body = call_wsgi(app, environ) + + assert status == "200 OK" + assert body == b"" + + +def test_wsgi_invalid_content_length_returns_400_without_reading_input() -> None: + app = Quater() + + stream = CountingInput(b"should-not-be-read") + environ = base_environ(method="POST", path="/echo") + environ["CONTENT_LENGTH"] = "abc" + environ["wsgi.input"] = stream + + @app.post("/echo") + async def echo(request: Request) -> bytes: + return await request.body() + + status, _, body = call_wsgi(app, environ) + + assert status == "400 Bad Request" + assert body == b"Invalid Content-Length header" + assert stream.read_calls == 0 + + def test_wsgi_runs_response_finalizers_when_streaming_body_fails() -> None: events: list[str] = [] app = Quater()