aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_authentication.py
diff options
context:
space:
mode:
authorRouli <rouli.net@gmail.com>2013-01-17 17:33:29 +0200
committerRouli <rouli.net@gmail.com>2013-01-17 17:33:29 +0200
commit446f9f0a0fc12159ba663d3b8bdc8f1206a197c7 (patch)
tree9cb474c3154fb4146cce41e40e25b4a8e3e57d46 /test/test_authentication.py
parent20fa6a30839500207d7d509fe3b8697dbd22a33e (diff)
parent280dd94198931bcd819848a70d68f6f5d9f3270b (diff)
downloadmitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.tar.gz
mitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.tar.bz2
mitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'test/test_authentication.py')
-rw-r--r--test/test_authentication.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/test_authentication.py b/test/test_authentication.py
new file mode 100644
index 00000000..f7a5ecd3
--- /dev/null
+++ b/test/test_authentication.py
@@ -0,0 +1,58 @@
+import binascii
+from libmproxy import authentication
+from netlib import odict
+import tutils
+
+
+class TestNullProxyAuth:
+ def test_simple(self):
+ na = authentication.NullProxyAuth(authentication.PermissivePasswordManager())
+ assert not na.auth_challenge_headers()
+ assert na.authenticate("foo")
+ na.clean({})
+
+
+class TestBasicProxyAuth:
+ def test_simple(self):
+ ba = authentication.BasicProxyAuth(authentication.PermissivePasswordManager(), "test")
+ h = odict.ODictCaseless()
+ assert ba.auth_challenge_headers()
+ assert not ba.authenticate(h)
+
+ def test_parse_auth_value(self):
+ ba = authentication.BasicProxyAuth(authentication.PermissivePasswordManager(), "test")
+ vals = ("basic", "foo", "bar")
+ assert ba.parse_auth_value(ba.unparse_auth_value(*vals)) == vals
+ tutils.raises(ValueError, ba.parse_auth_value, "")
+ tutils.raises(ValueError, ba.parse_auth_value, "foo bar")
+
+ v = "basic " + binascii.b2a_base64("foo")
+ tutils.raises(ValueError, ba.parse_auth_value, v)
+
+ def test_authenticate_clean(self):
+ ba = authentication.BasicProxyAuth(authentication.PermissivePasswordManager(), "test")
+
+ hdrs = odict.ODictCaseless()
+ vals = ("basic", "foo", "bar")
+ hdrs[ba.AUTH_HEADER] = [ba.unparse_auth_value(*vals)]
+ assert ba.authenticate(hdrs)
+
+ ba.clean(hdrs)
+ assert not ba.AUTH_HEADER in hdrs
+
+
+ hdrs[ba.AUTH_HEADER] = [""]
+ assert not ba.authenticate(hdrs)
+
+ hdrs[ba.AUTH_HEADER] = ["foo"]
+ assert not ba.authenticate(hdrs)
+
+ vals = ("foo", "foo", "bar")
+ hdrs[ba.AUTH_HEADER] = [ba.unparse_auth_value(*vals)]
+ assert not ba.authenticate(hdrs)
+
+ ba = authentication.BasicProxyAuth(authentication.PasswordManager(), "test")
+ vals = ("basic", "foo", "bar")
+ hdrs[ba.AUTH_HEADER] = [ba.unparse_auth_value(*vals)]
+ assert not ba.authenticate(hdrs)
+