diff options
author | Chris Czub <chris.czub@gmail.com> | 2015-11-09 15:07:58 -0500 |
---|---|---|
committer | Chris Czub <chris.czub@gmail.com> | 2015-11-13 15:09:05 -0500 |
commit | d3feaa3bc6e2d9c2c7ee8286038c69c0b9601869 (patch) | |
tree | 065950ff60f9cf92c3e205f852fa3faed0ba6444 /test | |
parent | d7239d665e6781d7b84ecfde3fd5d7d1831de284 (diff) | |
download | mitmproxy-d3feaa3bc6e2d9c2c7ee8286038c69c0b9601869.tar.gz mitmproxy-d3feaa3bc6e2d9c2c7ee8286038c69c0b9601869.tar.bz2 mitmproxy-d3feaa3bc6e2d9c2c7ee8286038c69c0b9601869.zip |
Add custom content view plugin support for mitmproxy/mitmdump
Diffstat (limited to 'test')
-rw-r--r-- | test/test_custom_contentview.py | 49 | ||||
-rw-r--r-- | test/test_script.py | 10 |
2 files changed, 59 insertions, 0 deletions
diff --git a/test/test_custom_contentview.py b/test/test_custom_contentview.py new file mode 100644 index 00000000..2ca184d0 --- /dev/null +++ b/test/test_custom_contentview.py @@ -0,0 +1,49 @@ +from libmproxy import script, flow +import libmproxy.contentviews as cv +from netlib.http import Headers + + +def test_custom_views(): + plugins = flow.Plugins() + + # two types: view and action + assert 'view_plugins' in dict(plugins).keys() + + view_plugins = plugins['view_plugins'] + assert len(view_plugins) == 0 + + class ViewNoop(cv.View): + name = "noop" + prompt = ("noop", "n") + content_types = ["text/none"] + + def __call__(self, data, **metadata): + return "noop", cv.format_text(data) + + plugins.register_view('noop', + title='Noop View Plugin', + class_ref=ViewNoop) + + assert len(view_plugins) == 1 + assert view_plugins['noop']['title'] == 'Noop View Plugin' + + assert cv.get("noop") + + r = cv.get_content_view( + cv.get("noop"), + "[1, 2, 3]", + headers=Headers( + content_type="text/plain" + ) + ) + assert "noop" in r[0] + + # now try content-type matching + r = cv.get_content_view( + cv.get("Auto"), + "[1, 2, 3]", + headers=Headers( + content_type="text/none" + ) + ) + assert "noop" in r[0] diff --git a/test/test_script.py b/test/test_script.py index 1b0e5a5b..f0883ad5 100644 --- a/test/test_script.py +++ b/test/test_script.py @@ -127,3 +127,13 @@ def test_command_parsing(): absfilepath = os.path.normcase(tutils.test_data.path("scripts/a.py")) s = script.Script(absfilepath, fm) assert os.path.isfile(s.args[0]) + + +def test_script_plugins(): + s = flow.State() + fm = flow.FlowMaster(None, s) + sp = tutils.test_data.path("scripts/a.py") + p = script.Script("%s --var 40" % sp, fm) + + assert hasattr(p.ctx, 'plugins') + |