From b57f1a86af5a5a1f7b300963b5b0b7eb77be4fc7 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 1 Feb 2018 09:31:20 +0100 Subject: [PATCH 1/2] improve error message for missing scripts, fix #2824 --- 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 2d0303215..0494aa91b 100644 --- a/mitmproxy/addons/script.py +++ b/mitmproxy/addons/script.py @@ -50,7 +50,7 @@ class Script: self.last_load = 0 self.last_mtime = 0 if not os.path.isfile(self.fullpath): - raise exceptions.OptionsError("No such script: %s" % path) + raise exceptions.OptionsError('No such script: "%s"' % self.fullpath) @property def addons(self): From 4decb5c2e321f582cb99f70aa2d19c533dee3b2f Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 1 Feb 2018 09:56:56 +0100 Subject: [PATCH 2/2] remove quotes around filename --- mitmproxy/addons/script.py | 4 +++- test/mitmproxy/addons/test_script.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mitmproxy/addons/script.py b/mitmproxy/addons/script.py index 0494aa91b..0a5243591 100644 --- a/mitmproxy/addons/script.py +++ b/mitmproxy/addons/script.py @@ -44,7 +44,9 @@ class Script: def __init__(self, path): self.name = "scriptmanager:" + path self.path = path - self.fullpath = os.path.expanduser(path) + self.fullpath = os.path.expanduser( + path.strip("'\" ") + ) self.ns = None self.last_load = 0 diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py index c4fe6b430..78a5be6cf 100644 --- a/test/mitmproxy/addons/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -68,6 +68,18 @@ class TestScript: with pytest.raises(exceptions.OptionsError): script.Script("nonexistent") + def test_quotes_around_filename(self): + """ + Test that a script specified as '"foo.py"' works to support the calling convention of + mitmproxy 2.0, as e.g. used by Cuckoo Sandbox. + """ + path = tutils.test_data.path("mitmproxy/data/addonscripts/recorder/recorder.py") + + s = script.Script( + '"{}"'.format(path) + ) + assert '"' not in s.fullpath + def test_simple(self): with taddons.context() as tctx: sc = script.Script(