aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-03-12 20:46:00 +0100
committerMaximilian Hils <git@maximilianhils.com>2017-03-12 23:28:49 +0100
commit0f4b523868856fccaf373c9108c9220a3aafb30b (patch)
tree2cbaf6d3c5103e20ba52edfeb410d70887694e5b /test
parent4684617d2c8e17d84fd98b635fd5c799dd77b741 (diff)
downloadmitmproxy-0f4b523868856fccaf373c9108c9220a3aafb30b.tar.gz
mitmproxy-0f4b523868856fccaf373c9108c9220a3aafb30b.tar.bz2
mitmproxy-0f4b523868856fccaf373c9108c9220a3aafb30b.zip
replacements: error right away when file does not exist
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_replace.py58
1 files changed, 30 insertions, 28 deletions
diff --git a/test/mitmproxy/addons/test_replace.py b/test/mitmproxy/addons/test_replace.py
index 5d268076..7d590b35 100644
--- a/test/mitmproxy/addons/test_replace.py
+++ b/test/mitmproxy/addons/test_replace.py
@@ -1,11 +1,8 @@
-import os.path
-
import pytest
from mitmproxy.addons import replace
from mitmproxy.test import taddons
from mitmproxy.test import tflow
-from mitmproxy.test import tutils
class TestReplace:
@@ -68,33 +65,38 @@ class TestReplace:
class TestReplaceFile:
- def test_simple(self):
+ def test_simple(self, tmpdir):
+ r = replace.Replace()
+ with taddons.context() as tctx:
+ tmpfile = tmpdir.join("replacement")
+ tmpfile.write("bar")
+ tctx.configure(
+ r,
+ replacements=["/~q/foo/@" + str(tmpfile)]
+ )
+ f = tflow.tflow()
+ f.request.content = b"foo"
+ r.request(f)
+ assert f.request.content == b"bar"
+
+ def test_nonexistent(self, tmpdir):
r = replace.Replace()
- with tutils.tmpdir() as td:
- rp = os.path.join(td, "replacement")
- with open(rp, "w") as f:
- f.write("bar")
- with taddons.context() as tctx:
+ with taddons.context() as tctx:
+ with pytest.raises(Exception, match="Invalid file path"):
tctx.configure(
r,
- replacements=[
- "/~q/foo/@" + rp,
- "/~s/foo/@" + rp,
- "/~b nonexistent/nonexistent/@nonexistent",
- ]
+ replacements=["/~q/foo/@nonexistent"]
)
- f = tflow.tflow()
- f.request.content = b"foo"
- r.request(f)
- assert f.request.content == b"bar"
- f = tflow.tflow(resp=True)
- f.response.content = b"foo"
- r.response(f)
- assert f.response.content == b"bar"
-
- f = tflow.tflow()
- f.request.content = b"nonexistent"
- assert not tctx.master.event_log
- r.request(f)
- assert tctx.master.event_log
+ tmpfile = tmpdir.join("replacement")
+ tmpfile.write("bar")
+ tctx.configure(
+ r,
+ replacements=["/~q/foo/@" + str(tmpfile)]
+ )
+ tmpfile.remove()
+ f = tflow.tflow()
+ f.request.content = b"foo"
+ assert not tctx.master.event_log
+ r.request(f)
+ assert tctx.master.event_log