mirror of
https://github.com/vee1e/mitmproxy.git
synced 2026-09-01 18:27:18 +00:00
load pending scripts before dumping options (#8176)
* fix: include addon options in --options output * add changelog entry for #4423 * explain why we do this dance * fix: tests --------- Co-authored-by: Maximilian Hils <git@maximilianhils.com>
This commit is contained in:
parent
bf16594f44
commit
cc58fc9f38
4 changed files with 46 additions and 0 deletions
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
## Unreleased: mitmproxy next
|
||||
|
||||
- Fix addon options not being included in `--options` output.
|
||||
([#4423](https://github.com/mitmproxy/mitmproxy/issues/4423))
|
||||
- Fix `view.settings.setval.toggle` command to correctly use the provided key parameter instead of hardcoded "key" string.
|
||||
([#8167](https://github.com/mitmproxy/mitmproxy/pull/8167), @nameearly)
|
||||
- Fix 400 Bad Request for HTTP requests with uppercase scheme (e.g. `HTTP://`).
|
||||
|
|
|
|||
|
|
@ -91,6 +91,11 @@ def run(
|
|||
process_options(parser, opts, args)
|
||||
|
||||
if args.options:
|
||||
# Load custom addons so that their options are registered
|
||||
if sl := master.addons.get("scriptloader"):
|
||||
for s in sl.addons:
|
||||
if s.ns is None:
|
||||
s.loadscript()
|
||||
optmanager.dump_defaults(opts, sys.stdout)
|
||||
sys.exit(0)
|
||||
if args.commands:
|
||||
|
|
|
|||
14
test/mitmproxy/data/addonscripts/custom_option.py
Normal file
14
test/mitmproxy/data/addonscripts/custom_option.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from typing import Optional
|
||||
|
||||
|
||||
class CustomOptionAddon:
|
||||
def load(self, loader):
|
||||
loader.add_option(
|
||||
name="custom_addon_option",
|
||||
typespec=Optional[int],
|
||||
default=None,
|
||||
help="A custom option registered by an addon.",
|
||||
)
|
||||
|
||||
|
||||
addons = [CustomOptionAddon()]
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
import pytest
|
||||
|
||||
from mitmproxy.tools import main
|
||||
|
||||
shutdown_script = "mitmproxy/data/addonscripts/shutdown.py"
|
||||
|
|
@ -28,3 +30,26 @@ def test_mitmdump(tdata):
|
|||
"0",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_options_includes_addon_options(tdata, capsys):
|
||||
"""--options should include options registered by addon scripts."""
|
||||
with pytest.raises(SystemExit):
|
||||
main.mitmdump(
|
||||
[
|
||||
"-s",
|
||||
tdata.path("mitmproxy/data/addonscripts/custom_option.py"),
|
||||
"--options",
|
||||
]
|
||||
)
|
||||
output = capsys.readouterr().out
|
||||
assert "custom_addon_option" in output
|
||||
|
||||
|
||||
def test_options_without_scripts(capsys):
|
||||
"""--options without any scripts should still work and list built-in options."""
|
||||
with pytest.raises(SystemExit):
|
||||
main.mitmdump(["--options"])
|
||||
output = capsys.readouterr().out
|
||||
assert "listen_port" in output
|
||||
assert "custom_addon_option" not in output
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue