diff options
Diffstat (limited to 'test/netlib')
-rw-r--r-- | test/netlib/http/test_cookies.py | 13 | ||||
-rw-r--r-- | test/netlib/http/test_request.py | 14 | ||||
-rw-r--r-- | test/netlib/http/test_response.py | 2 | ||||
-rw-r--r-- | test/netlib/test_odict.py | 10 | ||||
-rw-r--r-- | test/netlib/test_utils.py | 15 |
5 files changed, 40 insertions, 14 deletions
diff --git a/test/netlib/http/test_cookies.py b/test/netlib/http/test_cookies.py index 3b520a44..da28850f 100644 --- a/test/netlib/http/test_cookies.py +++ b/test/netlib/http/test_cookies.py @@ -228,7 +228,16 @@ def test_refresh_cookie(): c = "MOO=BAR; Expires=Tue, 08-Mar-2011 00:20:38 GMT; Path=foo.com; Secure" assert "00:21:38" in cookies.refresh_set_cookie_header(c, 60) + c = "foo,bar" + with raises(ValueError): + cookies.refresh_set_cookie_header(c, 60) + # https://github.com/mitmproxy/mitmproxy/issues/773 c = ">=A" - with raises(ValueError): - cookies.refresh_set_cookie_header(c, 60)
\ No newline at end of file + assert cookies.refresh_set_cookie_header(c, 60) + + # https://github.com/mitmproxy/mitmproxy/issues/1118 + c = "foo:bar=bla" + assert cookies.refresh_set_cookie_header(c, 0) + c = "foo/bar=bla" + assert cookies.refresh_set_cookie_header(c, 0) diff --git a/test/netlib/http/test_request.py b/test/netlib/http/test_request.py index 50ad2d05..7ed6bd0f 100644 --- a/test/netlib/http/test_request.py +++ b/test/netlib/http/test_request.py @@ -107,6 +107,14 @@ class TestRequestUtils(object): with raises(ValueError): request.url = "not-a-url" + def test_url_options(self): + request = treq(method=b"OPTIONS", path=b"*") + assert request.url == "http://address:22" + + def test_url_authority(self): + request = treq(first_line_format="authority") + assert request.url == "address:22" + def test_pretty_host(self): request = treq() # Without host header @@ -140,6 +148,10 @@ class TestRequestUtils(object): request.headers["host"] = "other" assert request.pretty_url == "http://address:22/path" + def test_pretty_url_options(self): + request = treq(method=b"OPTIONS", path=b"*") + assert request.pretty_url == "http://address:22" + def test_pretty_url_authority(self): request = treq(first_line_format="authority") assert request.pretty_url == "address:22" @@ -160,7 +172,7 @@ class TestRequestUtils(object): def test_get_cookies_none(self): request = treq() request.headers = Headers() - assert len(request.cookies) == 0 + assert not request.cookies def test_get_cookies_single(self): request = treq() diff --git a/test/netlib/http/test_response.py b/test/netlib/http/test_response.py index a0c44d90..5440176c 100644 --- a/test/netlib/http/test_response.py +++ b/test/netlib/http/test_response.py @@ -98,7 +98,7 @@ class TestResponseUtils(object): resp = tresp() v = resp.cookies v.add("foo", ["bar", ODictCaseless()]) - resp.set_cookies(v) + resp.cookies = v v = resp.cookies assert len(v) == 1 diff --git a/test/netlib/test_odict.py b/test/netlib/test_odict.py index f0985ef6..b6fd6401 100644 --- a/test/netlib/test_odict.py +++ b/test/netlib/test_odict.py @@ -27,16 +27,6 @@ class TestODict(object): b.set_state(state) assert b == od - def test_in_any(self): - od = odict.ODict() - od["one"] = ["atwoa", "athreea"] - assert od.in_any("one", "two") - assert od.in_any("one", "three") - assert not od.in_any("one", "four") - assert not od.in_any("nonexistent", "foo") - assert not od.in_any("one", "TWO") - assert od.in_any("one", "TWO", True) - def test_iter(self): od = odict.ODict() assert not [i for i in od] diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py index be2a59fc..1d8f7b0f 100644 --- a/test/netlib/test_utils.py +++ b/test/netlib/test_utils.py @@ -1,3 +1,4 @@ +# coding=utf-8 from netlib import utils, tutils from netlib.http import Headers @@ -170,3 +171,17 @@ class TestSerializable: def test_safe_subn(): assert utils.safe_subn("foo", u"bar", "\xc2foo") + + +def test_bytes_to_escaped_str(): + assert utils.bytes_to_escaped_str(b"foo") == "foo" + assert utils.bytes_to_escaped_str(b"\b") == r"\x08" + assert utils.bytes_to_escaped_str(br"&!?=\)") == r"&!?=\\)" + assert utils.bytes_to_escaped_str(b'\xc3\xbc') == r"\xc3\xbc" + + +def test_escaped_str_to_bytes(): + assert utils.escaped_str_to_bytes("foo") == b"foo" + assert utils.escaped_str_to_bytes(r"\x08") == b"\b" + assert utils.escaped_str_to_bytes(r"&!?=\\)") == br"&!?=\)" + assert utils.escaped_str_to_bytes(r"ΓΌ") == b'\xc3\xbc' |