diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-04-21 11:05:12 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-04-21 11:05:12 +1200 |
commit | 2c660d76337b11eb438a2978ec3bda3ac10babd5 (patch) | |
tree | 3c3cef787b9575c60de911a76dfd55e1074eea92 /test/test_http.py | |
parent | 0141629c0863c583f6c57965220be57f81a6ce17 (diff) | |
download | mitmproxy-2c660d76337b11eb438a2978ec3bda3ac10babd5.tar.gz mitmproxy-2c660d76337b11eb438a2978ec3bda3ac10babd5.tar.bz2 mitmproxy-2c660d76337b11eb438a2978ec3bda3ac10babd5.zip |
Migrate requeset reading from mitmproxy to netlib
Diffstat (limited to 'test/test_http.py')
-rw-r--r-- | test/test_http.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/test_http.py b/test/test_http.py index b1c62458..5bd7cab2 100644 --- a/test/test_http.py +++ b/test/test_http.py @@ -366,3 +366,75 @@ def test_parse_http_basic_auth(): assert not http.parse_http_basic_auth("foo bar") v = "basic " + binascii.b2a_base64("foo") assert not http.parse_http_basic_auth(v) + + +def test_get_line(): + r = cStringIO.StringIO("\nfoo") + assert http.get_line(r) == "foo" + tutils.raises(tcp.NetLibDisconnect, http.get_line, r) + + +class TestReadRequest(): + + def tst(self, data, **kwargs): + r = cStringIO.StringIO(data) + return http.read_request(r, **kwargs) + + def test_invalid(self): + tutils.raises( + "bad http request", + self.tst, + "xxx" + ) + tutils.raises( + "bad http request line", + self.tst, + "get /\xff HTTP/1.1" + ) + tutils.raises( + "invalid headers", + self.tst, + "get / HTTP/1.1\r\nfoo" + ) + + def test_asterisk_form_in(self): + v = self.tst("OPTIONS * HTTP/1.1") + assert v.form_in == "relative" + assert v.method == "OPTIONS" + + def test_absolute_form_in(self): + tutils.raises( + "Bad HTTP request line", + self.tst, + "GET oops-no-protocol.com HTTP/1.1" + ) + v = self.tst("GET http://address:22/ HTTP/1.1") + assert v.form_in == "absolute" + assert v.port == 22 + assert v.host == "address" + assert v.scheme == "http" + + def test_connect(self): + tutils.raises( + "Bad HTTP request line", + self.tst, + "CONNECT oops-no-port.com HTTP/1.1" + ) + v = self.tst("CONNECT foo.com:443 HTTP/1.1") + assert v.form_in == "authority" + assert v.method == "CONNECT" + assert v.port == 443 + assert v.host == "foo.com" + + def test_expect(self): + w = cStringIO.StringIO() + r = cStringIO.StringIO( + "GET / HTTP/1.1\r\n" + "Content-Length: 3\r\n" + "Expect: 100-continue\r\n\r\n" + "foobar", + ) + v = http.read_request(r, wfile=w) + assert w.getvalue() == "HTTP/1.1 100 Continue\r\n\r\n" + assert v.content == "foo" + assert r.read(3) == "bar" |