diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2017-04-27 15:27:51 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2017-04-27 15:27:51 +1200 |
commit | 8c4810f6069bcf592d480e5cc2d7338cd176085e (patch) | |
tree | f3e76c6b5af13e57e84cce28c2acc35a9018aad4 /test | |
parent | ee3dd3f3c5b6fe42df547156f25ab6e6f6578fff (diff) | |
download | mitmproxy-8c4810f6069bcf592d480e5cc2d7338cd176085e.tar.gz mitmproxy-8c4810f6069bcf592d480e5cc2d7338cd176085e.tar.bz2 mitmproxy-8c4810f6069bcf592d480e5cc2d7338cd176085e.zip |
console: flow resolution command
This is our first built-in command, which will be used by very many other
commands.
Also add a --commands option to dump all commands, analogous to --options.
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_view.py | 40 | ||||
-rw-r--r-- | test/mitmproxy/test_command.py | 5 |
2 files changed, 43 insertions, 2 deletions
diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index 7fa3819e..aca357a2 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -130,6 +130,46 @@ def test_filter(): assert len(v) == 4 +def test_resolve(): + v = view.View() + with taddons.context(options=options.Options()) as tctx: + assert tctx.command(v.resolve, "@focus") == [] + assert tctx.command(v.resolve, "@shown") == [] + assert tctx.command(v.resolve, "@hidden") == [] + assert tctx.command(v.resolve, "@marked") == [] + assert tctx.command(v.resolve, "@unmarked") == [] + assert tctx.command(v.resolve, "~m get") == [] + v.request(tft(method="get")) + assert len(tctx.command(v.resolve, "~m get")) == 1 + assert len(tctx.command(v.resolve, "@focus")) == 1 + assert len(tctx.command(v.resolve, "@shown")) == 1 + assert len(tctx.command(v.resolve, "@unmarked")) == 1 + assert tctx.command(v.resolve, "@hidden") == [] + assert tctx.command(v.resolve, "@marked") == [] + v.request(tft(method="put")) + assert len(tctx.command(v.resolve, "@focus")) == 1 + assert len(tctx.command(v.resolve, "@shown")) == 2 + assert tctx.command(v.resolve, "@hidden") == [] + assert tctx.command(v.resolve, "@marked") == [] + + v.request(tft(method="get")) + v.request(tft(method="put")) + + f = flowfilter.parse("~m get") + v.set_filter(f) + v[0].marked = True + + def m(l): + return [i.request.method for i in l] + + assert m(tctx.command(v.resolve, "~m get")) == ["GET", "GET"] + assert m(tctx.command(v.resolve, "~m put")) == ["PUT", "PUT"] + assert m(tctx.command(v.resolve, "@shown")) == ["GET", "GET"] + assert m(tctx.command(v.resolve, "@hidden")) == ["PUT", "PUT"] + assert m(tctx.command(v.resolve, "@marked")) == ["GET"] + assert m(tctx.command(v.resolve, "@unmarked")) == ["PUT", "GET", "PUT"] + + def test_order(): v = view.View() with taddons.context(options=options.Options()) as tctx: diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index d4da7c32..7d0359fa 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -2,6 +2,7 @@ from mitmproxy import command from mitmproxy import master from mitmproxy import options from mitmproxy import proxy +from mitmproxy import exceptions import pytest @@ -29,7 +30,7 @@ def test_simple(): a = TAddon() c.add("one.two", a.cmd1) assert(c.call("one.two foo") == "ret foo") - with pytest.raises(command.CommandError, match="Unknown"): + with pytest.raises(exceptions.CommandError, match="Unknown"): c.call("nonexistent") - with pytest.raises(command.CommandError, match="Invalid"): + with pytest.raises(exceptions.CommandError, match="Invalid"): c.call("") |