diff options
author | Aldo Cortesi <aldo@corte.si> | 2016-05-31 21:03:42 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2016-05-31 21:03:42 +1200 |
commit | a7abf8b731658b4e7ed8705f7a94a6a62f08d51d (patch) | |
tree | cb86e2e483530f5e1e8b0c5d60839de21fcf7390 /test/netlib/http/test_url.py | |
parent | 2f526393d29b6a03e43d1f6240175b4dfb13dc7d (diff) | |
parent | 4da125b6a098cc0fd8b1fd2878584beb5df75c6c (diff) | |
download | mitmproxy-a7abf8b731658b4e7ed8705f7a94a6a62f08d51d.tar.gz mitmproxy-a7abf8b731658b4e7ed8705f7a94a6a62f08d51d.tar.bz2 mitmproxy-a7abf8b731658b4e7ed8705f7a94a6a62f08d51d.zip |
Merge pull request #1179 from cortesi/reorg
Start reorganising */utils.py
Diffstat (limited to 'test/netlib/http/test_url.py')
-rw-r--r-- | test/netlib/http/test_url.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/test/netlib/http/test_url.py b/test/netlib/http/test_url.py new file mode 100644 index 00000000..26b37230 --- /dev/null +++ b/test/netlib/http/test_url.py @@ -0,0 +1,66 @@ +from netlib import tutils +from netlib.http import url + + +def test_parse(): + with tutils.raises(ValueError): + url.parse("") + + s, h, po, pa = url.parse(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("http://foo/bar") + assert s == b"http" + assert h == b"foo" + assert po == 80 + assert pa == b"/bar" + + s, h, po, pa = url.parse(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(b"http://foo") + assert pa == b"/" + + s, h, po, pa = url.parse(b"https://foo") + assert po == 443 + + with tutils.raises(ValueError): + url.parse(b"https://foo:bar") + + # Invalid IDNA + with tutils.raises(ValueError): + url.parse("http://\xfafoo") + # Invalid PATH + with tutils.raises(ValueError): + url.parse("http:/\xc6/localhost:56121") + # Null byte in host + with tutils.raises(ValueError): + url.parse("http://foo\0") + # Port out of range + _, _, port, _ = url.parse("http://foo:999999") + assert port == 80 + # Invalid IPv6 URL - see http://www.ietf.org/rfc/rfc2732.txt + with tutils.raises(ValueError): + url.parse('http://lo[calhost') + + +def test_unparse(): + assert url.unparse("http", "foo.com", 99, "") == "http://foo.com:99" + assert url.unparse("http", "foo.com", 80, "/bar") == "http://foo.com/bar" + assert url.unparse("https", "foo.com", 80, "") == "https://foo.com:80" + assert url.unparse("https", "foo.com", 443, "") == "https://foo.com" + + +def test_urlencode(): + assert url.encode([('foo', 'bar')]) + + +def test_urldecode(): + s = "one=two&three=four" + assert len(url.decode(s)) == 2 |