diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2017-02-01 12:19:51 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2017-02-01 12:22:05 +1300 |
commit | 914659e888792441cafb6373da53d7e15456f32c (patch) | |
tree | 6b068eb1f86b5b9308738487f18448263c55981f /test | |
parent | 4cc75a9560293cbe35d28e4950382e408aabdaea (diff) | |
download | mitmproxy-914659e888792441cafb6373da53d7e15456f32c.tar.gz mitmproxy-914659e888792441cafb6373da53d7e15456f32c.tar.bz2 mitmproxy-914659e888792441cafb6373da53d7e15456f32c.zip |
Regularise setheaders options
As per replacements:
- Make the option type a string/tuple union
- Localise parsing strictly within the addon
- Adapt the console editor (we'll find a more elegant solution later)
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_setheaders.py | 25 | ||||
-rw-r--r-- | test/mitmproxy/test_cmdline.py | 18 |
2 files changed, 17 insertions, 26 deletions
diff --git a/test/mitmproxy/addons/test_setheaders.py b/test/mitmproxy/addons/test_setheaders.py index 34395ddf..a721c180 100644 --- a/test/mitmproxy/addons/test_setheaders.py +++ b/test/mitmproxy/addons/test_setheaders.py @@ -3,19 +3,28 @@ from mitmproxy.test import tutils from mitmproxy.test import taddons from mitmproxy.addons import setheaders -from mitmproxy import options class TestSetHeaders: + def test_parse_setheaders(self): + x = setheaders.parse_setheader("/foo/bar/voing") + assert x == ("foo", "bar", "voing") + x = setheaders.parse_setheader("/foo/bar/vo/ing/") + assert x == ("foo", "bar", "vo/ing/") + x = setheaders.parse_setheader("/bar/voing") + assert x == (".*", "bar", "voing") + tutils.raises("invalid replacement", setheaders.parse_setheader, "/") + def test_configure(self): sh = setheaders.SetHeaders() - o = options.Options( - setheaders = [("~b", "one", "two")] - ) - tutils.raises( - "invalid setheader filter pattern", - sh.configure, o, o.keys() - ) + with taddons.context() as tctx: + tutils.raises( + "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() diff --git a/test/mitmproxy/test_cmdline.py b/test/mitmproxy/test_cmdline.py index fe0373d1..96d5ae31 100644 --- a/test/mitmproxy/test_cmdline.py +++ b/test/mitmproxy/test_cmdline.py @@ -1,11 +1,5 @@ import argparse from mitmproxy.tools import cmdline -from mitmproxy.test import tutils - - -def test_parse_setheaders(): - x = cmdline.parse_setheader("/foo/bar/voing") - assert x == ("foo", "bar", "voing") def test_common(): @@ -21,18 +15,6 @@ def test_common(): assert v["stickycookie"] == "foo" assert v["stickyauth"] == "foo" - opts.setheader = ["/foo/bar/voing"] - v = cmdline.get_common_options(opts) - assert v["setheaders"] == [("foo", "bar", "voing")] - - opts.setheader = ["//"] - tutils.raises( - "empty clause", - cmdline.get_common_options, - opts - ) - opts.setheader = [] - def test_mitmproxy(): ap = cmdline.mitmproxy() |