addon options: upstream_auth

Also the last "easy" option to shift.
This commit is contained in:
Aldo Cortesi 2018-02-24 15:58:37 +13:00
parent 2aa7ac584b
commit f361ea491c
3 changed files with 12 additions and 18 deletions

View File

@ -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

View File

@ -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",
"""

View File

@ -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()