From 488f31478d5ad4cadc4e05c405679f37e19303ad Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Thu, 23 Dec 2021 15:25:37 +0000 Subject: [PATCH] [PR #6451/a60e8a58 backport][3.9] Regression test for handling unsupported Upgrade requests (issue #6446) (#6455) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sviatoslav Sydorenko Co-authored-by: Peter Würtz --- tests/test_web_server.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test_web_server.py b/tests/test_web_server.py index b02787b88c2..627f0f9f774 100644 --- a/tests/test_web_server.py +++ b/tests/test_web_server.py @@ -3,7 +3,7 @@ import pytest -from aiohttp import client, web +from aiohttp import client, helpers, web async def test_simple_server(aiohttp_raw_server, aiohttp_client) -> None: @@ -18,6 +18,28 @@ async def handler(request): assert txt == "/path/to" +@pytest.mark.xfail( + not helpers.NO_EXTENSIONS, + raises=client.ServerDisconnectedError, + reason="The behavior of C-extensions differs from pure-Python: " + "https://github.com/aio-libs/aiohttp/issues/6446", +) +async def test_unsupported_upgrade(aiohttp_raw_server, aiohttp_client) -> None: + # don't fail if a client probes for an unsupported protocol upgrade + # https://github.com/aio-libs/aiohttp/issues/6446#issuecomment-999032039 + async def handler(request: web.Request): + return web.Response(body=await request.read()) + + upgrade_headers = {"Connection": "Upgrade", "Upgrade": "unsupported_proto"} + server = await aiohttp_raw_server(handler) + cli = await aiohttp_client(server) + test_data = b"Test" + resp = await cli.post("/path/to", data=test_data, headers=upgrade_headers) + assert resp.status == 200 + data = await resp.read() + assert data == test_data + + async def test_raw_server_not_http_exception(aiohttp_raw_server, aiohttp_client): exc = RuntimeError("custom runtime error")