From cf83cbf2dffebf34b451fb9f89d4ade5bfe47e72 Mon Sep 17 00:00:00 2001 From: lymanZerga11 Date: Wed, 8 Mar 2017 11:34:59 +0800 Subject: Update proxyauth.py --- mitmproxy/addons/proxyauth.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mitmproxy/addons/proxyauth.py b/mitmproxy/addons/proxyauth.py index 18a85866..ba6250f6 100644 --- a/mitmproxy/addons/proxyauth.py +++ b/mitmproxy/addons/proxyauth.py @@ -46,7 +46,7 @@ class ProxyAuth: self.htpasswd = None self.singleuser = None self.mode = None - self.authenticated = weakref.WeakSet() # type: Set[connections.ClientConnection] + self.authenticated = weakref.WeakKeyDictionary() """Contains all connections that are permanently authenticated after an HTTP CONNECT""" def enabled(self) -> bool: @@ -155,11 +155,12 @@ class ProxyAuth: def http_connect(self, f: http.HTTPFlow) -> None: if self.enabled(): if self.authenticate(f): - self.authenticated.add(f.client_conn) + self.authenticated[f.client_conn]=f.metadata["proxyauth"] def requestheaders(self, f: http.HTTPFlow) -> None: if self.enabled(): # Is this connection authenticated by a previous HTTP CONNECT? if f.client_conn in self.authenticated: + f.metadata["proxyauth"] = self.authenticated[f.client_conn] return self.authenticate(f) -- cgit v1.2.3 From 716306538f9bd073cda487d38df4a49d87994bab Mon Sep 17 00:00:00 2001 From: lymanZerga11 Date: Wed, 8 Mar 2017 13:59:43 +0800 Subject: Update proxyauth.py --- mitmproxy/addons/proxyauth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitmproxy/addons/proxyauth.py b/mitmproxy/addons/proxyauth.py index ba6250f6..3c3172bb 100644 --- a/mitmproxy/addons/proxyauth.py +++ b/mitmproxy/addons/proxyauth.py @@ -155,7 +155,7 @@ class ProxyAuth: def http_connect(self, f: http.HTTPFlow) -> None: if self.enabled(): if self.authenticate(f): - self.authenticated[f.client_conn]=f.metadata["proxyauth"] + self.authenticated[f.client_conn] = f.metadata["proxyauth"] def requestheaders(self, f: http.HTTPFlow) -> None: if self.enabled(): -- cgit v1.2.3 From 618e0c62656a992d929900de57e23b18cb3d6d3d Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Wed, 8 Mar 2017 15:10:06 +0100 Subject: add type hints --- mitmproxy/addons/proxyauth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mitmproxy/addons/proxyauth.py b/mitmproxy/addons/proxyauth.py index 3c3172bb..fffc4fcd 100644 --- a/mitmproxy/addons/proxyauth.py +++ b/mitmproxy/addons/proxyauth.py @@ -1,7 +1,7 @@ import binascii import weakref from typing import Optional -from typing import Set # noqa +from typing import Mapping # noqa from typing import Tuple import passlib.apache @@ -46,7 +46,7 @@ class ProxyAuth: self.htpasswd = None self.singleuser = None self.mode = None - self.authenticated = weakref.WeakKeyDictionary() + self.authenticated = weakref.WeakKeyDictionary() # type: Mapping[connections.ClientConnection, Tuple[str, str]] """Contains all connections that are permanently authenticated after an HTTP CONNECT""" def enabled(self) -> bool: -- cgit v1.2.3 From 6d53d08b6c6e55e1ce787ca8f0110351723fc21d Mon Sep 17 00:00:00 2001 From: lymanZerga11 Date: Thu, 9 Mar 2017 09:01:04 +0800 Subject: Add tests --- test/mitmproxy/addons/test_proxyauth.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/mitmproxy/addons/test_proxyauth.py b/test/mitmproxy/addons/test_proxyauth.py index dd5829ab..8b64a21b 100644 --- a/test/mitmproxy/addons/test_proxyauth.py +++ b/test/mitmproxy/addons/test_proxyauth.py @@ -171,3 +171,4 @@ def test_handlers(): f2 = tflow.tflow(client_conn=f.client_conn) up.requestheaders(f2) assert not f2.response + assert f2.metadata["proxyauth"] == ('test','test') -- cgit v1.2.3 From 8e67c6f512e53854bec567a0b1cc42bf34b6cedf Mon Sep 17 00:00:00 2001 From: lymanZerga11 Date: Thu, 9 Mar 2017 09:01:37 +0800 Subject: add tests --- test/mitmproxy/addons/test_proxyauth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mitmproxy/addons/test_proxyauth.py b/test/mitmproxy/addons/test_proxyauth.py index 8b64a21b..82517bff 100644 --- a/test/mitmproxy/addons/test_proxyauth.py +++ b/test/mitmproxy/addons/test_proxyauth.py @@ -171,4 +171,4 @@ def test_handlers(): f2 = tflow.tflow(client_conn=f.client_conn) up.requestheaders(f2) assert not f2.response - assert f2.metadata["proxyauth"] == ('test','test') + assert f2.metadata["proxyauth"] == ('test', 'test') -- cgit v1.2.3 From f3df4855aff135ef5d4206ce0d3c988671c415db Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 10 Mar 2017 19:15:44 +0100 Subject: fix type hints --- mitmproxy/addons/proxyauth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mitmproxy/addons/proxyauth.py b/mitmproxy/addons/proxyauth.py index fffc4fcd..992ec322 100644 --- a/mitmproxy/addons/proxyauth.py +++ b/mitmproxy/addons/proxyauth.py @@ -1,7 +1,7 @@ import binascii import weakref from typing import Optional -from typing import Mapping # noqa +from typing import MutableMapping # noqa from typing import Tuple import passlib.apache @@ -46,7 +46,7 @@ class ProxyAuth: self.htpasswd = None self.singleuser = None self.mode = None - self.authenticated = weakref.WeakKeyDictionary() # type: Mapping[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""" def enabled(self) -> bool: -- cgit v1.2.3