diff --git a/mitmproxy/addons/clientplayback.py b/mitmproxy/addons/clientplayback.py index 2dd488b9e..a017ec0f7 100644 --- a/mitmproxy/addons/clientplayback.py +++ b/mitmproxy/addons/clientplayback.py @@ -14,6 +14,12 @@ class ClientPlayback: self.current_thread = None self.configured = False + def load(self, loader): + loader.add_option( + "client_replay", typing.Sequence[str], [], + "Replay client requests from a saved file." + ) + def count(self) -> int: if self.current_thread: current = 1 diff --git a/mitmproxy/options.py b/mitmproxy/options.py index f31b4a036..ff13c385b 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -30,77 +30,75 @@ class Options(optmanager.OptManager): # This provides type hints for IDEs (e.g. PyCharm) and mypy. # Autogenerated using test/helper_tools/typehints_for_options.py add_upstream_certs_to_client_chain = None # type: bool - allow_remote = None # type: bool body_size_limit = None # type: Optional[str] cadir = None # type: str certs = None # type: Sequence[str] ciphers_client = None # type: Optional[str] ciphers_server = None # type: Optional[str] client_certs = None # type: Optional[str] - client_replay = None # type: Sequence[str] - console_focus_follow = None # type: bool - console_layout = None # type: str - console_layout_headers = None # type: bool - console_mouse = None # type: bool - console_palette = None # type: str - console_palette_transparent = None # type: bool - default_contentview = None # type: str - flow_detail = None # type: int http2 = None # type: bool http2_priority = None # type: bool ignore_hosts = None # type: Sequence[str] - intercept = None # type: Optional[str] - intercept_active = None # type: bool keep_host_header = None # type: bool - keepserving = None # type: bool listen_host = None # type: str listen_port = None # type: int mode = None # type: str - onboarding = None # type: bool - onboarding_host = None # type: str - onboarding_port = None # type: int - proxyauth = None # type: Optional[str] rawtcp = None # type: bool - server_replay_refresh = None # type: bool - replacements = None # type: Sequence[str] - server_replay_kill_extra = None # type: bool - rfile = None # type: Optional[str] - save_stream_file = None # type: Optional[str] - save_stream_filter = None # type: Optional[str] - scripts = None # type: Sequence[str] server = None # type: bool - server_replay = None # type: Sequence[str] - server_replay_ignore_content = None # type: bool - server_replay_ignore_host = None # type: bool - server_replay_ignore_params = None # type: Sequence[str] - server_replay_ignore_payload_params = None # type: Sequence[str] - server_replay_nopop = None # type: bool - server_replay_use_headers = None # type: Sequence[str] - setheaders = None # type: Sequence[str] - showhost = None # type: bool spoof_source_address = None # type: bool ssl_insecure = None # type: bool ssl_verify_upstream_trusted_ca = None # type: Optional[str] ssl_verify_upstream_trusted_cadir = None # type: Optional[str] ssl_version_client = None # type: str ssl_version_server = None # type: str + tcp_hosts = None # type: Sequence[str] + upstream_bind_address = None # type: str + upstream_cert = None # type: bool + websocket = None # type: bool + + # FIXME: Options that must be migrated to addons, but are complicated + # because they're used by more than one addon, or because they're + # embedded in the core code somehow. + default_contentview = None # type: str + flow_detail = None # type: int + intercept = None # type: Optional[str] + intercept_active = None # type: bool + proxyauth = None # type: Optional[str] + showhost = None # type: bool + verbosity = None # type: str + view_filter = None # type: Optional[str] + + # FIXME: Options that should be uncomplicated to migrate to addons + keepserving = None # type: bool + onboarding = None # type: bool + onboarding_host = None # type: str + onboarding_port = None # type: int + server_replay_refresh = None # type: bool + replacements = None # type: Sequence[str] + rfile = None # type: Optional[str] + save_stream_file = None # type: Optional[str] + save_stream_filter = None # type: Optional[str] + scripts = None # type: Sequence[str] + server_replay = None # type: Sequence[str] + server_replay_ignore_content = None # type: bool + server_replay_ignore_host = None # type: bool + server_replay_ignore_params = None # type: Sequence[str] + server_replay_ignore_payload_params = None # type: Sequence[str] + server_replay_kill_extra = None # type: bool + server_replay_nopop = None # type: bool + server_replay_use_headers = None # type: Sequence[str] + setheaders = None # type: Sequence[str] stickyauth = None # type: Optional[str] stickycookie = None # type: Optional[str] stream_large_bodies = None # type: Optional[str] stream_websockets = None # type: bool - tcp_hosts = None # type: Sequence[str] upstream_auth = None # type: Optional[str] - upstream_bind_address = None # type: str - upstream_cert = None # type: bool - verbosity = None # type: str - view_filter = None # type: Optional[str] view_order = None # type: str view_order_reversed = None # type: bool web_debug = None # type: bool web_iface = None # type: str web_open_browser = None # type: bool web_port = None # type: int - websocket = None # type: bool def __init__(self, **kwargs) -> None: super().__init__() @@ -119,10 +117,6 @@ class Options(optmanager.OptManager): "onboarding_port", int, APP_PORT, "Port to serve the onboarding app from." ) - self.add_option( - "client_replay", Sequence[str], [], - "Replay client requests from a saved file." - ) self.add_option( "server_replay_kill_extra", bool, False, "Kill extra requests during replay." diff --git a/test/mitmproxy/addons/test_allowremote.py b/test/mitmproxy/addons/test_allowremote.py index 9fc715251..52dae68d4 100644 --- a/test/mitmproxy/addons/test_allowremote.py +++ b/test/mitmproxy/addons/test_allowremote.py @@ -19,8 +19,7 @@ from mitmproxy.test import taddons ]) def test_allowremote(allow_remote, ip, should_be_killed): ar = allowremote.AllowRemote() - with taddons.context() as tctx: - tctx.master.addons.register(ar) + with taddons.context(ar) as tctx: tctx.options.allow_remote = allow_remote with mock.patch('mitmproxy.proxy.protocol.base.Layer') as layer: diff --git a/test/mitmproxy/addons/test_clientplayback.py b/test/mitmproxy/addons/test_clientplayback.py index 3f990668b..f172af83e 100644 --- a/test/mitmproxy/addons/test_clientplayback.py +++ b/test/mitmproxy/addons/test_clientplayback.py @@ -24,7 +24,7 @@ class MockThread(): class TestClientPlayback: def test_playback(self): cp = clientplayback.ClientPlayback() - with taddons.context() as tctx: + with taddons.context(cp) as tctx: assert cp.count() == 0 f = tflow.tflow(resp=True) cp.start_replay([f]) @@ -58,7 +58,7 @@ class TestClientPlayback: def test_load_file(self, tmpdir): cp = clientplayback.ClientPlayback() - with taddons.context(): + with taddons.context(cp): fpath = str(tmpdir.join("flows")) tdump(fpath, [tflow.tflow(resp=True)]) cp.load_file(fpath) @@ -68,7 +68,7 @@ class TestClientPlayback: def test_configure(self, tmpdir): cp = clientplayback.ClientPlayback() - with taddons.context() as tctx: + with taddons.context(cp) as tctx: path = str(tmpdir.join("flows")) tdump(path, [tflow.tflow()]) tctx.configure(cp, client_replay=[path])