aboutsummaryrefslogtreecommitdiffstats
path: root/test/http/test_authentication.py
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2015-07-15 22:32:14 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-07-22 15:30:51 +0200
commitbab6cbff1e5444aea72a188d57812130c375e0f0 (patch)
tree5b33c11cf076a099a039fa8e8494acf5b1eff07e /test/http/test_authentication.py
parentf50deb7b763d093a22a4d331e16465a2fb0329cf (diff)
downloadmitmproxy-bab6cbff1e5444aea72a188d57812130c375e0f0.tar.gz
mitmproxy-bab6cbff1e5444aea72a188d57812130c375e0f0.tar.bz2
mitmproxy-bab6cbff1e5444aea72a188d57812130c375e0f0.zip
extract authentication methods from protocol
Diffstat (limited to 'test/http/test_authentication.py')
-rw-r--r--test/http/test_authentication.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/test/http/test_authentication.py b/test/http/test_authentication.py
index c0dae1a2..8f231643 100644
--- a/test/http/test_authentication.py
+++ b/test/http/test_authentication.py
@@ -1,8 +1,21 @@
+import binascii
+
from netlib import odict, http
from netlib.http import authentication
from .. import tutils
+def test_parse_http_basic_auth():
+ vals = ("basic", "foo", "bar")
+ assert http.authentication.parse_http_basic_auth(
+ http.authentication.assemble_http_basic_auth(*vals)
+ ) == vals
+ assert not http.authentication.parse_http_basic_auth("")
+ assert not http.authentication.parse_http_basic_auth("foo bar")
+ v = "basic " + binascii.b2a_base64("foo")
+ assert not http.authentication.parse_http_basic_auth(v)
+
+
class TestPassManNonAnon:
def test_simple(self):
@@ -23,7 +36,7 @@ class TestPassManHtpasswd:
pm = authentication.PassManHtpasswd(tutils.test_data.path("data/htpasswd"))
vals = ("basic", "test", "test")
- http.http1.assemble_http_basic_auth(*vals)
+ authentication.assemble_http_basic_auth(*vals)
assert pm.test("test", "test")
assert not pm.test("test", "foo")
assert not pm.test("foo", "test")
@@ -62,7 +75,7 @@ class TestBasicProxyAuth:
hdrs = odict.ODictCaseless()
vals = ("basic", "foo", "bar")
- hdrs[ba.AUTH_HEADER] = [http.http1.assemble_http_basic_auth(*vals)]
+ hdrs[ba.AUTH_HEADER] = [authentication.assemble_http_basic_auth(*vals)]
assert ba.authenticate(hdrs)
ba.clean(hdrs)
@@ -75,12 +88,12 @@ class TestBasicProxyAuth:
assert not ba.authenticate(hdrs)
vals = ("foo", "foo", "bar")
- hdrs[ba.AUTH_HEADER] = [http.http1.assemble_http_basic_auth(*vals)]
+ hdrs[ba.AUTH_HEADER] = [authentication.assemble_http_basic_auth(*vals)]
assert not ba.authenticate(hdrs)
ba = authentication.BasicProxyAuth(authentication.PassMan(), "test")
vals = ("basic", "foo", "bar")
- hdrs[ba.AUTH_HEADER] = [http.http1.assemble_http_basic_auth(*vals)]
+ hdrs[ba.AUTH_HEADER] = [authentication.assemble_http_basic_auth(*vals)]
assert not ba.authenticate(hdrs)