aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2018-02-24 12:13:52 +1300
committerAldo Cortesi <aldo@corte.si>2018-02-24 12:13:52 +1300
commit4522a6f7b754be26084c40df5ecc7349023a692e (patch)
treefb3eeba45aebfb77558aba0ab0ed033f84e52099 /test
parent58ccad7576e5fd33e937aba58df2f9edc389e52e (diff)
downloadmitmproxy-4522a6f7b754be26084c40df5ecc7349023a692e.tar.gz
mitmproxy-4522a6f7b754be26084c40df5ecc7349023a692e.tar.bz2
mitmproxy-4522a6f7b754be26084c40df5ecc7349023a692e.zip
Start moving addon options into /addons
This takes the first few steps: - Extends taddons to make loading addon options easier - Removes dependencies in the test suite on options in addons - Tweaks command-line parser autocreation to ignore nonexistent options. This lets us load common options without over-depending on loaded addons.
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_anticache.py2
-rw-r--r--test/mitmproxy/addons/test_anticomp.py2
-rw-r--r--test/mitmproxy/addons/test_core.py6
-rw-r--r--test/mitmproxy/test_optmanager.py7
-rw-r--r--test/mitmproxy/tools/console/test_statusbar.py8
5 files changed, 13 insertions, 12 deletions
diff --git a/test/mitmproxy/addons/test_anticache.py b/test/mitmproxy/addons/test_anticache.py
index 928f2180..d1765fe0 100644
--- a/test/mitmproxy/addons/test_anticache.py
+++ b/test/mitmproxy/addons/test_anticache.py
@@ -7,7 +7,7 @@ from mitmproxy.test import taddons
class TestAntiCache:
def test_simple(self):
sa = anticache.AntiCache()
- with taddons.context() as tctx:
+ with taddons.context(sa) as tctx:
f = tflow.tflow(resp=True)
f.request.headers["if-modified-since"] = "test"
f.request.headers["if-none-match"] = "test"
diff --git a/test/mitmproxy/addons/test_anticomp.py b/test/mitmproxy/addons/test_anticomp.py
index 2a6cf3ce..92650332 100644
--- a/test/mitmproxy/addons/test_anticomp.py
+++ b/test/mitmproxy/addons/test_anticomp.py
@@ -7,7 +7,7 @@ from mitmproxy.test import taddons
class TestAntiComp:
def test_simple(self):
sa = anticomp.AntiComp()
- with taddons.context() as tctx:
+ with taddons.context(sa) as tctx:
f = tflow.tflow(resp=True)
sa.request(f)
diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py
index 5aa4ef37..5c9a8a0d 100644
--- a/test/mitmproxy/addons/test_core.py
+++ b/test/mitmproxy/addons/test_core.py
@@ -10,9 +10,9 @@ def test_set():
with taddons.context() as tctx:
tctx.master.addons.add(sa)
- assert not tctx.master.options.anticomp
- tctx.command(sa.set, "anticomp")
- assert tctx.master.options.anticomp
+ assert tctx.master.options.server
+ tctx.command(sa.set, "server=false")
+ assert not tctx.master.options.server
with pytest.raises(exceptions.CommandError):
tctx.command(sa.set, "nonexistent")
diff --git a/test/mitmproxy/test_optmanager.py b/test/mitmproxy/test_optmanager.py
index d9b93227..cd8857ca 100644
--- a/test/mitmproxy/test_optmanager.py
+++ b/test/mitmproxy/test_optmanager.py
@@ -351,7 +351,7 @@ def test_dump_defaults():
def test_dump_dicts():
o = options.Options()
assert optmanager.dump_dicts(o)
- assert optmanager.dump_dicts(o, ['http2', 'anticomp'])
+ assert optmanager.dump_dicts(o, ['http2', 'listen_port'])
class TTypes(optmanager.OptManager):
@@ -375,8 +375,9 @@ def test_make_parser():
opts.make_parser(parser, "int", short="c")
opts.make_parser(parser, "seqstr", short="d")
opts.make_parser(parser, "bool_on", short="e")
- with pytest.raises(ValueError):
- opts.make_parser(parser, "unknown")
+
+ # No error for nonexistent options
+ opts.make_parser(parser, "xxxxxxx")
def test_set():
diff --git a/test/mitmproxy/tools/console/test_statusbar.py b/test/mitmproxy/tools/console/test_statusbar.py
index 8522eb96..ac17c5c0 100644
--- a/test/mitmproxy/tools/console/test_statusbar.py
+++ b/test/mitmproxy/tools/console/test_statusbar.py
@@ -3,7 +3,9 @@ from mitmproxy.tools.console import statusbar, master
def test_statusbar(monkeypatch):
- o = options.Options(
+ o = options.Options()
+ m = master.ConsoleMaster(o)
+ m.options.update(
setheaders=[":~q:foo:bar"],
replacements=[":~q:foo:bar"],
ignore_hosts=["example.com", "example.org"],
@@ -21,10 +23,8 @@ def test_statusbar(monkeypatch):
upstream_cert=False,
stream_large_bodies="3m",
mode="transparent",
- scripts=["nonexistent"],
- save_stream_file="foo",
)
- m = master.ConsoleMaster(o)
+
m.options.update(view_order='url', console_focus_follow=True)
monkeypatch.setattr(m.addons.get("clientplayback"), "count", lambda: 42)
monkeypatch.setattr(m.addons.get("serverplayback"), "count", lambda: 42)