summaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test.py')
-rwxr-xr-xtest.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/test.py b/test.py
index f2e8910..1183d63 100755
--- a/test.py
+++ b/test.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
+import base64
import unittest
import doctest
import wsgiref.validate
@@ -7,6 +8,8 @@ import io
from hashlib import md5
import sys
+from wsgitools.internal import bytes2str, str2bytes
+
class Request:
def __init__(self, case):
"""
@@ -193,9 +196,9 @@ class AuthDigestMiddlewareTest(unittest.TestCase):
res.getheader("WWW-Authenticate").split())))
nonce = nonce.split('"')[1]
req = self.req.copy()
- token = md5("bar:foo:%s" % password).hexdigest()
- other = md5("GET:").hexdigest()
- resp = md5("%s:%s:%s" % (token, nonce, other)).hexdigest()
+ token = md5(str2bytes("bar:foo:%s" % password)).hexdigest()
+ other = md5(str2bytes("GET:")).hexdigest()
+ resp = md5(str2bytes("%s:%s:%s" % (token, nonce, other))).hexdigest()
req.setheader('http-authorization', 'Digest algorithm=md5,nonce="%s",' \
'uri=,username=bar,response="%s"' % (nonce, resp))
res = req(self.app)
@@ -213,9 +216,10 @@ class AuthDigestMiddlewareTest(unittest.TestCase):
res.getheader("WWW-Authenticate").split())))
nonce = nonce.split('"')[1]
req = self.req.copy()
- token = md5("bar:foo:baz").hexdigest()
- other = md5("GET:").hexdigest()
- resp = md5("%s:%s:1:qux:auth:%s" % (token, nonce, other)).hexdigest()
+ token = md5(str2bytes("bar:foo:baz")).hexdigest()
+ other = md5(str2bytes("GET:")).hexdigest()
+ resp = "%s:%s:1:qux:auth:%s" % (token, nonce, other)
+ resp = md5(str2bytes(resp)).hexdigest()
req.setheader('http-authorization', 'Digest algorithm=md5,nonce="%s",' \
'uri=,username=bar,response="%s",qop=auth,nc=1,' \
'cnonce=qux' % (nonce, resp))
@@ -318,7 +322,8 @@ class BasicAuthMiddlewareTest(unittest.TestCase):
def doauth(self, password="baz", status=200):
req = self.req.copy()
- token = ("bar:%s" % password).encode("base64").strip()
+ token = "bar:%s" % password
+ token = bytes2str(base64.b64encode(str2bytes(token)))
req.setheader('http-authorization', 'Basic %s' % token)
res = req(self.app)
res.status(status)