summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-05-08 17:36:08 (GMT)
committerGeorg Brandl <georg@python.org>2006-05-08 17:36:08 (GMT)
commitb5f2e5cc50a5eab06d36e25d7edc137eae454518 (patch)
tree9a1325ff52ef8f5a2abd08487b7c788f5f70e35a
parenta166a91659795b97144bbd9f1c2adf89c8adc694 (diff)
downloadcpython-b5f2e5cc50a5eab06d36e25d7edc137eae454518.zip
cpython-b5f2e5cc50a5eab06d36e25d7edc137eae454518.tar.gz
cpython-b5f2e5cc50a5eab06d36e25d7edc137eae454518.tar.bz2
Patch #1479302: Make urllib2 digest auth and basic auth play together.
-rw-r--r--Lib/test/test_urllib2.py21
-rw-r--r--Lib/urllib2.py3
2 files changed, 21 insertions, 3 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 08b97a6..c8f19bc 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -779,6 +779,27 @@ class HandlerTests(unittest.TestCase):
"proxy.example.com:3128",
)
+ def test_basic_and_digest_auth_handlers(self):
+ # HTTPDigestAuthHandler threw an exception if it couldn't handle a 40*
+ # response (http://python.org/sf/1479302), where it should instead
+ # return None to allow another handler (especially
+ # HTTPBasicAuthHandler) to handle the response.
+ class TestDigestAuthHandler(urllib2.HTTPDigestAuthHandler):
+ handler_order = 400 # strictly before HTTPBasicAuthHandler
+ opener = OpenerDirector()
+ password_manager = MockPasswordManager()
+ digest_handler = TestDigestAuthHandler(password_manager)
+ basic_handler = urllib2.HTTPBasicAuthHandler(password_manager)
+ opener.add_handler(digest_handler)
+ realm = "ACME Networks"
+ http_handler = MockHTTPHandler(
+ 401, 'WWW-Authenticate: Basic realm="%s"\r\n\r\n' % realm)
+ self._test_basic_auth(opener, basic_handler, "Authorization",
+ realm, http_handler, password_manager,
+ "http://acme.example.com/protected",
+ "http://acme.example.com/protected",
+ )
+
def _test_basic_auth(self, opener, auth_handler, auth_header,
realm, http_handler, password_manager,
request_url, protected_url):
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 8d38504..5948376 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -846,9 +846,6 @@ class AbstractDigestAuthHandler:
scheme = authreq.split()[0]
if scheme.lower() == 'digest':
return self.retry_http_digest_auth(req, authreq)
- else:
- raise ValueError("AbstractDigestAuthHandler doesn't know "
- "about %s"%(scheme))
def retry_http_digest_auth(self, req, auth):
token, challenge = auth.split(' ', 1)