Skip to content

Commit

Permalink
Add tests, accidentally dropped before (aio-libs#8088)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0016004)
  • Loading branch information
pajod committed Apr 23, 2024
1 parent 2c64c8a commit 4d208e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES/8088.contrib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enabled HTTP parser tests originally intended for 3.9.2 release -- by :user:`pajod`.
35 changes: 29 additions & 6 deletions tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,19 @@ def test_parse_headers_longline(parser: Any) -> None:
parser.feed_data(text)


@pytest.fixture
def xfail_c_parser_status(request) -> None:
if isinstance(request.getfixturevalue("parser"), HttpRequestParserPy):
return
request.node.add_marker(
pytest.mark.xfail(
reason="Regression test for Py parser. May match C behaviour later.",
raises=http_exceptions.BadStatusLine,
)
)


@pytest.mark.usefixtures("xfail_c_parser_status")
def test_parse_unusual_request_line(parser) -> None:
if not isinstance(response, HttpResponseParserPy):
pytest.xfail("Regression test for Py parser. May match C behaviour later.")
Expand Down Expand Up @@ -632,9 +645,6 @@ def test_invalid_header_spacing(parser, pad1: bytes, pad2: bytes, hdr: bytes) ->
if pad1 == pad2 == b"" and hdr != b"":
# one entry in param matrix is correct: non-empty name, not padded
expectation = nullcontext()
if pad1 == pad2 == hdr == b"":
if not isinstance(response, HttpResponseParserPy):
pytest.xfail("Regression test for Py parser. May match C behaviour later.")
with expectation:
parser.feed_data(text)

Expand Down Expand Up @@ -815,9 +825,20 @@ def test_http_request_upgrade(parser: Any) -> None:
assert tail == b"some raw data"


@pytest.fixture
def xfail_c_parser_url(request) -> None:
if isinstance(request.getfixturevalue("parser"), HttpRequestParserPy):
return
request.node.add_marker(
pytest.mark.xfail(
reason="Regression test for Py parser. May match C behaviour later.",
raises=http_exceptions.InvalidURLError,
)
)


@pytest.mark.usefixtures("xfail_c_parser_url")
def test_http_request_parser_utf8_request_line(parser) -> None:
if not isinstance(response, HttpResponseParserPy):
pytest.xfail("Regression test for Py parser. May match C behaviour later.")
messages, upgrade, tail = parser.feed_data(
# note the truncated unicode sequence
b"GET /P\xc3\xbcnktchen\xa0\xef\xb7 HTTP/1.1\r\n" +
Expand All @@ -837,7 +858,9 @@ def test_http_request_parser_utf8_request_line(parser) -> None:
assert msg.compression is None
assert not msg.upgrade
assert not msg.chunked
assert msg.url.path == URL("/P%C3%BCnktchen\udca0\udcef\udcb7").path
# python HTTP parser depends on Cython and CPython URL to match
# .. but yarl.URL("/abs") is not equal to URL.build(path="/abs"), see #6409
assert msg.url == URL.build(path="/Pünktchen\udca0\udcef\udcb7", encoded=True)


def test_http_request_parser_utf8(parser) -> None:
Expand Down

0 comments on commit 4d208e2

Please sign in to comment.