diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index cc7e2e761..5a354fd2d 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -6,6 +6,27 @@ import sys from . import exceptions +Events = frozenset([ + "clientconnect", + "clientdisconnect", + "serverconnect", + "serverdisconnect", + + "tcp_open", + "tcp_message", + "tcp_error", + "tcp_close", + + "request", + "response", + "responseheaders", + + "next_layer", + + "error", + "log", +]) + class ControlError(Exception): pass @@ -43,6 +64,8 @@ class Master(object): # exception is thrown. while True: mtype, obj = self.event_queue.get(timeout=timeout) + if mtype not in Events: + raise ControlError("Unknown event %s"%repr(mtype)) handle_func = getattr(self, "handle_" + mtype) if not handle_func.func_dict.get("handler"): raise ControlError( diff --git a/test/mitmproxy/test_controller.py b/test/mitmproxy/test_controller.py index fbbebaa6c..4b8656da9 100644 --- a/test/mitmproxy/test_controller.py +++ b/test/mitmproxy/test_controller.py @@ -18,7 +18,7 @@ class TestMaster(object): def test_simple(self): class DummyMaster(controller.Master): @controller.handler - def handle_panic(self, _): + def handle_log(self, _): m.should_exit.set() def tick(self, timeout): @@ -29,7 +29,7 @@ class TestMaster(object): assert not m.should_exit.is_set() msg = TMsg() msg.reply = controller.DummyReply() - m.event_queue.put(("panic", msg)) + m.event_queue.put(("log", msg)) m.run() assert m.should_exit.is_set()