aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_flow.py
diff options
context:
space:
mode:
authorMarcelo Glezer <marcelo.glezer@gmail.com>2014-10-03 07:29:44 -0300
committerMarcelo Glezer <marcelo.glezer@gmail.com>2014-10-03 07:29:44 -0300
commit81f5636389e15d345a25a5374078b2abeab73abe (patch)
tree641b9f55ce53d17d31c6f94394692801eabdb278 /test/test_flow.py
parent38218f4ccc698531b3450c8f7dee916e1195cc46 (diff)
downloadmitmproxy-81f5636389e15d345a25a5374078b2abeab73abe.tar.gz
mitmproxy-81f5636389e15d345a25a5374078b2abeab73abe.tar.bz2
mitmproxy-81f5636389e15d345a25a5374078b2abeab73abe.zip
--replay-ignore-content & --replay-ignore-param ported from branch 0.10
Diffstat (limited to 'test/test_flow.py')
-rw-r--r--test/test_flow.py58
1 files changed, 49 insertions, 9 deletions
diff --git a/test/test_flow.py b/test/test_flow.py
index c5254d11..b74119dd 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -111,7 +111,7 @@ class TestClientPlaybackState:
class TestServerPlaybackState:
def test_hash(self):
- s = flow.ServerPlaybackState(None, [], False, False)
+ s = flow.ServerPlaybackState(None, [], False, False, None, False)
r = tutils.tflow()
r2 = tutils.tflow()
@@ -123,7 +123,7 @@ class TestServerPlaybackState:
assert s._hash(r) != s._hash(r2)
def test_headers(self):
- s = flow.ServerPlaybackState(["foo"], [], False, False)
+ s = flow.ServerPlaybackState(["foo"], [], False, False, None, False)
r = tutils.tflow(resp=True)
r.request.headers["foo"] = ["bar"]
r2 = tutils.tflow(resp=True)
@@ -144,7 +144,7 @@ class TestServerPlaybackState:
r2 = tutils.tflow(resp=True)
r2.request.headers["key"] = ["two"]
- s = flow.ServerPlaybackState(None, [r, r2], False, False)
+ s = flow.ServerPlaybackState(None, [r, r2], False, False, None, False)
assert s.count() == 2
assert len(s.fmap.keys()) == 1
@@ -165,13 +165,53 @@ class TestServerPlaybackState:
r2 = tutils.tflow(resp=True)
r2.request.headers["key"] = ["two"]
- s = flow.ServerPlaybackState(None, [r, r2], False, True)
+ s = flow.ServerPlaybackState(None, [r, r2], False, True, None, False)
assert s.count() == 2
s.next_flow(r)
assert s.count() == 2
+ def test_ignore_params(self):
+ s = flow.ServerPlaybackState(None, [], False, False, ["param1", "param2"], False)
+ r = tutils.tflow(resp=True)
+ r.request.path="/test?param1=1"
+ r2 = tutils.tflow(resp=True)
+ r2.request.path="/test"
+ assert s._hash(r) == s._hash(r2)
+ r2.request.path="/test?param1=2"
+ assert s._hash(r) == s._hash(r2)
+ r2.request.path="/test?param2=1"
+ assert s._hash(r) == s._hash(r2)
+ r2.request.path="/test?param3=2"
+ assert not s._hash(r) == s._hash(r2)
+
+ def test_ignore_content(self):
+ s = flow.ServerPlaybackState(None, [], False, False, None, False)
+ r = tutils.tflow(resp=True)
+ r2 = tutils.tflow(resp=True)
+
+ r.request.content = "foo"
+ r2.request.content = "foo"
+ assert s._hash(r) == s._hash(r2)
+ r2.request.content = "bar"
+ assert not s._hash(r) == s._hash(r2)
+
+ #now ignoring content
+ s = flow.ServerPlaybackState(None, [], False, False, None, True)
+ r = tutils.tflow(resp=True)
+ r2 = tutils.tflow(resp=True)
+ r.request.content = "foo"
+ r2.request.content = "foo"
+ assert s._hash(r) == s._hash(r2)
+ r2.request.content = "bar"
+ assert s._hash(r) == s._hash(r2)
+ r2.request.content = ""
+ assert s._hash(r) == s._hash(r2)
+ r2.request.content = None
+ assert s._hash(r) == s._hash(r2)
+
+
class TestFlow:
def test_copy(self):
f = tutils.tflow(resp=True)
@@ -640,7 +680,7 @@ class TestFlowMaster:
f = tutils.tflow(resp=True)
pb = [tutils.tflow(resp=True), f]
fm = flow.FlowMaster(None, s)
- assert not fm.start_server_playback(pb, False, [], False, False)
+ assert not fm.start_server_playback(pb, False, [], False, False, None, False)
assert not fm.start_client_playback(pb, False)
q = Queue.Queue()
@@ -662,16 +702,16 @@ class TestFlowMaster:
fm.refresh_server_playback = True
assert not fm.do_server_playback(tutils.tflow())
- fm.start_server_playback(pb, False, [], False, False)
+ fm.start_server_playback(pb, False, [], False, False, None, False)
assert fm.do_server_playback(tutils.tflow())
- fm.start_server_playback(pb, False, [], True, False)
+ fm.start_server_playback(pb, False, [], True, False, None, False)
r = tutils.tflow()
r.request.content = "gibble"
assert not fm.do_server_playback(r)
assert fm.do_server_playback(tutils.tflow())
- fm.start_server_playback(pb, False, [], True, False)
+ fm.start_server_playback(pb, False, [], True, False, None, False)
q = Queue.Queue()
fm.tick(q, 0)
assert fm.should_exit.is_set()
@@ -686,7 +726,7 @@ class TestFlowMaster:
pb = [f]
fm = flow.FlowMaster(None, s)
fm.refresh_server_playback = True
- fm.start_server_playback(pb, True, [], False, False)
+ fm.start_server_playback(pb, True, [], False, False, None, False)
f = tutils.tflow()
f.request.host = "nonexistent"