From 9c31669211dd0b81e3f7f5325a3564e827a8d6d0 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 11 Sep 2015 19:03:50 +0200 Subject: mitmdump: colorize output, add content views --- test/test_dump.py | 58 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 11 deletions(-) (limited to 'test/test_dump.py') diff --git a/test/test_dump.py b/test/test_dump.py index c76f555f..0fc4cd4d 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -1,5 +1,7 @@ import os from cStringIO import StringIO +from libmproxy.contentview import ViewAuto +from libmproxy.exceptions import ContentViewException from libmproxy.models import HTTPResponse import netlib.tutils @@ -12,17 +14,51 @@ import mock def test_strfuncs(): - t = HTTPResponse.wrap(netlib.tutils.tresp()) - t.is_replay = True - dump.str_response(t) - - f = tutils.tflow() - f.client_conn = None - f.request.stickycookie = True - assert "stickycookie" in dump.str_request(f, False) - assert "stickycookie" in dump.str_request(f, True) - assert "replay" in dump.str_request(f, False) - assert "replay" in dump.str_request(f, True) + o = dump.Options() + m = dump.DumpMaster(None, o) + + m.outfile = StringIO() + m.o.flow_detail = 0 + m.echo_flow(tutils.tflow()) + assert not m.outfile.getvalue() + + m.o.flow_detail = 4 + m.echo_flow(tutils.tflow()) + assert m.outfile.getvalue() + + m.outfile = StringIO() + m.echo_flow(tutils.tflow(resp=True)) + assert "<<" in m.outfile.getvalue() + + m.outfile = StringIO() + m.echo_flow(tutils.tflow(err=True)) + assert "<<" in m.outfile.getvalue() + + flow = tutils.tflow() + flow.request = netlib.tutils.treq() + flow.request.stickycookie = True + flow.client_conn = mock.MagicMock() + flow.client_conn.address.host = "foo" + flow.response = netlib.tutils.tresp(content=CONTENT_MISSING) + flow.response.is_replay = True + flow.response.code = 300 + m.echo_flow(flow) + + + flow = tutils.tflow(resp=netlib.tutils.tresp("{")) + flow.response.headers["content-type"] = "application/json" + flow.response.code = 400 + m.echo_flow(flow) + + +@mock.patch("libmproxy.contentview.get_content_view") +def test_contentview(get_content_view): + get_content_view.side_effect = ContentViewException(""), ("x", []) + + o = dump.Options(flow_detail=4, verbosity=3) + m = dump.DumpMaster(None, o, StringIO()) + m.echo_flow(tutils.tflow()) + assert "Content viewer failed" in m.outfile.getvalue() class TestDumpMaster: -- cgit v1.2.3 From 049d253a83e18116340670cb86528b4ac1d3b215 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 12 Sep 2015 13:49:16 +0200 Subject: simplify contentview api --- test/test_dump.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/test_dump.py') diff --git a/test/test_dump.py b/test/test_dump.py index 0fc4cd4d..88f1a6fd 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -1,6 +1,5 @@ import os from cStringIO import StringIO -from libmproxy.contentview import ViewAuto from libmproxy.exceptions import ContentViewException from libmproxy.models import HTTPResponse @@ -51,7 +50,7 @@ def test_strfuncs(): m.echo_flow(flow) -@mock.patch("libmproxy.contentview.get_content_view") +@mock.patch("libmproxy.contentviews.get_content_view") def test_contentview(get_content_view): get_content_view.side_effect = ContentViewException(""), ("x", []) -- cgit v1.2.3 From 5fe12a467f37bfba2f4f663274cacbc6ecc770f7 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 12 Sep 2015 17:40:30 +0200 Subject: fix tests --- test/test_dump.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test_dump.py') diff --git a/test/test_dump.py b/test/test_dump.py index 88f1a6fd..29931759 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -52,7 +52,7 @@ def test_strfuncs(): @mock.patch("libmproxy.contentviews.get_content_view") def test_contentview(get_content_view): - get_content_view.side_effect = ContentViewException(""), ("x", []) + get_content_view.side_effect = ContentViewException(""), ("x", iter([])) o = dump.Options(flow_detail=4, verbosity=3) m = dump.DumpMaster(None, o, StringIO()) -- cgit v1.2.3