diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2017-03-12 11:18:16 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2017-03-14 08:32:19 +1300 |
commit | c24f7d8e12ee2002678adb695be513a7e593e198 (patch) | |
tree | 42e221417947aeb3d19265cd3fb21f680432ac79 | |
parent | 75f83ba380ca4133bdace8120383978a1e679410 (diff) | |
download | mitmproxy-c24f7d8e12ee2002678adb695be513a7e593e198.tar.gz mitmproxy-c24f7d8e12ee2002678adb695be513a7e593e198.tar.bz2 mitmproxy-c24f7d8e12ee2002678adb695be513a7e593e198.zip |
Optmanager: handle unknown options in value sets
-rw-r--r-- | examples/simple/custom_option.py | 2 | ||||
-rw-r--r-- | mitmproxy/optmanager.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/test_optmanager.py | 3 |
3 files changed, 6 insertions, 1 deletions
diff --git a/examples/simple/custom_option.py b/examples/simple/custom_option.py index e9c34850..a8b4e778 100644 --- a/examples/simple/custom_option.py +++ b/examples/simple/custom_option.py @@ -3,7 +3,7 @@ from mitmproxy import ctx def start(options): ctx.log.info("Registering option 'custom'") - options.add_option("custom", str, "default", "A custom option") + options.add_option("custom", bool, False, "A custom option") def configure(options, updated): diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py index a72a4355..fc540b74 100644 --- a/mitmproxy/optmanager.py +++ b/mitmproxy/optmanager.py @@ -338,6 +338,8 @@ class OptManager: optname, optval = parts[0], None else: optname, optval = parts[0], parts[1] + if optname not in self._options: + raise exceptions.OptionsError("No such option %s" % optname) o = self._options[optname] if o.typespec in (str, typing.Optional[str]): diff --git a/test/mitmproxy/test_optmanager.py b/test/mitmproxy/test_optmanager.py index 6e275802..8ca35984 100644 --- a/test/mitmproxy/test_optmanager.py +++ b/test/mitmproxy/test_optmanager.py @@ -346,3 +346,6 @@ def test_set(): assert opts.seqstr == ["foo", "bar"] opts.set("seqstr") assert opts.seqstr == [] + + with pytest.raises(exceptions.OptionsError): + opts.set("nonexistent=wobble") |