From 726536689b2d06dc3ceac252844a4f8e88669f9c Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 20 Mar 2016 22:58:35 +0100 Subject: [PATCH] py3++ --- mitmproxy/flow.py | 2 +- test/mitmproxy/test_filt.py | 70 +++++++++++-------------------------- test/mitmproxy/test_flow.py | 2 +- 3 files changed, 22 insertions(+), 52 deletions(-) diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py index a937e106e..8e239a441 100644 --- a/mitmproxy/flow.py +++ b/mitmproxy/flow.py @@ -248,7 +248,7 @@ class ServerPlaybackState: r = flow.request _, _, path, _, query, _ = urllib.parse.urlparse(r.url) - queriesArray = urllib.parse_qsl(query, keep_blank_values=True) + queriesArray = urllib.parse.parse_qsl(query, keep_blank_values=True) key = [ str(r.port), diff --git a/test/mitmproxy/test_filt.py b/test/mitmproxy/test_filt.py index 842cbd44b..4401f2be2 100644 --- a/test/mitmproxy/test_filt.py +++ b/test/mitmproxy/test_filt.py @@ -78,43 +78,13 @@ class TestParsing: class TestMatching: def req(self): - headers = Headers(header="qvalue") - req = http.HTTPRequest( - "absolute", - "GET", - "http", - "host", - 80, - "/path", - b"HTTP/1.1", - headers, - "content_request", - None, - None - ) - f = http.HTTPFlow(tutils.tclient_conn(), None) - f.request = req - return f + return tutils.tflow() def resp(self): - f = self.req() - - headers = Headers([["header_response", "svalue"]]) - f.response = http.HTTPResponse( - b"HTTP/1.1", - 200, - "OK", - headers, - "content_response", - None, - None) - - return f + return tutils.tflow(resp=True) def err(self): - f = self.req() - f.error = Error("msg") - return f + return tutils.tflow(err=True) def q(self, q, o): return filt.parse(q)(o) @@ -168,34 +138,34 @@ class TestMatching: assert self.q("~h 'header: qvalue'", q) assert self.q("~h 'header: qvalue'", s) - assert self.q("~h 'header_response: svalue'", s) + assert self.q("~h 'header-response: svalue'", s) assert self.q("~hq 'header: qvalue'", s) - assert not self.q("~hq 'header_response: svalue'", s) + assert not self.q("~hq 'header-response: svalue'", s) assert self.q("~hq 'header: qvalue'", q) - assert not self.q("~hq 'header_request: svalue'", q) + assert not self.q("~hq 'header-request: svalue'", q) assert not self.q("~hs 'header: qvalue'", s) - assert self.q("~hs 'header_response: svalue'", s) + assert self.q("~hs 'header-response: svalue'", s) assert not self.q("~hs 'header: qvalue'", q) def match_body(self, q, s): assert not self.q("~b nonexistent", q) assert self.q("~b content", q) - assert self.q("~b response", s) - assert self.q("~b content_request", s) + assert self.q("~b message", s) + assert not self.q("~bq nomatch", s) assert self.q("~bq content", q) assert self.q("~bq content", s) - assert not self.q("~bq response", q) - assert not self.q("~bq response", s) + assert not self.q("~bq message", q) + assert not self.q("~bq message", s) - assert not self.q("~bs content", q) - assert self.q("~bs content", s) assert not self.q("~bs nomatch", s) - assert not self.q("~bs response", q) - assert self.q("~bs response", s) + assert not self.q("~bs content", q) + assert not self.q("~bs content", s) + assert not self.q("~bs message", q) + assert self.q("~bs message", s) def test_body(self): q = self.req() @@ -217,18 +187,18 @@ class TestMatching: def test_domain(self): q = self.req() - assert self.q("~d host", q) + assert self.q("~d address", q) assert not self.q("~d none", q) def test_url(self): q = self.req() s = self.resp() - assert self.q("~u host", q) - assert self.q("~u host/path", q) + assert self.q("~u address", q) + assert self.q("~u address:22/path", q) assert not self.q("~u moo/path", q) - assert self.q("~u host", s) - assert self.q("~u host/path", s) + assert self.q("~u address", s) + assert self.q("~u address:22/path", s) assert not self.q("~u moo/path", s) def test_code(self): diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 993db876c..33d2b8f91 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -116,7 +116,7 @@ class TestClientPlaybackState: c.clear(c.current) assert c.done() - q = Queue.Queue() + q = queue.Queue() fm.state.clear() fm.tick(q, timeout=0)