diff options
author | Maximilian Hils <git@maximilianhils.com> | 2018-02-01 10:17:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-01 10:17:38 +0100 |
commit | 6d8731e144eaec2aaf2120c21969c9228b7af95a (patch) | |
tree | b85ce48dca4068c67be474a571d358259c3b924f | |
parent | 02d2ef75060784b1eec9db81e62edf4b058f86fa (diff) | |
parent | 4decb5c2e321f582cb99f70aa2d19c533dee3b2f (diff) | |
download | mitmproxy-6d8731e144eaec2aaf2120c21969c9228b7af95a.tar.gz mitmproxy-6d8731e144eaec2aaf2120c21969c9228b7af95a.tar.bz2 mitmproxy-6d8731e144eaec2aaf2120c21969c9228b7af95a.zip |
Merge pull request #2833 from mitmproxy/issue-2824
Improve error message for missing scripts, fix #2824
-rw-r--r-- | mitmproxy/addons/script.py | 6 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_script.py | 12 |
2 files changed, 16 insertions, 2 deletions
diff --git a/mitmproxy/addons/script.py b/mitmproxy/addons/script.py index 2d030321..0a524359 100644 --- a/mitmproxy/addons/script.py +++ b/mitmproxy/addons/script.py @@ -44,13 +44,15 @@ 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 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): diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py index c4fe6b43..78a5be6c 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( |