diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2017-03-16 15:40:43 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2017-03-16 18:33:24 +1300 |
commit | c5e0dc64b9b367eae8f4af66a4917c738dd87569 (patch) | |
tree | 8577458ea0e643e0f48d48e39dcb4f80a4317094 /test | |
parent | 3de982900381b9d3743e65defbfa413453cd3836 (diff) | |
download | mitmproxy-c5e0dc64b9b367eae8f4af66a4917c738dd87569.tar.gz mitmproxy-c5e0dc64b9b367eae8f4af66a4917c738dd87569.tar.bz2 mitmproxy-c5e0dc64b9b367eae8f4af66a4917c738dd87569.zip |
Rip out master handler mechanism
All events are now handled by addons, and we no longer support any events on
master.
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_disable_h2c.py | 1 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_intercept.py | 1 | ||||
-rw-r--r-- | test/mitmproxy/proxy/test_server.py | 1 | ||||
-rw-r--r-- | test/mitmproxy/test_controller.py | 25 | ||||
-rw-r--r-- | test/mitmproxy/test_examples.py | 22 | ||||
-rw-r--r-- | test/mitmproxy/test_flow.py | 10 | ||||
-rw-r--r-- | test/mitmproxy/test_http.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/test_taddons.py | 12 | ||||
-rw-r--r-- | test/mitmproxy/tools/console/test_master.py | 6 | ||||
-rw-r--r-- | test/mitmproxy/tools/test_dump.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/tools/web/test_app.py | 3 | ||||
-rw-r--r-- | test/mitmproxy/tservers.py | 15 |
12 files changed, 43 insertions, 57 deletions
diff --git a/test/mitmproxy/addons/test_disable_h2c.py b/test/mitmproxy/addons/test_disable_h2c.py index d4df8390..cf20a368 100644 --- a/test/mitmproxy/addons/test_disable_h2c.py +++ b/test/mitmproxy/addons/test_disable_h2c.py @@ -31,7 +31,6 @@ class TestDisableH2CleartextUpgrade: b = io.BytesIO(b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n") f = tflow.tflow() f.request = http.HTTPRequest.wrap(http1.read_request(b)) - f.reply.handle() f.intercept() a.request(f) diff --git a/test/mitmproxy/addons/test_intercept.py b/test/mitmproxy/addons/test_intercept.py index 465e6433..f436a817 100644 --- a/test/mitmproxy/addons/test_intercept.py +++ b/test/mitmproxy/addons/test_intercept.py @@ -29,6 +29,5 @@ def test_simple(): assert not f.intercepted f = tflow.tflow(resp=True) - f.reply._state = "handled" r.response(f) assert f.intercepted diff --git a/test/mitmproxy/proxy/test_server.py b/test/mitmproxy/proxy/test_server.py index 6f134b72..447b15a5 100644 --- a/test/mitmproxy/proxy/test_server.py +++ b/test/mitmproxy/proxy/test_server.py @@ -5,7 +5,6 @@ import pytest from unittest import mock from mitmproxy.test import tutils -from mitmproxy import controller from mitmproxy import options from mitmproxy.addons import script from mitmproxy.addons import proxyauth diff --git a/test/mitmproxy/test_controller.py b/test/mitmproxy/test_controller.py index 5f0e2d64..ccc8bf35 100644 --- a/test/mitmproxy/test_controller.py +++ b/test/mitmproxy/test_controller.py @@ -60,7 +60,6 @@ class TestChannel: def reply(): m, obj = q.get() assert m == "test" - obj.reply.handle() obj.reply.send(42) obj.reply.take() obj.reply.commit() @@ -82,10 +81,7 @@ class TestChannel: class TestReply: def test_simple(self): reply = controller.Reply(42) - assert reply.state == "unhandled" - - reply.handle() - assert reply.state == "handled" + assert reply.state == "start" reply.send("foo") assert reply.value == "foo" @@ -101,7 +97,6 @@ class TestReply: def test_kill(self): reply = controller.Reply(43) - reply.handle() reply.kill() reply.take() reply.commit() @@ -109,7 +104,6 @@ class TestReply: def test_ack(self): reply = controller.Reply(44) - reply.handle() reply.ack() reply.take() reply.commit() @@ -117,7 +111,6 @@ class TestReply: def test_reply_none(self): reply = controller.Reply(45) - reply.handle() reply.send(None) reply.take() reply.commit() @@ -125,7 +118,6 @@ class TestReply: def test_commit_no_reply(self): reply = controller.Reply(46) - reply.handle() reply.take() with pytest.raises(ControlException): reply.commit() @@ -134,7 +126,6 @@ class TestReply: def test_double_send(self): reply = controller.Reply(47) - reply.handle() reply.send(1) with pytest.raises(ControlException): reply.send(2) @@ -142,12 +133,11 @@ class TestReply: reply.commit() def test_state_transitions(self): - states = {"unhandled", "handled", "taken", "committed"} + states = {"start", "taken", "committed"} accept = { - "handle": {"unhandled"}, - "take": {"handled"}, + "take": {"start"}, "commit": {"taken"}, - "ack": {"handled", "taken"}, + "ack": {"start", "taken"}, } for fn, ok in accept.items(): for state in states: @@ -166,7 +156,6 @@ class TestReply: reply = controller.Reply(47) with pytest.raises(ControlException): reply.__del__() - reply.handle() reply.ack() reply.take() reply.commit() @@ -176,24 +165,22 @@ class TestDummyReply: def test_simple(self): reply = controller.DummyReply() for _ in range(2): - reply.handle() reply.ack() reply.take() reply.commit() reply.mark_reset() reply.reset() - assert reply.state == "unhandled" + assert reply.state == "start" def test_reset(self): reply = controller.DummyReply() - reply.handle() reply.ack() reply.take() reply.commit() reply.mark_reset() assert reply.state == "committed" reply.reset() - assert reply.state == "unhandled" + assert reply.state == "start" def test_del(self): reply = controller.DummyReply() diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index 56692364..030f2c4e 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -41,7 +41,7 @@ class TestScripts(tservers.MasterTest): def test_add_header(self): m, _ = tscript("simple/add_header.py") f = tflow.tflow(resp=tutils.tresp()) - m.response(f) + m.addons.handle_lifecycle("response", f) assert f.response.headers["newheader"] == "foo" def test_custom_contentviews(self): @@ -56,7 +56,7 @@ class TestScripts(tservers.MasterTest): m, sc = tscript("simple/modify_body_inject_iframe.py", "http://example.org/evil_iframe") f = tflow.tflow(resp=tutils.tresp(content=b"<html><body>mitmproxy</body></html>")) - m.response(f) + m.addons.handle_lifecycle("response", f) content = f.response.content assert b'iframe' in content and b'evil_iframe' in content @@ -65,41 +65,41 @@ class TestScripts(tservers.MasterTest): form_header = Headers(content_type="application/x-www-form-urlencoded") f = tflow.tflow(req=tutils.treq(headers=form_header)) - m.request(f) + m.addons.handle_lifecycle("request", f) assert f.request.urlencoded_form["mitmproxy"] == "rocks" f.request.headers["content-type"] = "" - m.request(f) + m.addons.handle_lifecycle("request", f) assert list(f.request.urlencoded_form.items()) == [("foo", "bar")] def test_modify_querystring(self): m, sc = tscript("simple/modify_querystring.py") f = tflow.tflow(req=tutils.treq(path="/search?q=term")) - m.request(f) + m.addons.handle_lifecycle("request", f) assert f.request.query["mitmproxy"] == "rocks" f.request.path = "/" - m.request(f) + m.addons.handle_lifecycle("request", f) assert f.request.query["mitmproxy"] == "rocks" def test_arguments(self): m, sc = tscript("simple/script_arguments.py", "mitmproxy rocks") f = tflow.tflow(resp=tutils.tresp(content=b"I <3 mitmproxy")) - m.response(f) + m.addons.handle_lifecycle("response", f) assert f.response.content == b"I <3 rocks" def test_redirect_requests(self): m, sc = tscript("simple/redirect_requests.py") f = tflow.tflow(req=tutils.treq(host="example.org")) - m.request(f) + m.addons.handle_lifecycle("request", f) assert f.request.host == "mitmproxy.org" def test_send_reply_from_proxy(self): m, sc = tscript("simple/send_reply_from_proxy.py") f = tflow.tflow(req=tutils.treq(host="example.com", port=80)) - m.request(f) + m.addons.handle_lifecycle("request", f) assert f.response.content == b"Hello World" def test_dns_spoofing(self): @@ -109,13 +109,13 @@ class TestScripts(tservers.MasterTest): host_header = Headers(host=original_host) f = tflow.tflow(req=tutils.treq(headers=host_header, port=80)) - m.requestheaders(f) + m.addons.handle_lifecycle("requestheaders", f) # Rewrite by reverse proxy mode f.request.scheme = "https" f.request.port = 443 - m.request(f) + m.addons.handle_lifecycle("request", f) assert f.request.scheme == "http" assert f.request.port == 80 diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 4f87a6ae..630fc7e4 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -122,19 +122,19 @@ class TestFlowMaster: fm = master.Master(None, DummyServer()) fm.addons.add(s) f = tflow.tflow(req=None) - fm.clientconnect(f.client_conn) + fm.addons.handle_lifecycle("clientconnect", f.client_conn) f.request = http.HTTPRequest.wrap(mitmproxy.test.tutils.treq()) - fm.request(f) + fm.addons.handle_lifecycle("request", f) assert len(s.flows) == 1 f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) - fm.response(f) + fm.addons.handle_lifecycle("response", f) assert len(s.flows) == 1 - fm.clientdisconnect(f.client_conn) + fm.addons.handle_lifecycle("clientdisconnect", f.client_conn) f.error = flow.Error("msg") - fm.error(f) + fm.addons.handle_lifecycle("error", f) fm.shutdown() diff --git a/test/mitmproxy/test_http.py b/test/mitmproxy/test_http.py index 889eb0a7..aa283530 100644 --- a/test/mitmproxy/test_http.py +++ b/test/mitmproxy/test_http.py @@ -175,7 +175,6 @@ class TestHTTPFlow: def test_kill(self): f = tflow.tflow() - f.reply.handle() f.intercept() assert f.killable f.kill() @@ -184,7 +183,6 @@ class TestHTTPFlow: def test_resume(self): f = tflow.tflow() - f.reply.handle() f.intercept() assert f.reply.state == "taken" f.resume() diff --git a/test/mitmproxy/test_taddons.py b/test/mitmproxy/test_taddons.py new file mode 100644 index 00000000..1e42141c --- /dev/null +++ b/test/mitmproxy/test_taddons.py @@ -0,0 +1,12 @@ + +from mitmproxy.test import taddons +from mitmproxy import ctx + + +def test_recordingmaster(): + with taddons.context() as tctx: + assert not tctx.master.has_log("nonexistent") + assert not tctx.master.has_event("nonexistent") + ctx.log.error("foo") + assert not tctx.master.has_log("foo", level="debug") + assert tctx.master.has_log("foo", level="error") diff --git a/test/mitmproxy/tools/console/test_master.py b/test/mitmproxy/tools/console/test_master.py index 45908450..44b9ff3f 100644 --- a/test/mitmproxy/tools/console/test_master.py +++ b/test/mitmproxy/tools/console/test_master.py @@ -52,11 +52,11 @@ class TestMaster(tservers.MasterTest): """regression test for https://github.com/mitmproxy/mitmproxy/issues/1605""" m = self.mkmaster(intercept="~b bar") f = tflow.tflow(req=tutils.treq(content=b"foo")) - m.request(f) + m.addons.handle_lifecycle("request", f) assert not m.view[0].intercepted f = tflow.tflow(req=tutils.treq(content=b"bar")) - m.request(f) + m.addons.handle_lifecycle("request", f) assert m.view[1].intercepted f = tflow.tflow(resp=tutils.tresp(content=b"bar")) - m.request(f) + m.addons.handle_lifecycle("request", f) assert m.view[2].intercepted diff --git a/test/mitmproxy/tools/test_dump.py b/test/mitmproxy/tools/test_dump.py index 810fcaaa..8e2fa5b2 100644 --- a/test/mitmproxy/tools/test_dump.py +++ b/test/mitmproxy/tools/test_dump.py @@ -20,7 +20,7 @@ class TestDumpMaster(tservers.MasterTest): m = self.mkmaster(None) ent = log.LogEntry("foo", "error") ent.reply = controller.DummyReply() - m.log(ent) + m.addons.trigger("log", ent) assert m.errorcheck.has_errored @pytest.mark.parametrize("termlog", [False, True]) diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py index 00dc2c7c..e3d5dc44 100644 --- a/test/mitmproxy/tools/web/test_app.py +++ b/test/mitmproxy/tools/web/test_app.py @@ -83,7 +83,6 @@ class TestApp(tornado.testing.AsyncHTTPTestCase): def test_resume(self): for f in self.view: - f.reply.handle() f.intercept() assert self.fetch( @@ -95,7 +94,6 @@ class TestApp(tornado.testing.AsyncHTTPTestCase): def test_kill(self): for f in self.view: f.backup() - f.reply.handle() f.intercept() assert self.fetch("/flows/42/kill", method="POST").code == 200 @@ -109,7 +107,6 @@ class TestApp(tornado.testing.AsyncHTTPTestCase): f = self.view.get_by_id("42") assert f - f.reply.handle() assert self.fetch("/flows/42", method="DELETE").code == 200 assert not self.view.get_by_id("42") diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py index 9568976e..b737b82a 100644 --- a/test/mitmproxy/tservers.py +++ b/test/mitmproxy/tservers.py @@ -10,10 +10,10 @@ from mitmproxy import controller from mitmproxy import options from mitmproxy import exceptions from mitmproxy import io -from mitmproxy import http import pathod.test import pathod.pathoc +from mitmproxy import eventsequence from mitmproxy.test import tflow from mitmproxy.test import tutils from mitmproxy.test import taddons @@ -23,15 +23,10 @@ class MasterTest: def cycle(self, master, content): f = tflow.tflow(req=tutils.treq(content=content)) - master.clientconnect(f.client_conn) - master.serverconnect(f.server_conn) - master.request(f) - if not f.error: - f.response = http.HTTPResponse.wrap( - tutils.tresp(content=content) - ) - master.response(f) - master.clientdisconnect(f) + master.addons.handle_lifecycle("clientconnect", f.client_conn) + for i in eventsequence.iterate(f): + master.addons.handle_lifecycle(*i) + master.addons.handle_lifecycle("clientdisconnect", f.client_conn) return f def dummy_cycle(self, master, n, content): |