Commit e88dd1c3 authored by Berker Peksag's avatar Berker Peksag

Issue #2202: Fix UnboundLocalError in AbstractDigestAuthHandler.get_algorithm_impls

Raise ValueError if algorithm is not MD5 or SHA.

Initial patch by Mathieu Dupuy.
parent 8cc859c1
...@@ -13,7 +13,8 @@ import urllib.request ...@@ -13,7 +13,8 @@ import urllib.request
# proxy config data structure but is testable on all platforms. # proxy config data structure but is testable on all platforms.
from urllib.request import (Request, OpenerDirector, HTTPBasicAuthHandler, from urllib.request import (Request, OpenerDirector, HTTPBasicAuthHandler,
HTTPPasswordMgrWithPriorAuth, _parse_proxy, HTTPPasswordMgrWithPriorAuth, _parse_proxy,
_proxy_bypass_macosx_sysconf) _proxy_bypass_macosx_sysconf,
AbstractDigestAuthHandler)
from urllib.parse import urlparse from urllib.parse import urlparse
import urllib.error import urllib.error
import http.client import http.client
...@@ -1680,6 +1681,15 @@ class MiscTests(unittest.TestCase): ...@@ -1680,6 +1681,15 @@ class MiscTests(unittest.TestCase):
self.assertRaises(ValueError, _parse_proxy, 'file:/ftp.example.com'), 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 RequestTests(unittest.TestCase):
class PutRequest(Request): class PutRequest(Request):
......
...@@ -1111,6 +1111,9 @@ class AbstractDigestAuthHandler: ...@@ -1111,6 +1111,9 @@ class AbstractDigestAuthHandler:
elif algorithm == 'SHA': elif algorithm == 'SHA':
H = lambda x: hashlib.sha1(x.encode("ascii")).hexdigest() H = lambda x: hashlib.sha1(x.encode("ascii")).hexdigest()
# XXX MD5-sess # XXX MD5-sess
else:
raise ValueError("Unsupported digest authentication "
"algorithm %r" % algorithm)
KD = lambda s, d: H("%s:%s" % (s, d)) KD = lambda s, d: H("%s:%s" % (s, d))
return H, KD return H, KD
......
...@@ -91,6 +91,9 @@ Core and Builtins ...@@ -91,6 +91,9 @@ Core and Builtins
Library 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 - Issue #25718: Fixed pickling and copying the accumulate() iterator with
total is None. total is None.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment