diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2018-11-17 13:16:26 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2018-11-17 13:16:26 +0100 |
commit | 990bb56afd0c537aa836deec2469b50d737c8eb9 (patch) | |
tree | ccb442904901f6b7d54a9021c91ce5441f9a0197 /crocoite | |
parent | da68cf771dbc5ff21168afaa027ab206c6cdb7f1 (diff) | |
download | crocoite-990bb56afd0c537aa836deec2469b50d737c8eb9.tar.gz crocoite-990bb56afd0c537aa836deec2469b50d737c8eb9.tar.bz2 crocoite-990bb56afd0c537aa836deec2469b50d737c8eb9.zip |
browser: Add tests for header deserialization
Diffstat (limited to 'crocoite')
-rw-r--r-- | crocoite/test_browser.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/crocoite/test_browser.py b/crocoite/test_browser.py index 331fa49..f72d899 100644 --- a/crocoite/test_browser.py +++ b/crocoite/test_browser.py @@ -66,6 +66,13 @@ testItems = [ # 1×1 png image b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x00\x00\x00\x00:~\x9bU\x00\x00\x00\nIDAT\x08\x1dc\xf8\x0f\x00\x01\x01\x01\x006_g\x80\x00\x00\x00\x00IEND\xaeB`\x82'), TItem ('empty', 200, {'Content-Type': 'text/plain'}, b''), + TItem ('headers/duplicate', 200, [('Content-Type', 'text/plain'), ('Duplicate', '1'), ('Duplicate', '2')], b''), + TItem ('headers/fetch/req', 200, {'Content-Type': 'text/plain'}, b''), + TItem ('headers/fetch/html', 200, {'Content-Type': 'text/html'}, + r"""<html><body><script> + let h = new Headers([["custom", "1"]]); + fetch("/headers/fetch/req", {"method": "GET", "headers": h}).then(x => console.log("done")); + </script></body></html>""".encode ('utf8')), TItem ('redirect/301/empty', 301, {'Location': '/empty'}, b'', isRedirect=True), TItem ('redirect/301/redirect/301/empty', 301, {'Location': '/redirect/301/empty'}, b'', isRedirect=True), TItem ('nonexistent', 404, {}, b''), @@ -170,6 +177,38 @@ async def test_empty (loader): await literalItem (loader, testItemMap['/empty']) @pytest.mark.asyncio +async def test_headers_duplicate (loader): + """ + Some headers, like Set-Cookie can be present multiple times. Chrome + separates these with a newline. + """ + async with loader ('/headers/duplicate') as l: + await l.start () + async for it in l: + if it.parsedUrl.path == '/headers/duplicate': + assert not it.failed + dup = list (filter (lambda x: x[0] == 'Duplicate', it.responseHeaders)) + assert len(dup) == 2 + assert list(sorted(map(itemgetter(1), dup))) == ['1', '2'] + break + +@pytest.mark.asyncio +async def test_headers_req (loader): + """ + Custom request headers. JavaScript’s Headers() does not support duplicate + headers, so we can’t generate those. + """ + async with loader ('/headers/fetch/html') as l: + await l.start () + async for it in l: + if it.parsedUrl.path == '/headers/fetch/req': + assert not it.failed + dup = list (filter (lambda x: x[0] == 'custom', it.requestHeaders)) + assert len(dup) == 1 + assert list(sorted(map(itemgetter(1), dup))) == ['1'] + break + +@pytest.mark.asyncio async def test_redirect (loader): await literalItem (loader, testItemMap['/redirect/301/empty'], [testItemMap['/empty']]) # chained redirects |