add test for HTTP Digest auth algorithms and
@@ -54,6 +54,8 @@ except AttributeError:
class TestRequests:
+ digest_auth_algo = ('MD5', 'SHA-256', 'SHA-512')
+
def test_entry_points(self):
requests.session
@@ -574,14 +576,16 @@ class TestRequests:
def test_DIGEST_HTTP_200_OK_GET(self, httpbin):
+ for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth('user', 'pass')
- url = httpbin('digest-auth', 'auth', 'user', 'pass')
+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype, 'never')
r = requests.get(url, auth=auth)
assert r.status_code == 200
r = requests.get(url)
assert r.status_code == 401
+ print(r.headers['WWW-Authenticate'])
s = requests.session()
s.auth = HTTPDigestAuth('user', 'pass')
@@ -589,7 +593,9 @@ class TestRequests:
assert r.status_code == 200
def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):
- url = httpbin('digest-auth', 'auth', 'user', 'pass')
+
+ for authtype in self.digest_auth_algo:
+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype)
auth = HTTPDigestAuth('user', 'pass')
r = requests.get(url)
assert r.cookies['fake'] == 'fake_value'
@@ -598,7 +604,9 @@ class TestRequests:
assert r.status_code == 200
def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):
- url = httpbin('digest-auth', 'auth', 'user', 'pass')
+
+ for authtype in self.digest_auth_algo:
+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype)
auth = HTTPDigestAuth('user', 'pass')
s = requests.Session()
s.get(url, auth=auth)
@@ -606,8 +614,9 @@ class TestRequests:
def test_DIGEST_STREAM(self, httpbin):
+ for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth('user', 'pass')
- url = httpbin('digest-auth', 'auth', 'user', 'pass')
+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype)
r = requests.get(url, auth=auth, stream=True)
assert r.raw.read() != b''
@@ -617,8 +626,9 @@ class TestRequests:
def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):
+ for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth('user', 'wrongpass')
- url = httpbin('digest-auth', 'auth', 'user', 'pass')
+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype)
r = requests.get(url, auth=auth)
assert r.status_code == 401
@@ -633,8 +643,9 @@ class TestRequests:
def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):
+ for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth('user', 'pass')
- url = httpbin('digest-auth', 'auth', 'user', 'pass')
+ url = httpbin('digest-auth', 'auth', 'user', 'pass', authtype)
r = requests.get(url, auth=auth)
assert '"auth"' in r.request.headers['Authorization']
