From 8eea05fcafde2410e6af0746c09a05c6d8d5a3e9 Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Wed, 17 May 2017 11:04:43 +0530 Subject: [PATCH 1/4] Increase contentviews api coverage --- test/mitmproxy/contentviews/test_api.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/mitmproxy/contentviews/test_api.py b/test/mitmproxy/contentviews/test_api.py index 95d83af91..c072c86ff 100644 --- a/test/mitmproxy/contentviews/test_api.py +++ b/test/mitmproxy/contentviews/test_api.py @@ -9,23 +9,28 @@ from mitmproxy.test import tutils class TestContentView(contentviews.View): name = "test" - prompt = ("t", "test") + prompt = ("test", "t") content_types = ["test/123"] def test_add_remove(): tcv = TestContentView() contentviews.add(tcv) + assert tcv in contentviews.views # repeated addition causes exception - with pytest.raises(ContentViewException): + with pytest.raises(ContentViewException, match="Duplicate view"): contentviews.add(tcv) + tcv2 = TestContentView() + tcv2.name = "test2" + tcv2.prompt = ("test2", "t") # Same shortcut doesn't work either. - with pytest.raises(ContentViewException): - contentviews.add(TestContentView()) + with pytest.raises(ContentViewException, match="Duplicate view shortcut"): + contentviews.add(tcv2) contentviews.remove(tcv) + assert tcv not in contentviews.views def test_get_content_view(): @@ -43,6 +48,7 @@ def test_get_content_view(): headers=Headers(content_type="application/json") ) assert desc == "JSON" + assert list(lines) desc, lines, err = contentviews.get_content_view( contentviews.get("JSON"), @@ -84,3 +90,4 @@ def test_get_message_content_view(): def test_get_by_shortcut(): assert contentviews.get_by_shortcut("s") + assert not contentviews.get_by_shortcut("b") From 204d06f93f7c3fbdce38b12219c530e1eddc3e4d Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Wed, 17 May 2017 11:05:49 +0530 Subject: [PATCH 2/4] Increased xml_html contentview coverage --- test/mitmproxy/contentviews/test_xml_html.py | 8 ++++ .../test_xml_html_data/test-formatted.html | 44 +++++++++++++++++++ .../contentviews/test_xml_html_data/test.html | 14 ++++++ 3 files changed, 66 insertions(+) create mode 100644 test/mitmproxy/contentviews/test_xml_html_data/test-formatted.html create mode 100644 test/mitmproxy/contentviews/test_xml_html_data/test.html diff --git a/test/mitmproxy/contentviews/test_xml_html.py b/test/mitmproxy/contentviews/test_xml_html.py index 2b0aee4d6..8148fd4ce 100644 --- a/test/mitmproxy/contentviews/test_xml_html.py +++ b/test/mitmproxy/contentviews/test_xml_html.py @@ -11,6 +11,13 @@ def test_simple(): v = full_eval(xml_html.ViewXmlHtml()) assert v(b"foo") == ('XML', [[('text', 'foo')]]) assert v(b"") == ('HTML', [[('text', '')]]) + assert v(b"<>") == ('XML', [[('text', '<>')]]) + assert v(b")" @pytest.mark.parametrize("filename", [ @@ -18,6 +25,7 @@ def test_simple(): "cdata.xml", "comment.xml", "inline.html", + "test.html" ]) def test_format_xml(filename): path = data.path(filename) diff --git a/test/mitmproxy/contentviews/test_xml_html_data/test-formatted.html b/test/mitmproxy/contentviews/test_xml_html_data/test-formatted.html new file mode 100644 index 000000000..0eb600048 --- /dev/null +++ b/test/mitmproxy/contentviews/test_xml_html_data/test-formatted.html @@ -0,0 +1,44 @@ + + + + + Title + + +

+ Lorem ipsum dolor +

+ sit amet, consectetur +

+ adipiscing elit, sed +

+ do eiusmod tempor +

+ incididunt ut +

+ labore et dolore +

+ magna aliqua. +

+ Ut enim ad minim +

+ veniam, quis nostrud +

+ exercitation +

+ ullamco laboris +

+ nisi ut aliquip ex ea +

+ commodo consequat. +

+ Duis aute irure +

+ dolor in reprehenderit +

+ in voluptate velit +

+ esse cillum dolore +

eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

+ + diff --git a/test/mitmproxy/contentviews/test_xml_html_data/test.html b/test/mitmproxy/contentviews/test_xml_html_data/test.html new file mode 100644 index 000000000..e74ac3146 --- /dev/null +++ b/test/mitmproxy/contentviews/test_xml_html_data/test.html @@ -0,0 +1,14 @@ + + + + + Title + + +

Lorem ipsum dolor

sit amet, consectetur

adipiscing elit, sed

do eiusmod tempor

incididunt ut

labore et dolore

magna aliqua. +

Ut enim ad minim

veniam, quis nostrud

exercitation

ullamco laboris

+ nisi ut aliquip ex ea

commodo consequat.

Duis aute irure

dolor in reprehenderit

in voluptate velit

esse cillum dolore

eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

+ + + + \ No newline at end of file From 37053f0efc439ab4406c57f74a7bcc8daa5ea156 Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Wed, 17 May 2017 11:06:40 +0530 Subject: [PATCH 3/4] Increased mitmproxy.controller coverage --- test/mitmproxy/test_controller.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/mitmproxy/test_controller.py b/test/mitmproxy/test_controller.py index ccc8bf351..2e13d2983 100644 --- a/test/mitmproxy/test_controller.py +++ b/test/mitmproxy/test_controller.py @@ -176,6 +176,8 @@ class TestDummyReply: reply = controller.DummyReply() reply.ack() reply.take() + with pytest.raises(ControlException): + reply.mark_reset() reply.commit() reply.mark_reset() assert reply.state == "committed" From 208931021e28de8b57e3f28d0fbcb018b5fb3879 Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Wed, 17 May 2017 11:26:18 +0530 Subject: [PATCH 4/4] Updated setup.cfg --- setup.cfg | 4 ---- 1 file changed, 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index ebe76efd7..f1382a6ef 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,9 +21,7 @@ exclude_lines = [tool:full_coverage] exclude = - mitmproxy/contentviews/__init__.py mitmproxy/contentviews/wbxml.py - mitmproxy/contentviews/xml_html.py mitmproxy/net/tcp.py mitmproxy/net/http/encoding.py mitmproxy/proxy/protocol/ @@ -31,7 +29,6 @@ exclude = mitmproxy/proxy/root_context.py mitmproxy/proxy/server.py mitmproxy/tools/ - mitmproxy/controller.py mitmproxy/flow.py mitmproxy/master.py pathod/pathoc.py @@ -45,7 +42,6 @@ exclude = mitmproxy/addons/termlog.py mitmproxy/contentviews/base.py mitmproxy/contentviews/wbxml.py - mitmproxy/contentviews/xml_html.py mitmproxy/controller.py mitmproxy/ctx.py mitmproxy/exceptions.py