summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-03-06 16:16:40 +0200
committerBerker Peksag <berker.peksag@gmail.com>2016-03-06 16:16:40 +0200
commite88dd1c32c2961e0fe40b09c48904451fa1eba9a (patch)
tree8bc1614b2ffb4bf2878b63ecca28175d84a7e86c
parent8cc859c103287089daeece91793fd2acc49baff9 (diff)
downloadcpython-git-e88dd1c32c2961e0fe40b09c48904451fa1eba9a.tar.gz
Issue #2202: Fix UnboundLocalError in AbstractDigestAuthHandler.get_algorithm_impls
Raise ValueError if algorithm is not MD5 or SHA. Initial patch by Mathieu Dupuy.
-rw-r--r--Lib/test/test_urllib2.py12
-rw-r--r--Lib/urllib/request.py3
-rw-r--r--Misc/NEWS3
3 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index a5281d864c..008c751f9c 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -13,7 +13,8 @@ import urllib.request
# proxy config data structure but is testable on all platforms.
from urllib.request import (Request, OpenerDirector, HTTPBasicAuthHandler,
HTTPPasswordMgrWithPriorAuth, _parse_proxy,
- _proxy_bypass_macosx_sysconf)
+ _proxy_bypass_macosx_sysconf,
+ AbstractDigestAuthHandler)
from urllib.parse import urlparse
import urllib.error
import http.client
@@ -1680,6 +1681,15 @@ class MiscTests(unittest.TestCase):
self.assertRaises(ValueError, _parse_proxy, 'file:/ftp.example.com'),
+ 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):
class PutRequest(Request):
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 4c1651861b..fc8ef7f91b 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1111,6 +1111,9 @@ class AbstractDigestAuthHandler:
elif algorithm == 'SHA':
H = lambda x: hashlib.sha1(x.encode("ascii")).hexdigest()
# XXX MD5-sess
+ else:
+ raise ValueError("Unsupported digest authentication "
+ "algorithm %r" % algorithm)
KD = lambda s, d: H("%s:%s" % (s, d))
return H, KD
diff --git a/Misc/NEWS b/Misc/NEWS
index 8257b0f745..9a775ac527 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -91,6 +91,9 @@ Core and Builtins
Library
-------
+- Issue #2202: Fix UnboundLocalError in
+ AbstractDigestAuthHandler.get_algorithm_impls. Initial patch by Mathieu Dupuy.
+
- Issue #25718: Fixed pickling and copying the accumulate() iterator with
total is None.