def handler(f): k[0] += 1 if not (k[0] in exclude): f.client_conn.finish() f.error = Error("terminated") f.reply(Kill) return _func(f)
def handler(*args): f = args[-1] k[0] += 1 if not (k[0] in exclude): f.client_conn.finish() f.error = Error("terminated") f.reply.kill() return _func(f)
def test_getset_state(self): f = tutils.tflow(resp=True) state = f.get_state() assert f.get_state() == HTTPFlow.from_state(state).get_state() f.response = None f.error = Error("error") state = f.get_state() assert f.get_state() == HTTPFlow.from_state(state).get_state() f2 = f.copy() f2.id = f.id # copy creates a different uuid assert f.get_state() == f2.get_state() assert not f == f2 f2.error = Error("e2") assert not f == f2 f.set_state(f2.get_state()) assert f.get_state() == f2.get_state()
def test_err(self): c = flow.State() f = tutils.tflow() c.add_flow(f) f.error = Error("message") assert c.update_flow(f) c = flow.State() f = tutils.tflow() c.add_flow(f) c.set_limit("~e") assert not c.view f.error = tutils.terr() assert c.update_flow(f) assert c.view
def test_client_playback(self): s = flow.State() f = tutils.tflow(resp=True) pb = [tutils.tflow(resp=True), f] fm = flow.FlowMaster(options.Options(), DummyServer(ProxyConfig(options.Options())), s) assert not fm.start_client_playback(pb, False) fm.client_playback.testing = True assert not fm.state.flow_count() fm.tick(0) assert fm.state.flow_count() f.error = Error("error") fm.error(f)
def test_client_playback(self): s = flow.State() f = tutils.tflow(resp=True) pb = [tutils.tflow(resp=True), f] fm = flow.FlowMaster(DummyServer(ProxyConfig()), s) assert not fm.start_server_playback(pb, False, [], False, False, None, False, None, False) assert not fm.start_client_playback(pb, False) fm.client_playback.testing = True q = queue.Queue() assert not fm.state.flow_count() fm.tick(q, 0) assert fm.state.flow_count() f.error = Error("error") fm.handle_error(f)
def test_all(self): s = flow.State() fm = flow.FlowMaster(None, None, s) f = tutils.tflow(req=None) fm.clientconnect(f.client_conn) f.request = HTTPRequest.wrap(netlib.tutils.treq()) fm.request(f) assert s.flow_count() == 1 f.response = HTTPResponse.wrap(netlib.tutils.tresp()) fm.response(f) assert s.flow_count() == 1 fm.clientdisconnect(f.client_conn) f.error = Error("msg") fm.error(f) fm.shutdown()
def test_all(self): s = flow.State() fm = flow.FlowMaster(None, s) fm.anticache = True fm.anticomp = True f = tutils.tflow(req=None) fm.clientconnect(f.client_conn) f.request = HTTPRequest.wrap(netlib.tutils.treq()) fm.request(f) assert s.flow_count() == 1 f.response = HTTPResponse.wrap(netlib.tutils.tresp()) fm.response(f) assert s.flow_count() == 1 fm.clientdisconnect(f.client_conn) f.error = Error("msg") f.error.reply = controller.DummyReply() fm.error(f) fm.load_script(tutils.test_data.path("data/scripts/a.py")) fm.shutdown()
def terr(content="error"): """ @return: mitmproxy.protocol.primitives.Error """ err = Error(content) return err
def test_getset_state(self): e = Error("Error") state = e.get_state() assert Error.from_state(state).get_state() == e.get_state() assert e.copy() e2 = Error("bar") assert not e == e2 e.set_state(e2.get_state()) assert e.get_state() == e2.get_state() e3 = e.copy() assert e3.get_state() == e.get_state()
def test_getset_state(self): e = Error("Error") state = e.get_state() assert Error.from_state(state).get_state() == e.get_state() assert e.copy() e2 = Error("bar") assert not e == e2 e.set_state(e2.get_state()) assert e.get_state() == e2.get_state() e3 = e.copy() assert e3.get_state() == e.get_state()
def test_repr(self): e = Error("yay") assert repr(e)
def err(self): f = self.req() f.error = Error("msg") return f