mirror of
https://github.com/django/django.git
synced 2024-11-29 14:46:18 +01:00
Refs #27468 -- Added explicit tests for django.utils.crypto.salted_hmac()
This commit is contained in:
parent
59b4e99dd0
commit
b5a62bd17d
@ -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):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user