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 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 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.load_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_all(self): s = flow.State() fm = flow.FlowMaster(None, s) fm.anticache = True fm.anticomp = True f = tutils.tflow(req=None) fm.handle_clientconnect(f.client_conn) f.request = HTTPRequest.wrap(netlib.tutils.treq()) fm.handle_request(f) assert s.flow_count() == 1 f.response = HTTPResponse.wrap(netlib.tutils.tresp()) fm.handle_response(f) assert not fm.handle_response(None) assert s.flow_count() == 1 fm.handle_clientdisconnect(f.client_conn) f.error = Error("msg") f.error.reply = controller.DummyReply() fm.handle_error(f) fm.load_script(tutils.test_data.path("scripts/a.py")) fm.shutdown()
def err(self): f = self.req() f.error = Error("msg") return f
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.load_state(e2.get_state()) assert e.get_state() == e2.get_state() e3 = e.copy() assert e3.get_state() == e.get_state()
def terr(content="error"): """ @return: libmproxy.protocol.primitives.Error """ err = Error(content) return err