summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorCalvin Bui <3604363+calvinbui@users.noreply.github.com>2024-12-28 21:05:34 (GMT)
committerGitHub <noreply@github.com>2024-12-28 21:05:34 (GMT)
commitf9a5a3a3ef34e63dc197156e9a5f57842859ca04 (patch)
treeb823b79dc0e2edaf819b13224d6795c93179ecfb /Lib/test
parent492b224b991cd9027f1bc6d9988d01e94f764992 (diff)
downloadcpython-f9a5a3a3ef34e63dc197156e9a5f57842859ca04.zip
cpython-f9a5a3a3ef34e63dc197156e9a5f57842859ca04.tar.gz
cpython-f9a5a3a3ef34e63dc197156e9a5f57842859ca04.tar.bz2
gh-128192: support HTTP sha-256 digest authentication as per RFC-7617 (GH-128193)
support sha-256 digest authentication Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_urllib2.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 4a9e653..96d91c1 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1962,10 +1962,29 @@ class MiscTests(unittest.TestCase):
self.assertRaises(ValueError, _parse_proxy, 'file:/ftp.example.com'),
- def test_unsupported_algorithm(self):
- handler = AbstractDigestAuthHandler()
+
+class TestDigestAlgorithms(unittest.TestCase):
+ def setUp(self):
+ self.handler = AbstractDigestAuthHandler()
+
+ def test_md5_algorithm(self):
+ H, KD = self.handler.get_algorithm_impls('MD5')
+ self.assertEqual(H("foo"), "acbd18db4cc2f85cedef654fccc4a4d8")
+ self.assertEqual(KD("foo", "bar"), "4e99e8c12de7e01535248d2bac85e732")
+
+ def test_sha_algorithm(self):
+ H, KD = self.handler.get_algorithm_impls('SHA')
+ self.assertEqual(H("foo"), "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
+ self.assertEqual(KD("foo", "bar"), "54dcbe67d21d5eb39493d46d89ae1f412d3bd6de")
+
+ def test_sha256_algorithm(self):
+ H, KD = self.handler.get_algorithm_impls('SHA-256')
+ self.assertEqual(H("foo"), "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae")
+ self.assertEqual(KD("foo", "bar"), "a765a8beaa9d561d4c5cbed29d8f4e30870297fdfa9cb7d6e9848a95fec9f937")
+
+ def test_invalid_algorithm(self):
with self.assertRaises(ValueError) as exc:
- handler.get_algorithm_impls('invalid')
+ self.handler.get_algorithm_impls('invalid')
self.assertEqual(
str(exc.exception),
"Unsupported digest authentication algorithm 'invalid'"