From f361ea491c4719c2a17d4abc0ef894116556a4c1 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 24 Feb 2018 15:58:37 +1300 Subject: [PATCH] addon options: upstream_auth Also the last "easy" option to shift. --- mitmproxy/addons/upstream_auth.py | 10 ++++++++++ mitmproxy/options.py | 16 ---------------- test/mitmproxy/addons/test_upstream_auth.py | 4 ++-- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/mitmproxy/addons/upstream_auth.py b/mitmproxy/addons/upstream_auth.py index 685494c23..ea6af337a 100644 --- a/mitmproxy/addons/upstream_auth.py +++ b/mitmproxy/addons/upstream_auth.py @@ -1,4 +1,5 @@ import re +import typing import base64 from mitmproxy import exceptions @@ -28,6 +29,15 @@ class UpstreamAuth(): def __init__(self): self.auth = None + def load(self, loader): + loader.add_option( + "upstream_auth", typing.Optional[str], None, + """ + Add HTTP Basic authentication to upstream proxy and reverse proxy + requests. Format: username:password. + """ + ) + def configure(self, updated): # FIXME: We're doing this because our proxy core is terminally confused # at the moment. Ideally, we should be able to check if we're in diff --git a/mitmproxy/options.py b/mitmproxy/options.py index ed17489a7..70d454fd3 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -66,15 +66,6 @@ class Options(optmanager.OptManager): verbosity = None # type: str view_filter = None # type: Optional[str] - # FIXME: Options that should be uncomplicated to migrate to addons - upstream_auth = 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 - def __init__(self, **kwargs) -> None: super().__init__() self.add_option( @@ -221,13 +212,6 @@ class Options(optmanager.OptManager): --upstream-bind-address to spoof a fixed source address. """ ) - self.add_option( - "upstream_auth", Optional[str], None, - """ - Add HTTP Basic authentication to upstream proxy and reverse proxy - requests. Format: username:password. - """ - ) self.add_option( "ssl_version_client", str, "secure", """ diff --git a/test/mitmproxy/addons/test_upstream_auth.py b/test/mitmproxy/addons/test_upstream_auth.py index c7342bb5b..53b342a27 100644 --- a/test/mitmproxy/addons/test_upstream_auth.py +++ b/test/mitmproxy/addons/test_upstream_auth.py @@ -9,7 +9,7 @@ from mitmproxy.addons import upstream_auth def test_configure(): up = upstream_auth.UpstreamAuth() - with taddons.context() as tctx: + with taddons.context(up) as tctx: tctx.configure(up, upstream_auth="test:test") assert up.auth == b"Basic" + b" " + base64.b64encode(b"test:test") @@ -29,7 +29,7 @@ def test_configure(): def test_simple(): up = upstream_auth.UpstreamAuth() - with taddons.context() as tctx: + with taddons.context(up) as tctx: tctx.configure(up, upstream_auth="foo:bar") f = tflow.tflow()