From fecb35a08ec77d6392bdc609ab1ea21943e40228 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Fri, 29 Nov 2013 08:37:25 +0000 Subject: [PATCH] Quote qop values in digest auth. --- requests/auth.py | 4 ++-- test_requests.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/requests/auth.py b/requests/auth.py index a3de123..f87087d 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -105,7 +105,7 @@ class HTTPDigestAuth(AuthBase): A1 = '%s:%s:%s' % (self.username, realm, self.password) A2 = '%s:%s' % (method, path) - + HA1 = hash_utf8(A1) HA2 = hash_utf8(A2) @@ -144,7 +144,7 @@ class HTTPDigestAuth(AuthBase): if entdig: base += ', digest="%s"' % entdig if qop: - base += ', qop=auth, nc=%s, cnonce="%s"' % (ncvalue, cnonce) + base += ', qop="auth", nc=%s, cnonce="%s"' % (ncvalue, cnonce) return 'Digest %s' % (base) diff --git a/test_requests.py b/test_requests.py index 3b67395..4035695 100755 --- a/test_requests.py +++ b/test_requests.py @@ -320,6 +320,14 @@ class RequestsTestCase(unittest.TestCase): r = s.get(url) assert r.status_code == 401 + def test_DIGESTAUTH_QUOTES_QOP_VALUE(self): + + auth = HTTPDigestAuth('user', 'pass') + url = httpbin('digest-auth', 'auth', 'user', 'pass') + + r = requests.get(url, auth=auth) + assert '"auth"' in r.request.headers['Authorization'] + def test_POSTBIN_GET_POST_FILES(self): url = httpbin('post') -- 2.34.1