From: Berker Peksag Date: Sun, 6 Mar 2016 14:27:23 +0000 (+0200) Subject: Issue #2202: Fix UnboundLocalError in AbstractDigestAuthHandler.get_algorithm_impls X-Git-Tag: v2.7.12rc1~197 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=87640b30cef32377be844a16129fcb449ccaec29;p=thirdparty%2FPython%2Fcpython.git Issue #2202: Fix UnboundLocalError in AbstractDigestAuthHandler.get_algorithm_impls Raise ValueError if algorithm is not MD5 or SHA. Initial patch by Mathieu Dupuy. --- diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 5a631b3a5738..a6889cc619c9 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 8ec5e2aefed9..93a3350a867b 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 diff --git a/Misc/NEWS b/Misc/NEWS index 5308a1239a36..a89afa17376e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -55,6 +55,9 @@ Core and Builtins Library ------- +- Issue #2202: Fix UnboundLocalError in + AbstractDigestAuthHandler.get_algorithm_impls. Initial patch by Mathieu Dupuy. + - Issue #26475: Fixed debugging output for regular expressions with the (?x) flag.