From 9695377b283f97c872e4ddbb27060883c3c32980 Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Mon, 5 Jan 2015 18:12:38 -0300 Subject: [PATCH 1/3] first steps in scenario support --- libmproxy/cmdline.py | 4 ++-- libmproxy/dump.py | 10 ++++++---- test/test_dump.py | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index 185944da4..e45cc54c2 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -418,14 +418,14 @@ def common_options(parser): group = parser.add_argument_group("Client Replay") group.add_argument( "-c", "--client-replay", - action="store", dest="client_replay", default=None, metavar="PATH", + action="append", dest="client_replay", default=None, metavar="PATH", help="Replay client requests from a saved file." ) group = parser.add_argument_group("Server Replay") group.add_argument( "-S", "--server-replay", - action="store", dest="server_replay", default=None, metavar="PATH", + action="append", dest="server_replay", default=None, metavar="PATH", help="Replay server responses from a saved file." ) group.add_argument( diff --git a/libmproxy/dump.py b/libmproxy/dump.py index 91ccb42b4..c4a70a146 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -143,11 +143,13 @@ class DumpMaster(flow.FlowMaster): if self.o.app: self.start_app(self.o.app_host, self.o.app_port) - def _readflow(self, path): - path = os.path.expanduser(path) + def _readflow(self, paths): try: - f = file(path, "rb") - flows = list(flow.FlowReader(f).stream()) + flows = [] + for path in paths: + path = os.path.expanduser(path) + f = file(path, "rb") + flows.extend(list(flow.FlowReader(f).stream())) except (IOError, flow.FlowReadError), v: raise DumpError(v.strerror) return flows diff --git a/test/test_dump.py b/test/test_dump.py index 927b5b505..69df912f5 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -82,17 +82,17 @@ class TestDumpMaster: p = os.path.join(t, "rep") self._flowfile(p) - o = dump.Options(server_replay=p, kill=True) + o = dump.Options(server_replay=[p], kill=True) m = dump.DumpMaster(None, o, outfile=cs) self._cycle(m, "content") self._cycle(m, "content") - o = dump.Options(server_replay=p, kill=False) + o = dump.Options(server_replay=[p], kill=False) m = dump.DumpMaster(None, o, outfile=cs) self._cycle(m, "nonexistent") - o = dump.Options(client_replay=p, kill=False) + o = dump.Options(client_replay=[p], kill=False) m = dump.DumpMaster(None, o, outfile=cs) def test_read(self): From 30213d6370bca2bb222e315a63bf4d924a9b0b94 Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Tue, 6 Jan 2015 15:49:49 -0300 Subject: [PATCH 2/3] now mitmproxy supports multiple saved flows files too. also fixed server_play_back start with mitmproxy (missing parameter) --- libmproxy/console/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index f5b6a2a60..e2a0ec75f 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -496,11 +496,13 @@ class ConsoleMaster(flow.FlowMaster): self.eventlog = not self.eventlog self.view_flowlist() - def _readflow(self, path): - path = os.path.expanduser(path) + def _readflow(self, paths): try: - f = file(path, "rb") - flows = list(flow.FlowReader(f).stream()) + flows = [] + for path in paths: + path = os.path.expanduser(path) + f = file(path, "rb") + flows.extend(list(flow.FlowReader(f).stream())) except (IOError, flow.FlowReadError), v: return True, v.strerror return False, flows @@ -521,7 +523,7 @@ class ConsoleMaster(flow.FlowMaster): ret, self.killextra, self.rheaders, False, self.nopop, - self.options.replay_ignore_params, self.options.replay_ignore_content + self.options.replay_ignore_params, self.options.replay_ignore_content, self.options.replay_ignore_payload_params ) def spawn_editor(self, data): From 4f578866fac9e8261ad659d9a04c87822d7c9aab Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Mon, 12 Jan 2015 14:31:18 -0300 Subject: [PATCH 3/3] open flow files using with as max suggested --- libmproxy/console/__init__.py | 4 ++-- libmproxy/dump.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index b2f4d96c7..559c78d4a 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -501,8 +501,8 @@ class ConsoleMaster(flow.FlowMaster): flows = [] for path in paths: path = os.path.expanduser(path) - f = file(path, "rb") - flows.extend(list(flow.FlowReader(f).stream())) + with file(path, "rb") as f: + flows.extend(list(flow.FlowReader(f).stream())) except (IOError, flow.FlowReadError), v: return True, v.strerror return False, flows diff --git a/libmproxy/dump.py b/libmproxy/dump.py index c4a70a146..70f175f6a 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -148,8 +148,8 @@ class DumpMaster(flow.FlowMaster): flows = [] for path in paths: path = os.path.expanduser(path) - f = file(path, "rb") - flows.extend(list(flow.FlowReader(f).stream())) + with file(path, "rb") as f: + flows.extend(list(flow.FlowReader(f).stream())) except (IOError, flow.FlowReadError), v: raise DumpError(v.strerror) return flows