diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_urllib2.py | 12 | ||||
-rw-r--r-- | Lib/urllib2.py | 3 |
2 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 5a631b3..a6889cc 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -6,7 +6,7 @@ import socket import StringIO import urllib2 -from urllib2 import Request, OpenerDirector +from urllib2 import Request, OpenerDirector, AbstractDigestAuthHandler try: import ssl @@ -1290,6 +1290,16 @@ class MiscTests(unittest.TestCase): else: self.assertTrue(False) + def test_unsupported_algorithm(self): + handler = AbstractDigestAuthHandler() + with self.assertRaises(ValueError) as exc: + handler.get_algorithm_impls('invalid') + self.assertEqual( + str(exc.exception), + "Unsupported digest authentication algorithm 'invalid'" + ) + + class RequestTests(unittest.TestCase): def setUp(self): diff --git a/Lib/urllib2.py b/Lib/urllib2.py index 8ec5e2a..93a3350 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -1071,6 +1071,9 @@ class AbstractDigestAuthHandler: elif algorithm == 'SHA': H = lambda x: hashlib.sha1(x).hexdigest() # XXX MD5-sess + else: + raise ValueError("Unsupported digest authentication " + "algorithm %r" % algorithm.lower()) KD = lambda s, d: H("%s:%s" % (s, d)) return H, KD |