diff options
author | Matthew Shao <me@matshao.com> | 2017-08-17 10:53:09 +0800 |
---|---|---|
committer | Matthew Shao <me@matshao.com> | 2017-08-17 11:17:15 +0800 |
commit | af30930ae8ea10b1be3d062cc12481d37c377aa6 (patch) | |
tree | baaff0377f6dfa71874f7166c8993c7a21f1c67a /test | |
parent | d687ebc1ead4dc87237598e0ce1ac8fdcbaaacd1 (diff) | |
download | mitmproxy-af30930ae8ea10b1be3d062cc12481d37c377aa6.tar.gz mitmproxy-af30930ae8ea10b1be3d062cc12481d37c377aa6.tar.bz2 mitmproxy-af30930ae8ea10b1be3d062cc12481d37c377aa6.zip |
[web] Add tests for StaticViewer and minor fixes.
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_static_viewer.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/mitmproxy/addons/test_static_viewer.py b/test/mitmproxy/addons/test_static_viewer.py new file mode 100644 index 00000000..7e34a9fc --- /dev/null +++ b/test/mitmproxy/addons/test_static_viewer.py @@ -0,0 +1,60 @@ +import json + +from mitmproxy.test import taddons +from mitmproxy.test import tflow + +from mitmproxy import flowfilter +from mitmproxy.tools.web.app import flow_to_json + +from mitmproxy.addons import static_viewer +from mitmproxy.addons import save + + +def test_save_static(tmpdir): + tmpdir.mkdir('static') + static_viewer.save_static(tmpdir) + assert len(tmpdir.listdir()) == 2 + assert tmpdir.join('index.html').check(file=1) + assert tmpdir.join('static/static.js').read() == 'MITMWEB_STATIC = true;' + + +def test_save_filter_help(tmpdir): + static_viewer.save_filter_help(tmpdir) + f = tmpdir.join('/filter-help.json') + assert f.check(file=1) + assert f.read() == json.dumps(dict(commands=flowfilter.help)) + + +def test_save_flows(tmpdir): + flows = [tflow.tflow(req=True, resp=None), tflow.tflow(req=True, resp=True)] + static_viewer.save_flows(tmpdir, flows) + assert tmpdir.join('flows.json').check(file=1) + assert tmpdir.join('flows.json').read() == json.dumps([flow_to_json(f) for f in flows]) + + +def test_save_flows_content(tmpdir): + flows = [tflow.tflow(req=True, resp=None), tflow.tflow(req=True, resp=True)] + static_viewer.save_flows_content(tmpdir, flows) + flows_path = tmpdir.join('flows') + assert len(flows_path.listdir()) == len(flows) + for p in flows_path.listdir(): + assert p.join('request').check(dir=1) + assert p.join('response').check(dir=1) + assert p.join('request/_content').check(file=1) + assert p.join('request/content').check(dir=1) + assert p.join('response/_content').check(file=1) + assert p.join('response/content').check(dir=1) + assert p.join('request/content/Auto.json').check(file=1) + assert p.join('response/content/Auto.json').check(file=1) + + +def test_static_viewer(tmpdir): + s = static_viewer.StaticViewer() + sa = save.Save() + with taddons.context() as tctx: + sa.save([tflow.tflow(resp=True)], str(tmpdir.join('foo'))) + tctx.master.addons.add(s) + tctx.configure(s, web_static_viewer=str(tmpdir), rfile=str(tmpdir.join('foo'))) + assert tmpdir.join('index.html').check(file=1) + assert tmpdir.join('static').check(dir=1) + assert tmpdir.join('flows').check(dir=1) |