diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-09-11 19:03:50 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-09-11 19:03:50 +0200 |
commit | 9c31669211dd0b81e3f7f5325a3564e827a8d6d0 (patch) | |
tree | ffe52286fe57d17f9d40af73f2eac68fd4a63232 /test | |
parent | b7b46bac467a48a893de9e751ed90ed8e903066f (diff) | |
download | mitmproxy-9c31669211dd0b81e3f7f5325a3564e827a8d6d0.tar.gz mitmproxy-9c31669211dd0b81e3f7f5325a3564e827a8d6d0.tar.bz2 mitmproxy-9c31669211dd0b81e3f7f5325a3564e827a8d6d0.zip |
mitmdump: colorize output, add content views
Diffstat (limited to 'test')
-rw-r--r-- | test/test_dump.py | 58 |
1 files changed, 47 insertions, 11 deletions
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: |