mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-12-02 12:01:17 +00:00
addon options: proxyauth to /addons
This commit is contained in:
parent
59db25bd0f
commit
6ea81a96d4
@ -52,6 +52,18 @@ class ProxyAuth:
|
|||||||
self.authenticated = weakref.WeakKeyDictionary() # type: MutableMapping[connections.ClientConnection, Tuple[str, str]]
|
self.authenticated = weakref.WeakKeyDictionary() # type: MutableMapping[connections.ClientConnection, Tuple[str, str]]
|
||||||
"""Contains all connections that are permanently authenticated after an HTTP CONNECT"""
|
"""Contains all connections that are permanently authenticated after an HTTP CONNECT"""
|
||||||
|
|
||||||
|
def load(self, loader):
|
||||||
|
loader.add_option(
|
||||||
|
"proxyauth", Optional[str], None,
|
||||||
|
"""
|
||||||
|
Require proxy authentication. Format:
|
||||||
|
"username:pass",
|
||||||
|
"any" to accept any user/pass combination,
|
||||||
|
"@path" to use an Apache htpasswd file,
|
||||||
|
or "ldap[s]:url_server_ldap:dn_auth:password:dn_subtree" for LDAP authentication.
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
def enabled(self) -> bool:
|
def enabled(self) -> bool:
|
||||||
return any([self.nonanonymous, self.htpasswd, self.singleuser, self.ldapconn, self.ldapserver])
|
return any([self.nonanonymous, self.htpasswd, self.singleuser, self.ldapconn, self.ldapserver])
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@ class Options(optmanager.OptManager):
|
|||||||
# FIXME: Options that must be migrated to addons, but are complicated
|
# FIXME: Options that must be migrated to addons, but are complicated
|
||||||
# because they're used by more than one addon, or because they're
|
# because they're used by more than one addon, or because they're
|
||||||
# embedded in the core code somehow.
|
# embedded in the core code somehow.
|
||||||
proxyauth = None # type: Optional[str]
|
|
||||||
showhost = None # type: bool
|
showhost = None # type: bool
|
||||||
verbosity = None # type: str
|
verbosity = None # type: str
|
||||||
view_filter = None # type: Optional[str]
|
view_filter = None # type: Optional[str]
|
||||||
@ -78,16 +77,6 @@ class Options(optmanager.OptManager):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Proxy options
|
# Proxy options
|
||||||
self.add_option(
|
|
||||||
"proxyauth", Optional[str], None,
|
|
||||||
"""
|
|
||||||
Require proxy authentication. Format:
|
|
||||||
"username:pass",
|
|
||||||
"any" to accept any user/pass combination,
|
|
||||||
"@path" to use an Apache htpasswd file,
|
|
||||||
or "ldap[s]:url_server_ldap:dn_auth:password:dn_subtree" for LDAP authentication.
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
self.add_option(
|
self.add_option(
|
||||||
"add_upstream_certs_to_client_chain", bool, False,
|
"add_upstream_certs_to_client_chain", bool, False,
|
||||||
"""
|
"""
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from mitmproxy.addons import allowremote
|
from mitmproxy.addons import allowremote, proxyauth
|
||||||
from mitmproxy.test import taddons
|
from mitmproxy.test import taddons
|
||||||
|
|
||||||
|
|
||||||
@ -19,7 +19,8 @@ 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(ar) as tctx:
|
up = proxyauth.ProxyAuth()
|
||||||
|
with taddons.context(ar, up) as tctx:
|
||||||
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:
|
||||||
|
@ -49,7 +49,7 @@ class TestProxyAuth:
|
|||||||
])
|
])
|
||||||
def test_is_proxy_auth(self, mode, expected):
|
def test_is_proxy_auth(self, mode, expected):
|
||||||
up = proxyauth.ProxyAuth()
|
up = proxyauth.ProxyAuth()
|
||||||
with taddons.context() as ctx:
|
with taddons.context(up) as ctx:
|
||||||
ctx.options.mode = mode
|
ctx.options.mode = mode
|
||||||
assert up.is_proxy_auth() is expected
|
assert up.is_proxy_auth() is expected
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ class TestProxyAuth:
|
|||||||
|
|
||||||
def test_check(self):
|
def test_check(self):
|
||||||
up = proxyauth.ProxyAuth()
|
up = proxyauth.ProxyAuth()
|
||||||
with taddons.context() as ctx:
|
with taddons.context(up) as ctx:
|
||||||
ctx.configure(up, proxyauth="any", mode="regular")
|
ctx.configure(up, proxyauth="any", mode="regular")
|
||||||
f = tflow.tflow()
|
f = tflow.tflow()
|
||||||
assert not up.check(f)
|
assert not up.check(f)
|
||||||
@ -133,7 +133,7 @@ class TestProxyAuth:
|
|||||||
|
|
||||||
def test_authenticate(self):
|
def test_authenticate(self):
|
||||||
up = proxyauth.ProxyAuth()
|
up = proxyauth.ProxyAuth()
|
||||||
with taddons.context() as ctx:
|
with taddons.context(up) as ctx:
|
||||||
ctx.configure(up, proxyauth="any", mode="regular")
|
ctx.configure(up, proxyauth="any", mode="regular")
|
||||||
|
|
||||||
f = tflow.tflow()
|
f = tflow.tflow()
|
||||||
@ -165,7 +165,7 @@ class TestProxyAuth:
|
|||||||
|
|
||||||
def test_configure(self):
|
def test_configure(self):
|
||||||
up = proxyauth.ProxyAuth()
|
up = proxyauth.ProxyAuth()
|
||||||
with taddons.context() as ctx:
|
with taddons.context(up) as ctx:
|
||||||
with pytest.raises(exceptions.OptionsError):
|
with pytest.raises(exceptions.OptionsError):
|
||||||
ctx.configure(up, proxyauth="foo")
|
ctx.configure(up, proxyauth="foo")
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ class TestProxyAuth:
|
|||||||
|
|
||||||
def test_handlers(self):
|
def test_handlers(self):
|
||||||
up = proxyauth.ProxyAuth()
|
up = proxyauth.ProxyAuth()
|
||||||
with taddons.context() as ctx:
|
with taddons.context(up) as ctx:
|
||||||
ctx.configure(up, proxyauth="any", mode="regular")
|
ctx.configure(up, proxyauth="any", mode="regular")
|
||||||
|
|
||||||
f = tflow.tflow()
|
f = tflow.tflow()
|
||||||
|
Loading…
Reference in New Issue
Block a user