client options: migrate allowremote and clientplayback

Also triage options, and categorize them into core options (won't be migrated),
options that are hard to migrate for various reasons, and easy migrations.
This commit is contained in:
Aldo Cortesi 2018-02-24 14:39:03 +13:00
parent 42094b29ff
commit a12d149230
4 changed files with 47 additions and 48 deletions

View File

@ -14,6 +14,12 @@ class ClientPlayback:
self.current_thread = None self.current_thread = None
self.configured = False 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: def count(self) -> int:
if self.current_thread: if self.current_thread:
current = 1 current = 1

View File

@ -30,77 +30,75 @@ class Options(optmanager.OptManager):
# This provides type hints for IDEs (e.g. PyCharm) and mypy. # This provides type hints for IDEs (e.g. PyCharm) and mypy.
# Autogenerated using test/helper_tools/typehints_for_options.py # Autogenerated using test/helper_tools/typehints_for_options.py
add_upstream_certs_to_client_chain = None # type: bool add_upstream_certs_to_client_chain = None # type: bool
allow_remote = None # type: bool
body_size_limit = None # type: Optional[str] body_size_limit = None # type: Optional[str]
cadir = None # type: str cadir = None # type: str
certs = None # type: Sequence[str] certs = None # type: Sequence[str]
ciphers_client = None # type: Optional[str] ciphers_client = None # type: Optional[str]
ciphers_server = None # type: Optional[str] ciphers_server = None # type: Optional[str]
client_certs = 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 = None # type: bool
http2_priority = None # type: bool http2_priority = None # type: bool
ignore_hosts = None # type: Sequence[str] ignore_hosts = None # type: Sequence[str]
intercept = None # type: Optional[str]
intercept_active = None # type: bool
keep_host_header = None # type: bool keep_host_header = None # type: bool
keepserving = None # type: bool
listen_host = None # type: str listen_host = None # type: str
listen_port = None # type: int listen_port = None # type: int
mode = None # type: str 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 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 = 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 spoof_source_address = None # type: bool
ssl_insecure = None # type: bool ssl_insecure = None # type: bool
ssl_verify_upstream_trusted_ca = None # type: Optional[str] ssl_verify_upstream_trusted_ca = None # type: Optional[str]
ssl_verify_upstream_trusted_cadir = None # type: Optional[str] ssl_verify_upstream_trusted_cadir = None # type: Optional[str]
ssl_version_client = None # type: str ssl_version_client = None # type: str
ssl_version_server = 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] stickyauth = None # type: Optional[str]
stickycookie = None # type: Optional[str] stickycookie = None # type: Optional[str]
stream_large_bodies = None # type: Optional[str] stream_large_bodies = None # type: Optional[str]
stream_websockets = None # type: bool stream_websockets = None # type: bool
tcp_hosts = None # type: Sequence[str]
upstream_auth = None # type: Optional[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 = None # type: str
view_order_reversed = None # type: bool view_order_reversed = None # type: bool
web_debug = None # type: bool web_debug = None # type: bool
web_iface = None # type: str web_iface = None # type: str
web_open_browser = None # type: bool web_open_browser = None # type: bool
web_port = None # type: int web_port = None # type: int
websocket = None # type: bool
def __init__(self, **kwargs) -> None: def __init__(self, **kwargs) -> None:
super().__init__() super().__init__()
@ -119,10 +117,6 @@ class Options(optmanager.OptManager):
"onboarding_port", int, APP_PORT, "onboarding_port", int, APP_PORT,
"Port to serve the onboarding app from." "Port to serve the onboarding app from."
) )
self.add_option(
"client_replay", Sequence[str], [],
"Replay client requests from a saved file."
)
self.add_option( self.add_option(
"server_replay_kill_extra", bool, False, "server_replay_kill_extra", bool, False,
"Kill extra requests during replay." "Kill extra requests during replay."

View File

@ -19,8 +19,7 @@ from mitmproxy.test import taddons
]) ])
def test_allowremote(allow_remote, ip, should_be_killed): def test_allowremote(allow_remote, ip, should_be_killed):
ar = allowremote.AllowRemote() ar = allowremote.AllowRemote()
with taddons.context() as tctx: with taddons.context(ar) as tctx:
tctx.master.addons.register(ar)
tctx.options.allow_remote = allow_remote tctx.options.allow_remote = allow_remote
with mock.patch('mitmproxy.proxy.protocol.base.Layer') as layer: with mock.patch('mitmproxy.proxy.protocol.base.Layer') as layer:

View File

@ -24,7 +24,7 @@ class MockThread():
class TestClientPlayback: class TestClientPlayback:
def test_playback(self): def test_playback(self):
cp = clientplayback.ClientPlayback() cp = clientplayback.ClientPlayback()
with taddons.context() as tctx: with taddons.context(cp) as tctx:
assert cp.count() == 0 assert cp.count() == 0
f = tflow.tflow(resp=True) f = tflow.tflow(resp=True)
cp.start_replay([f]) cp.start_replay([f])
@ -58,7 +58,7 @@ class TestClientPlayback:
def test_load_file(self, tmpdir): def test_load_file(self, tmpdir):
cp = clientplayback.ClientPlayback() cp = clientplayback.ClientPlayback()
with taddons.context(): with taddons.context(cp):
fpath = str(tmpdir.join("flows")) fpath = str(tmpdir.join("flows"))
tdump(fpath, [tflow.tflow(resp=True)]) tdump(fpath, [tflow.tflow(resp=True)])
cp.load_file(fpath) cp.load_file(fpath)
@ -68,7 +68,7 @@ class TestClientPlayback:
def test_configure(self, tmpdir): def test_configure(self, tmpdir):
cp = clientplayback.ClientPlayback() cp = clientplayback.ClientPlayback()
with taddons.context() as tctx: with taddons.context(cp) as tctx:
path = str(tmpdir.join("flows")) path = str(tmpdir.join("flows"))
tdump(path, [tflow.tflow()]) tdump(path, [tflow.tflow()])
tctx.configure(cp, client_replay=[path]) tctx.configure(cp, client_replay=[path])