From 9f77c79227f424f48ec16871d7efd451c8de6d47 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 3 Nov 2016 15:00:18 +1300 Subject: FileStreamer -> StreamFile options.wfile -> options.streamfile --- test/mitmproxy/addons/test_filestreamer.py | 69 ------------------------------ test/mitmproxy/addons/test_streamfile.py | 68 +++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 69 deletions(-) delete mode 100644 test/mitmproxy/addons/test_filestreamer.py create mode 100644 test/mitmproxy/addons/test_streamfile.py (limited to 'test') diff --git a/test/mitmproxy/addons/test_filestreamer.py b/test/mitmproxy/addons/test_filestreamer.py deleted file mode 100644 index 658a0aa8..00000000 --- a/test/mitmproxy/addons/test_filestreamer.py +++ /dev/null @@ -1,69 +0,0 @@ -from mitmproxy.test import tflow -from mitmproxy.test import tutils -from mitmproxy.test import taddons - -import os.path -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_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 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")) - - f = tflow.tflow(resp=True) - sa.request(f) - sa.response(f) - tctx.configure(sa, outfile=None) - assert rd(p)[0].response - - tctx.configure(sa, outfile=(p, "ab")) - f = tflow.tflow() - sa.request(f) - tctx.configure(sa, outfile=None) - assert not rd(p)[1].response - diff --git a/test/mitmproxy/addons/test_streamfile.py b/test/mitmproxy/addons/test_streamfile.py new file mode 100644 index 00000000..f63f29c4 --- /dev/null +++ b/test/mitmproxy/addons/test_streamfile.py @@ -0,0 +1,68 @@ +from mitmproxy.test import tflow +from mitmproxy.test import tutils +from mitmproxy.test import taddons + +import os.path +from mitmproxy import io +from mitmproxy import exceptions +from mitmproxy.tools import dump +from mitmproxy.addons import streamfile + + +def test_configure(): + sa = streamfile.StreamFile() + 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, streamfile=(tdir, "ab") + ) + tutils.raises( + "invalid filter", + tctx.configure, sa, streamfile=(p, "ab"), filtstr="~~" + ) + tutils.raises( + "invalid mode", + tctx.configure, sa, streamfile=(p, "xx") + ) + + +def rd(p): + x = io.FlowReader(open(p, "rb")) + return list(x.stream()) + + +def test_tcp(): + sa = streamfile.StreamFile() + with taddons.context() as tctx: + with tutils.tmpdir() as tdir: + p = os.path.join(tdir, "foo") + tctx.configure(sa, streamfile=(p, "wb")) + + tt = tflow.ttcpflow() + sa.tcp_start(tt) + sa.tcp_end(tt) + tctx.configure(sa, streamfile=None) + assert rd(p) + + +def test_simple(): + sa = streamfile.StreamFile() + with taddons.context() as tctx: + with tutils.tmpdir() as tdir: + p = os.path.join(tdir, "foo") + + tctx.configure(sa, streamfile=(p, "wb")) + + f = tflow.tflow(resp=True) + sa.request(f) + sa.response(f) + tctx.configure(sa, streamfile=None) + assert rd(p)[0].response + + tctx.configure(sa, streamfile=(p, "ab")) + f = tflow.tflow() + sa.request(f) + tctx.configure(sa, streamfile=None) + assert not rd(p)[1].response -- cgit v1.2.3