diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/test_flow.py | 37 | ||||
-rw-r--r-- | test/mitmproxy/test_server.py | 16 | ||||
-rw-r--r-- | test/netlib/http/http2/test_connections.py | 16 | ||||
-rw-r--r-- | test/netlib/http/test_cookies.py | 16 | ||||
-rw-r--r-- | test/netlib/http/test_response.py | 23 |
5 files changed, 60 insertions, 48 deletions
diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 2353935b..1fadb23d 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -809,6 +809,11 @@ class TestFlowMaster: assert s.flow_count() == 2 assert s.index(f2) == 1 + def test_create_flow(self): + s = flow.State() + fm = flow.FlowMaster(None, s) + assert fm.create_request("GET", "http", "example.com", 80, "/") + def test_all(self): s = flow.State() fm = flow.FlowMaster(None, s) @@ -1146,38 +1151,6 @@ class TestResponse: resp2 = resp.copy() assert resp2.get_state() == resp.get_state() - def test_refresh(self): - r = HTTPResponse.wrap(netlib.tutils.tresp()) - n = time.time() - r.headers["date"] = email.utils.formatdate(n) - pre = r.headers["date"] - r.refresh(n) - assert pre == r.headers["date"] - r.refresh(n + 60) - - d = email.utils.parsedate_tz(r.headers["date"]) - d = email.utils.mktime_tz(d) - # Weird that this is not exact... - assert abs(60 - (d - n)) <= 1 - - r.headers["set-cookie"] = "MOO=BAR; Expires=Tue, 08-Mar-2011 00:20:38 GMT; Path=foo.com; Secure" - r.refresh() - - def test_refresh_cookie(self): - r = HTTPResponse.wrap(netlib.tutils.tresp()) - - # Invalid expires format, sent to us by Reddit. - c = "rfoo=bar; Domain=reddit.com; expires=Thu, 31 Dec 2037 23:59:59 GMT; Path=/" - assert r._refresh_cookie(c, 60) - - c = "MOO=BAR; Expires=Tue, 08-Mar-2011 00:20:38 GMT; Path=foo.com; Secure" - assert "00:21:38" in r._refresh_cookie(c, 60) - - # https://github.com/mitmproxy/mitmproxy/issues/773 - c = ">=A" - with tutils.raises(ValueError): - r._refresh_cookie(c, 60) - def test_replace(self): r = HTTPResponse.wrap(netlib.tutils.tresp()) r.headers["Foo"] = "fOo" diff --git a/test/mitmproxy/test_server.py b/test/mitmproxy/test_server.py index dc72f032..0d56e7ea 100644 --- a/test/mitmproxy/test_server.py +++ b/test/mitmproxy/test_server.py @@ -973,22 +973,22 @@ class TestProxyChainingSSLReconnect(tservers.HTTPUpstreamProxyTest): assert not self.chain[1].tmaster.state.flows[0].response # killed assert self.chain[1].tmaster.state.flows[1].response - assert self.proxy.tmaster.state.flows[0].request.form_in == "authority" - assert self.proxy.tmaster.state.flows[1].request.form_in == "relative" + assert self.proxy.tmaster.state.flows[0].request.first_line_format == "authority" + assert self.proxy.tmaster.state.flows[1].request.first_line_format == "relative" assert self.chain[0].tmaster.state.flows[ - 0].request.form_in == "authority" + 0].request.first_line_format == "authority" assert self.chain[0].tmaster.state.flows[ - 1].request.form_in == "relative" + 1].request.first_line_format == "relative" assert self.chain[0].tmaster.state.flows[ - 2].request.form_in == "authority" + 2].request.first_line_format == "authority" assert self.chain[0].tmaster.state.flows[ - 3].request.form_in == "relative" + 3].request.first_line_format == "relative" assert self.chain[1].tmaster.state.flows[ - 0].request.form_in == "relative" + 0].request.first_line_format == "relative" assert self.chain[1].tmaster.state.flows[ - 1].request.form_in == "relative" + 1].request.first_line_format == "relative" req = p.request("get:'/p/418:b\"content2\"'") diff --git a/test/netlib/http/http2/test_connections.py b/test/netlib/http/http2/test_connections.py index c067d487..7b003067 100644 --- a/test/netlib/http/http2/test_connections.py +++ b/test/netlib/http/http2/test_connections.py @@ -325,7 +325,7 @@ class TestReadRequestRelative(tservers.ServerTestBase): ssl = True - def test_asterisk_form_in(self): + def test_asterisk_form(self): c = tcp.TCPClient(("127.0.0.1", self.port)) c.connect() c.convert_to_ssl() @@ -334,7 +334,7 @@ class TestReadRequestRelative(tservers.ServerTestBase): req = protocol.read_request(NotImplemented) - assert req.form_in == "relative" + assert req.first_line_format == "relative" assert req.method == "OPTIONS" assert req.path == "*" @@ -348,7 +348,7 @@ class TestReadRequestAbsolute(tservers.ServerTestBase): ssl = True - def test_absolute_form_in(self): + def test_absolute_form(self): c = tcp.TCPClient(("127.0.0.1", self.port)) c.connect() c.convert_to_ssl() @@ -357,7 +357,7 @@ class TestReadRequestAbsolute(tservers.ServerTestBase): req = protocol.read_request(NotImplemented) - assert req.form_in == "absolute" + assert req.first_line_format == "absolute" assert req.scheme == "http" assert req.host == "address" assert req.port == 22 @@ -382,13 +382,13 @@ class TestReadRequestConnect(tservers.ServerTestBase): protocol.connection_preface_performed = True req = protocol.read_request(NotImplemented) - assert req.form_in == "authority" + assert req.first_line_format == "authority" assert req.method == "CONNECT" assert req.host == "address" assert req.port == 22 req = protocol.read_request(NotImplemented) - assert req.form_in == "authority" + assert req.first_line_format == "authority" assert req.method == "CONNECT" assert req.host == "example.com" assert req.port == 443 @@ -417,7 +417,7 @@ class TestReadResponse(tservers.ServerTestBase): assert resp.http_version == "HTTP/2.0" assert resp.status_code == 200 - assert resp.msg == '' + assert resp.reason == '' assert resp.headers.fields == [[b':status', b'200'], [b'etag', b'foobar']] assert resp.content == b'foobar' assert resp.timestamp_end @@ -444,7 +444,7 @@ class TestReadEmptyResponse(tservers.ServerTestBase): assert resp.stream_id == 42 assert resp.http_version == "HTTP/2.0" assert resp.status_code == 200 - assert resp.msg == '' + assert resp.reason == '' assert resp.headers.fields == [[b':status', b'200'], [b'etag', b'foobar']] assert resp.content == b'' diff --git a/test/netlib/http/test_cookies.py b/test/netlib/http/test_cookies.py index 34bb64f2..3b520a44 100644 --- a/test/netlib/http/test_cookies.py +++ b/test/netlib/http/test_cookies.py @@ -1,4 +1,5 @@ from netlib.http import cookies +from netlib.tutils import raises def test_read_token(): @@ -216,3 +217,18 @@ def test_parse_set_cookie_header(): assert ret2[2].lst == expected[2] else: assert ret is None + + +def test_refresh_cookie(): + + # Invalid expires format, sent to us by Reddit. + c = "rfoo=bar; Domain=reddit.com; expires=Thu, 31 Dec 2037 23:59:59 GMT; Path=/" + assert cookies.refresh_set_cookie_header(c, 60) + + 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) + + # 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 diff --git a/test/netlib/http/test_response.py b/test/netlib/http/test_response.py index 14588000..a0c44d90 100644 --- a/test/netlib/http/test_response.py +++ b/test/netlib/http/test_response.py @@ -1,6 +1,9 @@ from __future__ import absolute_import, print_function, division +import email + import six +import time from netlib.http import Headers from netlib.odict import ODict, ODictCaseless @@ -100,3 +103,23 @@ class TestResponseUtils(object): v = resp.cookies assert len(v) == 1 assert v["foo"] == [["bar", ODictCaseless()]] + + def test_refresh(self): + r = tresp() + n = time.time() + r.headers["date"] = email.utils.formatdate(n) + pre = r.headers["date"] + r.refresh(n) + assert pre == r.headers["date"] + r.refresh(n + 60) + + d = email.utils.parsedate_tz(r.headers["date"]) + d = email.utils.mktime_tz(d) + # Weird that this is not exact... + assert abs(60 - (d - n)) <= 1 + + cookie = "MOO=BAR; Expires=Tue, 08-Mar-2011 00:20:38 GMT; Path=foo.com; Secure" + r.headers["set-cookie"] = cookie + r.refresh() + # Cookie refreshing is tested in test_cookies, we just make sure that it's triggered here. + assert cookie != r.headers["set-cookie"] |