diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/test_contentview.py | 6 | ||||
-rw-r--r-- | test/netlib/http/test_url.py | 65 | ||||
-rw-r--r-- | test/netlib/test_utils.py | 64 |
3 files changed, 68 insertions, 67 deletions
diff --git a/test/mitmproxy/test_contentview.py b/test/mitmproxy/test_contentview.py index c00afa5f..57e5ae99 100644 --- a/test/mitmproxy/test_contentview.py +++ b/test/mitmproxy/test_contentview.py @@ -1,8 +1,8 @@ from mitmproxy.exceptions import ContentViewException from netlib.http import Headers from netlib.odict import ODict -import netlib.utils from netlib import encoding +from netlib.http import url import mitmproxy.contentviews as cv from . import tutils @@ -60,10 +60,10 @@ class TestContentView: assert f[0] == "Query" def test_view_urlencoded(self): - d = netlib.utils.urlencode([("one", "two"), ("three", "four")]) + d = url.urlencode([("one", "two"), ("three", "four")]) v = cv.ViewURLEncoded() assert v(d) - d = netlib.utils.urlencode([("adsfa", "")]) + d = url.urlencode([("adsfa", "")]) v = cv.ViewURLEncoded() assert v(d) diff --git a/test/netlib/http/test_url.py b/test/netlib/http/test_url.py new file mode 100644 index 00000000..d777a949 --- /dev/null +++ b/test/netlib/http/test_url.py @@ -0,0 +1,65 @@ +from netlib import tutils +from netlib.http import url + +def test_parse_url(): + with tutils.raises(ValueError): + url.parse_url("") + + s, h, po, pa = url.parse_url(b"http://foo.com:8888/test") + assert s == b"http" + assert h == b"foo.com" + assert po == 8888 + assert pa == b"/test" + + s, h, po, pa = url.parse_url("http://foo/bar") + assert s == b"http" + assert h == b"foo" + assert po == 80 + assert pa == b"/bar" + + s, h, po, pa = url.parse_url(b"http://user:pass@foo/bar") + assert s == b"http" + assert h == b"foo" + assert po == 80 + assert pa == b"/bar" + + s, h, po, pa = url.parse_url(b"http://foo") + assert pa == b"/" + + s, h, po, pa = url.parse_url(b"https://foo") + assert po == 443 + + with tutils.raises(ValueError): + url.parse_url(b"https://foo:bar") + + # Invalid IDNA + with tutils.raises(ValueError): + url.parse_url("http://\xfafoo") + # Invalid PATH + with tutils.raises(ValueError): + url.parse_url("http:/\xc6/localhost:56121") + # Null byte in host + with tutils.raises(ValueError): + url.parse_url("http://foo\0") + # Port out of range + _, _, port, _ = url.parse_url("http://foo:999999") + assert port == 80 + # Invalid IPv6 URL - see http://www.ietf.org/rfc/rfc2732.txt + with tutils.raises(ValueError): + url.parse_url('http://lo[calhost') + + +def test_unparse_url(): + assert url.unparse_url("http", "foo.com", 99, "") == "http://foo.com:99" + assert url.unparse_url("http", "foo.com", 80, "/bar") == "http://foo.com/bar" + assert url.unparse_url("https", "foo.com", 80, "") == "https://foo.com:80" + assert url.unparse_url("https", "foo.com", 443, "") == "https://foo.com" + + +def test_urlencode(): + assert url.urlencode([('foo', 'bar')]) + + +def test_urldecode(): + s = "one=two&three=four" + assert len(url.urldecode(s)) == 2 diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py index cd629d77..f9315667 100644 --- a/test/netlib/test_utils.py +++ b/test/netlib/test_utils.py @@ -38,70 +38,6 @@ def test_pretty_size(): assert utils.pretty_size(1024 * 1024) == "1MB" -def test_parse_url(): - with tutils.raises(ValueError): - utils.parse_url("") - - s, h, po, pa = utils.parse_url(b"http://foo.com:8888/test") - assert s == b"http" - assert h == b"foo.com" - assert po == 8888 - assert pa == b"/test" - - s, h, po, pa = utils.parse_url("http://foo/bar") - assert s == b"http" - assert h == b"foo" - assert po == 80 - assert pa == b"/bar" - - s, h, po, pa = utils.parse_url(b"http://user:pass@foo/bar") - assert s == b"http" - assert h == b"foo" - assert po == 80 - assert pa == b"/bar" - - s, h, po, pa = utils.parse_url(b"http://foo") - assert pa == b"/" - - s, h, po, pa = utils.parse_url(b"https://foo") - assert po == 443 - - with tutils.raises(ValueError): - utils.parse_url(b"https://foo:bar") - - # Invalid IDNA - with tutils.raises(ValueError): - utils.parse_url("http://\xfafoo") - # Invalid PATH - with tutils.raises(ValueError): - utils.parse_url("http:/\xc6/localhost:56121") - # Null byte in host - with tutils.raises(ValueError): - utils.parse_url("http://foo\0") - # Port out of range - _, _, port, _ = utils.parse_url("http://foo:999999") - assert port == 80 - # Invalid IPv6 URL - see http://www.ietf.org/rfc/rfc2732.txt - with tutils.raises(ValueError): - utils.parse_url('http://lo[calhost') - - -def test_unparse_url(): - assert utils.unparse_url("http", "foo.com", 99, "") == "http://foo.com:99" - assert utils.unparse_url("http", "foo.com", 80, "/bar") == "http://foo.com/bar" - assert utils.unparse_url("https", "foo.com", 80, "") == "https://foo.com:80" - assert utils.unparse_url("https", "foo.com", 443, "") == "https://foo.com" - - -def test_urlencode(): - assert utils.urlencode([('foo', 'bar')]) - - -def test_urldecode(): - s = "one=two&three=four" - assert len(utils.urldecode(s)) == 2 - - def test_get_header_tokens(): headers = Headers() assert utils.get_header_tokens(headers, "foo") == [] |