def test_nesting(): o = options.Options() m = master.Master(o) a = addonmanager.AddonManager(m) a.add( TAddon( "one", addons=[TAddon("two"), TAddon("three", addons=[TAddon("four")])])) assert len(a.chain) == 1 assert a.get("one") assert a.get("two") assert a.get("three") assert a.get("four") a.trigger("custom") assert a.get("one").custom_called assert a.get("two").custom_called assert a.get("three").custom_called assert a.get("four").custom_called a.remove(a.get("three")) assert not a.get("three") assert not a.get("four")
def test_simple(): o = options.Options() m = master.Master(o, proxy.DummyServer(o)) a = addonmanager.AddonManager(m) with pytest.raises(exceptions.AddonError): a.invoke_addon(TAddon("one"), "done") assert len(a) == 0 a.add(TAddon("one")) assert a.get("one") assert not a.get("two") assert len(a) == 1 a.clear() assert len(a) == 0 assert not a.chain a.add(TAddon("one")) a.trigger("done") with pytest.raises(exceptions.AddonError): a.trigger("tick") a.remove(a.get("one")) assert not a.get("one") ta = TAddon("one") a.add(ta) a.trigger("custom") assert ta.custom_called
def test_loadchain(): o = options.Options() m = master.Master(o, proxy.DummyServer(o)) a = addonmanager.AddonManager(m) a.add(AChain("one", None)) assert a.get("one") a.clear() a.add(AChain("one", AChain("two", None))) assert not a.get("one") assert a.get("two") a.clear() a.add(AChain("one", AChain("two", AChain("three", None)))) assert not a.get("one") assert not a.get("two") assert a.get("three") a.clear() a.add(AChain("one", AChain("two", AChain("three", AChain("four", None))))) assert not a.get("one") assert not a.get("two") assert not a.get("three") assert a.get("four") a.clear()
def __init__(self, opts): self.options = opts or options.Options() # type: options.Options self.commands = command.CommandManager(self) self.addons = addonmanager.AddonManager(self) self.event_queue = queue.Queue() self.should_exit = threading.Event() self._server = None self.first_tick = True
def __init__(self, opts, server): self.options = opts or options.Options() self.addons = addonmanager.AddonManager(self) self.event_queue = queue.Queue() self.should_exit = threading.Event() self.server = server channel = controller.Channel(self.event_queue, self.should_exit) server.set_channel(channel)
def test_simple(): o = options.Options() m = master.Master(o, proxy.DummyServer(o)) a = addonmanager.AddonManager(m) a.add(TAddon("one")) assert a.get("one") assert not a.get("two") a.clear() assert not a.chain
def test_lifecycle(): o = options.Options() m = master.Master(o, proxy.DummyServer(o)) a = addonmanager.AddonManager(m) a.add(TAddon("one")) f = tflow.tflow() a.handle_lifecycle("request", f) a.configure_all(o, o.keys())
def __init__(self, opts): self.should_exit = threading.Event() self.event_loop = asyncio.get_event_loop() self.options: options.Options = opts or options.Options() self.commands = command.CommandManager(self) self.addons = addonmanager.AddonManager(self) self._server = None self.log = log.Log(self) mitmproxy_ctx.master = self mitmproxy_ctx.log = self.log mitmproxy_ctx.options = self.options
def test_simple(): o = options.Options() m = master.Master(o, proxy.DummyServer(o)) a = addonmanager.AddonManager(m) a.add(TAddon("one")) assert a.get("one") assert not a.get("two") a.clear() assert not a.chain a.add(TAddon("one")) a("noop") with pytest.raises(exceptions.AddonError): a("noop_member")
def test_lifecycle(): o = options.Options() m = master.Master(o) a = addonmanager.AddonManager(m) a.add(TAddon("one")) with pytest.raises(exceptions.AddonManagerError): a.add(TAddon("one")) with pytest.raises(exceptions.AddonManagerError): a.remove(TAddon("nonexistent")) f = tflow.tflow() a.handle_lifecycle("request", f) a._configure_all(o, o.keys())
def test_halt(): o = options.Options() m = master.Master(o) a = addonmanager.AddonManager(m) halt = THalt() end = TAddon("end") a.add(halt) a.add(end) a.trigger("custom") assert not end.custom_called a.remove(halt) a.trigger("custom") assert end.custom_called
def test_halt(): o = options.Options() m = master.Master(o) a = addonmanager.AddonManager(m) halt = THalt() end = TAddon("end") a.add(halt) a.add(end) assert not end.running_called a.trigger(hooks.RunningHook()) assert not end.running_called a.remove(halt) a.trigger(hooks.RunningHook()) assert end.running_called
def __init__(self, opts, event_loop: Optional[asyncio.AbstractEventLoop] = None): self.options: options.Options = opts or options.Options() self.commands = command.CommandManager(self) self.addons = addonmanager.AddonManager(self) self.log = log.Log(self) # We expect an active event loop here already because some addons # may want to spawn tasks during the initial configuration phase, # which happens before run(). self.event_loop = event_loop or asyncio.get_running_loop() try: self.should_exit = asyncio.Event() except RuntimeError: self.should_exit = asyncio.Event(loop=self.event_loop) mitmproxy_ctx.master = self mitmproxy_ctx.log = self.log mitmproxy_ctx.options = self.options
def __init__(self, opts): self.event_queue = asyncio.Queue() self.should_exit = threading.Event() self.channel = controller.Channel( asyncio.get_event_loop(), self.event_queue, self.should_exit, ) asyncio.ensure_future(self.main()) asyncio.ensure_future(self.tick()) self.options = opts or options.Options() # type: options.Options self.commands = command.CommandManager(self) self.addons = addonmanager.AddonManager(self) self._server = None self.first_tick = True self.waiting_flows = []
def __init__(self, opts): self.should_exit = threading.Event() self.channel = controller.Channel( self, asyncio.get_event_loop(), self.should_exit, ) self.options: options.Options = opts or options.Options() self.commands = command.CommandManager(self) self.addons = addonmanager.AddonManager(self) self._server = None self.waiting_flows = [] self.log = log.Log(self) mitmproxy_ctx.master = self mitmproxy_ctx.log = self.log mitmproxy_ctx.options = self.options
def test_load_option(): o = options.Options() m = master.Master(o) a = addonmanager.AddonManager(m) a.add(AOption()) assert "custom_option" in m.options._options