diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_filestreamer.py | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/test/mitmproxy/addons/test_filestreamer.py b/test/mitmproxy/addons/test_filestreamer.py index f86912fc..658a0aa8 100644 --- a/test/mitmproxy/addons/test_filestreamer.py +++ b/test/mitmproxy/addons/test_filestreamer.py @@ -3,19 +3,55 @@ from mitmproxy.test import tutils from mitmproxy.test import taddons import os.path -from mitmproxy.addons import filestreamer from mitmproxy import io +from mitmproxy import exceptions +from mitmproxy.tools import dump +from mitmproxy.addons import filestreamer + + +def test_configure(): + sa = filestreamer.FileStreamer() + with taddons.context(options=dump.Options()) as tctx: + with tutils.tmpdir() as tdir: + p = os.path.join(tdir, "foo") + tutils.raises( + exceptions.OptionsError, + tctx.configure, sa, outfile=(tdir, "ab") + ) + tutils.raises( + "invalid filter", + tctx.configure, sa, outfile=(p, "ab"), filtstr="~~" + ) + tutils.raises( + "invalid mode", + tctx.configure, sa, outfile=(p, "xx") + ) + + +def rd(p): + x = io.FlowReader(open(p, "rb")) + return list(x.stream()) -def test_stream(): +def test_tcp(): sa = filestreamer.FileStreamer() with taddons.context() as tctx: with tutils.tmpdir() as tdir: p = os.path.join(tdir, "foo") + tctx.configure(sa, outfile=(p, "wb")) + + tt = tflow.ttcpflow() + sa.tcp_start(tt) + sa.tcp_end(tt) + tctx.configure(sa, outfile=None) + assert rd(p) - def r(): - x = io.FlowReader(open(p, "rb")) - return list(x.stream()) + +def test_simple(): + sa = filestreamer.FileStreamer() + with taddons.context() as tctx: + with tutils.tmpdir() as tdir: + p = os.path.join(tdir, "foo") tctx.configure(sa, outfile=(p, "wb")) @@ -23,10 +59,11 @@ def test_stream(): sa.request(f) sa.response(f) tctx.configure(sa, outfile=None) - assert r()[0].response + assert rd(p)[0].response tctx.configure(sa, outfile=(p, "ab")) f = tflow.tflow() sa.request(f) tctx.configure(sa, outfile=None) - assert not r()[1].response + assert not rd(p)[1].response + |