aboutsummaryrefslogtreecommitdiffstats
path: root/test/http/test_semantics.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-07-24 16:50:56 +0200
committerMaximilian Hils <git@maximilianhils.com>2015-07-24 16:50:56 +0200
commitb57c1386a19f7faac50d0ad428afba18283d33c1 (patch)
treeb0303bf08c3429cd5d7f09ab38bebd052063f909 /test/http/test_semantics.py
parent1b261613826565dc5453b2846904c23773243921 (diff)
parent657973eca3b091cdf07a65f8363affd3d36f0d0f (diff)
downloadmitmproxy-b57c1386a19f7faac50d0ad428afba18283d33c1.tar.gz
mitmproxy-b57c1386a19f7faac50d0ad428afba18283d33c1.tar.bz2
mitmproxy-b57c1386a19f7faac50d0ad428afba18283d33c1.zip
Merge pull request #81 from Kriechi/protocol-refactor
HTTP protocol refactoring
Diffstat (limited to 'test/http/test_semantics.py')
-rw-r--r--test/http/test_semantics.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/http/test_semantics.py b/test/http/test_semantics.py
new file mode 100644
index 00000000..c4605302
--- /dev/null
+++ b/test/http/test_semantics.py
@@ -0,0 +1,54 @@
+import cStringIO
+import textwrap
+import binascii
+
+from netlib import http, odict, tcp
+from netlib.http import http1
+from .. import tutils, tservers
+
+def test_httperror():
+ e = http.exceptions.HttpError(404, "Not found")
+ assert str(e)
+
+
+def test_parse_url():
+ assert not http.parse_url("")
+
+ u = "http://foo.com:8888/test"
+ s, h, po, pa = http.parse_url(u)
+ assert s == "http"
+ assert h == "foo.com"
+ assert po == 8888
+ assert pa == "/test"
+
+ s, h, po, pa = http.parse_url("http://foo/bar")
+ assert s == "http"
+ assert h == "foo"
+ assert po == 80
+ assert pa == "/bar"
+
+ s, h, po, pa = http.parse_url("http://user:pass@foo/bar")
+ assert s == "http"
+ assert h == "foo"
+ assert po == 80
+ assert pa == "/bar"
+
+ s, h, po, pa = http.parse_url("http://foo")
+ assert pa == "/"
+
+ s, h, po, pa = http.parse_url("https://foo")
+ assert po == 443
+
+ assert not http.parse_url("https://foo:bar")
+ assert not http.parse_url("https://foo:")
+
+ # Invalid IDNA
+ assert not http.parse_url("http://\xfafoo")
+ # Invalid PATH
+ assert not http.parse_url("http:/\xc6/localhost:56121")
+ # Null byte in host
+ assert not http.parse_url("http://foo\0")
+ # Port out of range
+ assert not http.parse_url("http://foo:999999")
+ # Invalid IPv6 URL - see http://www.ietf.org/rfc/rfc2732.txt
+ assert not http.parse_url('http://lo[calhost')