aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2018-02-24 15:45:12 +1300
committerAldo Cortesi <aldo@nullcube.com>2018-02-24 15:45:12 +1300
commit704c1db1b7aa25c4ee6371bec811e92409b92398 (patch)
treec0cb32622569af0e0dc56e85e7c20486e6eaa05b /test
parent12633adeb9cbe3a81df2f6dfd9b739eae26bdcba (diff)
downloadmitmproxy-704c1db1b7aa25c4ee6371bec811e92409b92398.tar.gz
mitmproxy-704c1db1b7aa25c4ee6371bec811e92409b92398.tar.bz2
mitmproxy-704c1db1b7aa25c4ee6371bec811e92409b92398.zip
addon options: setheaders, stickyauth
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_core.py19
-rw-r--r--test/mitmproxy/addons/test_script.py11
-rw-r--r--test/mitmproxy/addons/test_setheaders.py4
-rw-r--r--test/mitmproxy/addons/test_stickyauth.py4
4 files changed, 16 insertions, 22 deletions
diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py
index 5c9a8a0d..3f95bed4 100644
--- a/test/mitmproxy/addons/test_core.py
+++ b/test/mitmproxy/addons/test_core.py
@@ -128,28 +128,23 @@ def test_options(tmpdir):
p = str(tmpdir.join("path"))
sa = core.Core()
with taddons.context() as tctx:
- tctx.options.stickycookie = "foo"
- assert tctx.options.stickycookie == "foo"
- sa.options_reset()
- assert tctx.options.stickycookie is None
-
- tctx.options.stickycookie = "foo"
- tctx.options.stickyauth = "bar"
- sa.options_reset_one("stickycookie")
- assert tctx.options.stickycookie is None
- assert tctx.options.stickyauth == "bar"
+ tctx.options.listen_host = "foo"
+ assert tctx.options.listen_host == "foo"
+ sa.options_reset_one("listen_host")
+ assert tctx.options.listen_host != "foo"
with pytest.raises(exceptions.CommandError):
sa.options_reset_one("unknown")
+ tctx.options.listen_host = "foo"
sa.options_save(p)
with pytest.raises(exceptions.CommandError):
sa.options_save("/")
sa.options_reset()
- assert tctx.options.stickyauth is None
+ assert tctx.options.listen_host == ""
sa.options_load(p)
- assert tctx.options.stickyauth == "bar"
+ assert tctx.options.listen_host == "foo"
sa.options_load("/nonexistent")
diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py
index 78a5be6c..73641d24 100644
--- a/test/mitmproxy/addons/test_script.py
+++ b/test/mitmproxy/addons/test_script.py
@@ -171,7 +171,7 @@ class TestScriptLoader:
"mitmproxy/data/addonscripts/recorder/recorder.py"
)
sc = script.ScriptLoader()
- with taddons.context() as tctx:
+ with taddons.context(sc) as tctx:
sc.script_run([tflow.tflow(resp=True)], rp)
debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
assert debug == [
@@ -183,7 +183,7 @@ class TestScriptLoader:
def test_script_run_nonexistent(self):
sc = script.ScriptLoader()
- with taddons.context():
+ with taddons.context(sc):
with pytest.raises(exceptions.CommandError):
sc.script_run([tflow.tflow(resp=True)], "/")
@@ -208,8 +208,7 @@ class TestScriptLoader:
def test_dupes(self):
sc = script.ScriptLoader()
- with taddons.context() as tctx:
- tctx.master.addons.add(sc)
+ with taddons.context(sc) as tctx:
with pytest.raises(exceptions.OptionsError):
tctx.configure(
sc,
@@ -232,7 +231,7 @@ class TestScriptLoader:
def test_load_err(self):
sc = script.ScriptLoader()
- with taddons.context() as tctx:
+ with taddons.context(sc) as tctx:
tctx.configure(sc, scripts=[
tutils.test_data.path("mitmproxy/data/addonscripts/load_error.py")
])
@@ -242,7 +241,7 @@ class TestScriptLoader:
pass # this is expected and normally guarded.
# on the next tick we should not fail however.
tctx.invoke(sc, "tick")
- assert len(tctx.master.addons) == 0
+ assert len(tctx.master.addons) == 1
def test_order(self):
rec = tutils.test_data.path("mitmproxy/data/addonscripts/recorder")
diff --git a/test/mitmproxy/addons/test_setheaders.py b/test/mitmproxy/addons/test_setheaders.py
index 3aaee7f4..2d5e9e3c 100644
--- a/test/mitmproxy/addons/test_setheaders.py
+++ b/test/mitmproxy/addons/test_setheaders.py
@@ -19,14 +19,14 @@ class TestSetHeaders:
def test_configure(self):
sh = setheaders.SetHeaders()
- with taddons.context() as tctx:
+ with taddons.context(sh) as tctx:
with pytest.raises(Exception, match="Invalid setheader filter pattern"):
tctx.configure(sh, setheaders = ["/~b/one/two"])
tctx.configure(sh, setheaders = ["/foo/bar/voing"])
def test_setheaders(self):
sh = setheaders.SetHeaders()
- with taddons.context() as tctx:
+ with taddons.context(sh) as tctx:
tctx.configure(
sh,
setheaders = [
diff --git a/test/mitmproxy/addons/test_stickyauth.py b/test/mitmproxy/addons/test_stickyauth.py
index ef7d0793..7b422fdd 100644
--- a/test/mitmproxy/addons/test_stickyauth.py
+++ b/test/mitmproxy/addons/test_stickyauth.py
@@ -9,7 +9,7 @@ from mitmproxy import exceptions
def test_configure():
r = stickyauth.StickyAuth()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tctx.configure(r, stickyauth="~s")
with pytest.raises(exceptions.OptionsError):
tctx.configure(r, stickyauth="~~")
@@ -20,7 +20,7 @@ def test_configure():
def test_simple():
r = stickyauth.StickyAuth()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tctx.configure(r, stickyauth=".*")
f = tflow.tflow(resp=True)
f.request.headers["authorization"] = "foo"