Quote qop values in digest auth.
authorCory Benfield <lukasaoz@gmail.com>
Fri, 29 Nov 2013 08:37:25 +0000 (08:37 +0000)
committerCory Benfield <lukasaoz@gmail.com>
Fri, 29 Nov 2013 08:37:25 +0000 (08:37 +0000)
requests/auth.py
test_requests.py

index a3de123d306be88f910db295ca21e106d8fd202f..f87087dfd222167392b4c8aa49747f2cfa64d6e1 100644 (file)
@@ -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)
 
index 3b673956ce7cbb7326f1c79dc53c21e024b819e1..4035695d3470392cb960927b948c4c489cf544ea 100755 (executable)
@@ -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')