From d3feaa3bc6e2d9c2c7ee8286038c69c0b9601869 Mon Sep 17 00:00:00 2001 From: Chris Czub Date: Mon, 9 Nov 2015 15:07:58 -0500 Subject: Add custom content view plugin support for mitmproxy/mitmdump --- test/test_custom_contentview.py | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/test_custom_contentview.py (limited to 'test/test_custom_contentview.py') 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] -- cgit v1.2.3 From e72a9a62a107ea3f53b6b26d1abe63c554448d17 Mon Sep 17 00:00:00 2001 From: Chris Czub Date: Fri, 13 Nov 2015 16:55:27 -0500 Subject: Feedback from PR #832 --- test/test_custom_contentview.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'test/test_custom_contentview.py') diff --git a/test/test_custom_contentview.py b/test/test_custom_contentview.py index 2ca184d0..4b5a3e53 100644 --- a/test/test_custom_contentview.py +++ b/test/test_custom_contentview.py @@ -4,14 +4,6 @@ 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") @@ -20,12 +12,10 @@ def test_custom_views(): 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' + view_obj = ViewNoop() + + cv.add(view_obj) assert cv.get("noop") @@ -47,3 +37,16 @@ def test_custom_views(): ) ) assert "noop" in r[0] + + # now try removing the custom view + cv.remove(view_obj) + r = cv.get_content_view( + cv.get("Auto"), + "[1, 2, 3]", + headers=Headers( + content_type="text/none" + ) + ) + assert "noop" not in r[0] + + -- cgit v1.2.3