aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-11-03 14:41:30 +1300
committerAldo Cortesi <aldo@nullcube.com>2016-11-03 14:50:23 +1300
commit43a822198923215b78ae08cef7a63d1ad24e37c7 (patch)
tree76bcc8786167b5fb6c2b19f371e298415207fc3c /test
parentfbdce4b629fe0e626818aafe81dc247f746d70cd (diff)
downloadmitmproxy-43a822198923215b78ae08cef7a63d1ad24e37c7.tar.gz
mitmproxy-43a822198923215b78ae08cef7a63d1ad24e37c7.tar.bz2
mitmproxy-43a822198923215b78ae08cef7a63d1ad24e37c7.zip
addons: filestreamer test cov to 100%
Also address a bug in taddons that caused options changes that raised errors to be retained rather than rolled back.
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_filestreamer.py51
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
+