From 84e4d6d57534be5d5e12b2e1e6ed60d564b64e57 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 7 Mar 2020 23:03:06 +0530 Subject: Options Exception in script --- mitmproxy/addons/script.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mitmproxy/addons/script.py b/mitmproxy/addons/script.py index 3b2568c9..0e6c0252 100644 --- a/mitmproxy/addons/script.py +++ b/mitmproxy/addons/script.py @@ -105,11 +105,14 @@ class Script: # We're already running, so we have to explicitly register and # configure the addon ctx.master.addons.invoke_addon(self.ns, "running") - ctx.master.addons.invoke_addon( - self.ns, - "configure", - ctx.options.keys() - ) + try: + ctx.master.addons.invoke_addon( + self.ns, + "configure", + ctx.options.keys() + ) + except exceptions.OptionsError as e: + script_error_handler(self.fullpath,e,str(e)) async def watcher(self): last_mtime = 0 -- cgit v1.2.3 From e3499e4b99627ffbc44db6a6bb542d9ad439b00a Mon Sep 17 00:00:00 2001 From: root Date: Sat, 7 Mar 2020 23:18:49 +0530 Subject: test resolve --- mitmproxy/addons/script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitmproxy/addons/script.py b/mitmproxy/addons/script.py index 0e6c0252..b3cb0999 100644 --- a/mitmproxy/addons/script.py +++ b/mitmproxy/addons/script.py @@ -112,7 +112,7 @@ class Script: ctx.options.keys() ) except exceptions.OptionsError as e: - script_error_handler(self.fullpath,e,str(e)) + script_error_handler(self.fullpath, e, msg=str(e)) async def watcher(self): last_mtime = 0 -- cgit v1.2.3 From 42ea9a2d4967be2e867fc860c96d4c4939433a78 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 11 Mar 2020 01:35:07 +0530 Subject: test case option error --- test/mitmproxy/addons/test_script.py | 11 +++++++++++ test/mitmproxy/data/addonscripts/configure.py | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/mitmproxy/data/addonscripts/configure.py 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() +] + -- cgit v1.2.3 From 61617919ffffd62ab42aa5fec8a9b5bf9b76f8e1 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 11 Mar 2020 01:46:29 +0530 Subject: remove whitespace --- test/mitmproxy/addons/test_script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py index 0279d1d9..61e19174 100644 --- a/test/mitmproxy/addons/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -135,7 +135,7 @@ 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: -- cgit v1.2.3 From 79b8fcc052f78f836dac2dcf0221097ff8c10c10 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 31 Mar 2020 10:07:53 +0530 Subject: Changes --- test/mitmproxy/data/addonscripts/configure.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/test/mitmproxy/data/addonscripts/configure.py b/test/mitmproxy/data/addonscripts/configure.py index 64abba6e..6f6ac06a 100644 --- a/test/mitmproxy/data/addonscripts/configure.py +++ b/test/mitmproxy/data/addonscripts/configure.py @@ -1,27 +1,21 @@ import typing -from mitmproxy import ctx from mitmproxy import exceptions -class TestHeader: +class OptionAddon: def load(self, loader): loader.add_option( - name = "testheader", + name = "optionaddon", typespec = typing.Optional[int], default = None, - help = "test header", + help = "Option Addon", ) 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() + OptionAddon() ] -- cgit v1.2.3