From df8480156d27b36dde428251b83c0a8371c416b5 Mon Sep 17 00:00:00 2001 From: Stephen Sadowski Date: Tue, 1 Feb 2022 20:14:57 -0600 Subject: [PATCH] test: update malformed url test --- tests/test_bad_request.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test_bad_request.py b/tests/test_bad_request.py index 9229570e..c805f3c9 100644 --- a/tests/test_bad_request.py +++ b/tests/test_bad_request.py @@ -24,4 +24,22 @@ def test_bad_request_response(app): def test_malformed_uri_bad_request(app): - assert False \ No newline at end of file + lines = [] + + app.get("/")(lambda x: ...) + + @app.listener("after_server_start") + async def _request(sanic, loop): + connect = asyncio.open_connection("127.0.0.1", 42101) + reader, writer = await connect + writer.write(b"GET /\r\nHost: ---.com\r\n\r\n") + while True: + line = await reader.readline() + if not line: + break + lines.append(line) + app.stop() + + app.run(host="127.0.0.1", port=42101, debug=False) + assert lines[0] == b"HTTP/1.1 400 Bad Request\r\n" + assert b"Bad Request" in lines[-2] \ No newline at end of file