aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorroot <skkaushik212@gmail.com>2020-03-11 01:35:07 +0530
committerroot <skkaushik212@gmail.com>2020-03-11 01:36:47 +0530
commit42ea9a2d4967be2e867fc860c96d4c4939433a78 (patch)
tree38b84540950fa229690fb058d791b139f235cbeb /test
parente3499e4b99627ffbc44db6a6bb542d9ad439b00a (diff)
downloadmitmproxy-42ea9a2d4967be2e867fc860c96d4c4939433a78.tar.gz
mitmproxy-42ea9a2d4967be2e867fc860c96d4c4939433a78.tar.bz2
mitmproxy-42ea9a2d4967be2e867fc860c96d4c4939433a78.zip
test case option error
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_script.py11
-rw-r--r--test/mitmproxy/data/addonscripts/configure.py27
2 files changed, 38 insertions, 0 deletions
diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py
index 05472d9a..0279d1d9 100644
--- a/test/mitmproxy/addons/test_script.py
+++ b/test/mitmproxy/addons/test_script.py
@@ -135,6 +135,17 @@ class TestScript:
assert await tctx.master.await_log("ValueError: Error!")
assert await tctx.master.await_log("error.py")
+
+ @pytest.mark.asyncio
+ async def test_optionexceptions(self, tdata):
+ with taddons.context() as tctx:
+ sc = script.Script(
+ tdata.path("mitmproxy/data/addonscripts/configure.py"),
+ True,
+ )
+ tctx.master.addons.add(sc)
+ tctx.configure(sc)
+ assert await tctx.master.await_log("Options Error")
@pytest.mark.asyncio
async def test_addon(self, tdata):
diff --git a/test/mitmproxy/data/addonscripts/configure.py b/test/mitmproxy/data/addonscripts/configure.py
new file mode 100644
index 00000000..64abba6e
--- /dev/null
+++ b/test/mitmproxy/data/addonscripts/configure.py
@@ -0,0 +1,27 @@
+import typing
+
+from mitmproxy import ctx
+from mitmproxy import exceptions
+
+
+class TestHeader:
+ def load(self, loader):
+ loader.add_option(
+ name = "testheader",
+ typespec = typing.Optional[int],
+ default = None,
+ help = "test header",
+ )
+
+ def configure(self, updates):
+ raise exceptions.OptionsError("Options Error")
+
+ def response(self, flow):
+ if ctx.options.testheader is not None:
+ flow.response.headers["testheader"] = str(ctx.options.testheader)
+
+
+addons = [
+ TestHeader()
+]
+