From f21a970f294486e47b183472ef9f535e2a661604 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 29 Apr 2017 09:14:44 +1200 Subject: commands: marking Add "view.mark [flows] bool" and "view.mark.toggle [flows]". Use this to rebind marking keys in flowlist. --- test/mitmproxy/addons/test_core.py | 14 ++++++++++++++ test/mitmproxy/test_command.py | 6 ++++++ 2 files changed, 20 insertions(+) (limited to 'test') diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py index 39aac935..2d9ee751 100644 --- a/test/mitmproxy/addons/test_core.py +++ b/test/mitmproxy/addons/test_core.py @@ -26,3 +26,17 @@ def test_resume(): f.intercept() sa.resume([f]) assert not f.reply.state == "taken" + + +def test_mark(): + sa = core.Core() + with taddons.context(): + f = tflow.tflow() + assert not f.marked + sa.mark([f], True) + assert f.marked + + sa.mark_toggle([f]) + assert not f.marked + sa.mark_toggle([f]) + assert f.marked diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index 306650c7..96d79dba 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -76,10 +76,16 @@ def test_parsearg(): with taddons.context() as tctx: tctx.master.addons.add(DummyConsole()) assert command.parsearg(tctx.master.commands, "foo", str) == "foo" + assert command.parsearg(tctx.master.commands, "1", int) == 1 with pytest.raises(exceptions.CommandError): command.parsearg(tctx.master.commands, "foo", int) + assert command.parsearg(tctx.master.commands, "true", bool) is True + assert command.parsearg(tctx.master.commands, "false", bool) is False + with pytest.raises(exceptions.CommandError): + command.parsearg(tctx.master.commands, "flobble", bool) + assert len(command.parsearg( tctx.master.commands, "2", typing.Sequence[flow.Flow] )) == 2 -- cgit v1.2.3 From 7317ea134e467dd0bc8ad9129dd8a417b0a0fdfd Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 29 Apr 2017 09:58:32 +1200 Subject: command: flow.kill, flow.replay Plus the matching bindings in the flow list. --- test/mitmproxy/addons/test_core.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py index 2d9ee751..9501fb22 100644 --- a/test/mitmproxy/addons/test_core.py +++ b/test/mitmproxy/addons/test_core.py @@ -3,6 +3,7 @@ from mitmproxy.test import taddons from mitmproxy.test import tflow from mitmproxy import exceptions import pytest +from unittest import mock def test_set(): @@ -40,3 +41,22 @@ def test_mark(): assert not f.marked sa.mark_toggle([f]) assert f.marked + + +def test_replay(): + sa = core.Core() + with taddons.context(): + f = tflow.tflow() + with mock.patch("mitmproxy.master.Master.replay_request") as rp: + sa.replay(f) + assert rp.called + + +def test_kill(): + sa = core.Core() + with taddons.context(): + f = tflow.tflow() + f.intercept() + assert f.killable + sa.kill([f]) + assert not f.killable -- cgit v1.2.3 From a92017a6c1a0d7cf20f53e1cb4eb24716aaf55e6 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 29 Apr 2017 11:02:36 +1200 Subject: Rework client and server replay - Add client.replay [flows], client.replay.stop - Add server.replay [flows], server.replay.stop - The corresponding options for file loading are only read on startup, further changes are ignored. In interactive contexts, replay is started with the commands, not through option changes. - Deprecate flow.replay, use replay.client instead --- test/mitmproxy/addons/test_clientplayback.py | 9 ++++++++- test/mitmproxy/addons/test_core.py | 10 ---------- test/mitmproxy/addons/test_serverplayback.py | 1 + 3 files changed, 9 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/addons/test_clientplayback.py b/test/mitmproxy/addons/test_clientplayback.py index f71662f0..843d7409 100644 --- a/test/mitmproxy/addons/test_clientplayback.py +++ b/test/mitmproxy/addons/test_clientplayback.py @@ -26,7 +26,7 @@ class TestClientPlayback: with taddons.context() as tctx: assert cp.count() == 0 f = tflow.tflow(resp=True) - cp.load([f]) + cp.start_replay([f]) assert cp.count() == 1 RP = "mitmproxy.proxy.protocol.http_replay.RequestReplayThread" with mock.patch(RP) as rp: @@ -44,13 +44,20 @@ class TestClientPlayback: cp.tick() assert cp.current_thread is None + cp.start_replay([f]) + cp.stop_replay() + assert not cp.flows + def test_configure(self, tmpdir): cp = clientplayback.ClientPlayback() with taddons.context() as tctx: path = str(tmpdir.join("flows")) tdump(path, [tflow.tflow()]) tctx.configure(cp, client_replay=[path]) + cp.configured = False tctx.configure(cp, client_replay=[]) + cp.configured = False tctx.configure(cp) + cp.configured = False with pytest.raises(exceptions.OptionsError): tctx.configure(cp, client_replay=["nonexistent"]) diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py index 9501fb22..25fefb5d 100644 --- a/test/mitmproxy/addons/test_core.py +++ b/test/mitmproxy/addons/test_core.py @@ -3,7 +3,6 @@ from mitmproxy.test import taddons from mitmproxy.test import tflow from mitmproxy import exceptions import pytest -from unittest import mock def test_set(): @@ -43,15 +42,6 @@ def test_mark(): assert f.marked -def test_replay(): - sa = core.Core() - with taddons.context(): - f = tflow.tflow() - with mock.patch("mitmproxy.master.Master.replay_request") as rp: - sa.replay(f) - assert rp.called - - def test_kill(): sa = core.Core() with taddons.context(): diff --git a/test/mitmproxy/addons/test_serverplayback.py b/test/mitmproxy/addons/test_serverplayback.py index 29de48a0..e0c025fe 100644 --- a/test/mitmproxy/addons/test_serverplayback.py +++ b/test/mitmproxy/addons/test_serverplayback.py @@ -22,6 +22,7 @@ def test_config(tmpdir): fpath = str(tmpdir.join("flows")) tdump(fpath, [tflow.tflow(resp=True)]) tctx.configure(s, server_replay=[fpath]) + s.configured = False with pytest.raises(exceptions.OptionsError): tctx.configure(s, server_replay=[str(tmpdir)]) -- cgit v1.2.3