summaryrefslogtreecommitdiff
path: root/tests/utils_tests/test_crypto.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2020-01-08 16:23:08 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-01-15 12:53:21 +0100
commitb5a62bd17db0e28e6842111034fa6714d0701edb (patch)
tree5395f9ba2175f8668e8619163ce1dc4b93f32ab5 /tests/utils_tests/test_crypto.py
parent59b4e99dd00b9c36d56055b889f96885995e4240 (diff)
Refs #27468 -- Added explicit tests for django.utils.crypto.salted_hmac()
Diffstat (limited to 'tests/utils_tests/test_crypto.py')
-rw-r--r--tests/utils_tests/test_crypto.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/utils_tests/test_crypto.py b/tests/utils_tests/test_crypto.py
index c2045fc4ab..1c3868f4ca 100644
--- a/tests/utils_tests/test_crypto.py
+++ b/tests/utils_tests/test_crypto.py
@@ -1,7 +1,7 @@
import hashlib
import unittest
-from django.utils.crypto import constant_time_compare, pbkdf2
+from django.utils.crypto import constant_time_compare, pbkdf2, salted_hmac
class TestUtilsCryptoMisc(unittest.TestCase):
@@ -13,6 +13,25 @@ class TestUtilsCryptoMisc(unittest.TestCase):
self.assertTrue(constant_time_compare('spam', 'spam'))
self.assertFalse(constant_time_compare('spam', 'eggs'))
+ def test_salted_hmac(self):
+ tests = [
+ ((b'salt', b'value'), {}, 'b51a2e619c43b1ca4f91d15c57455521d71d61eb'),
+ (('salt', 'value'), {}, 'b51a2e619c43b1ca4f91d15c57455521d71d61eb'),
+ (
+ ('salt', 'value'),
+ {'secret': 'abcdefg'},
+ '8bbee04ccddfa24772d1423a0ba43bd0c0e24b76',
+ ),
+ (
+ ('salt', 'value'),
+ {'secret': 'x' * hashlib.sha1().block_size},
+ 'bd3749347b412b1b0a9ea65220e55767ac8e96b0',
+ ),
+ ]
+ for args, kwargs, digest in tests:
+ with self.subTest(args=args, kwargs=kwargs):
+ self.assertEqual(salted_hmac(*args, **kwargs).hexdigest(), digest)
+
class TestUtilsCryptoPBKDF2(unittest.TestCase):