summaryrefslogtreecommitdiff
path: root/tests/utils_tests
diff options
context:
space:
mode:
authorSaJH <wogur981208@gmail.com>2025-08-22 15:32:09 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-08-25 14:45:16 +0200
commit0246f478882c26bc1fe293224653074cd46a90d0 (patch)
treeed94f807ae565c16be1ad634654bae98ea7596a9 /tests/utils_tests
parent3ba24c18e70dd242ae237fd955fb8be30f99bc4d (diff)
Fixed #36546 -- Deprecated django.utils.crypto.constant_time_compare() in favor of hmac.compare_digest().
Signed-off-by: SaJH <wogur981208@gmail.com>
Diffstat (limited to 'tests/utils_tests')
-rw-r--r--tests/utils_tests/test_crypto.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/utils_tests/test_crypto.py b/tests/utils_tests/test_crypto.py
index ed3ed25a9d..bbedb3080d 100644
--- a/tests/utils_tests/test_crypto.py
+++ b/tests/utils_tests/test_crypto.py
@@ -2,15 +2,19 @@ import hashlib
import unittest
from django.test import SimpleTestCase
+from django.test.utils import ignore_warnings
from django.utils.crypto import (
InvalidAlgorithm,
constant_time_compare,
pbkdf2,
salted_hmac,
)
+from django.utils.deprecation import RemovedInDjango70Warning
class TestUtilsCryptoMisc(SimpleTestCase):
+ # RemovedInDjango70Warning.
+ @ignore_warnings(category=RemovedInDjango70Warning)
def test_constant_time_compare(self):
# It's hard to test for constant time, just test the result.
self.assertTrue(constant_time_compare(b"spam", b"spam"))
@@ -18,6 +22,15 @@ class TestUtilsCryptoMisc(SimpleTestCase):
self.assertTrue(constant_time_compare("spam", "spam"))
self.assertFalse(constant_time_compare("spam", "eggs"))
+ def test_constant_time_compare_deprecated(self):
+ msg = (
+ "constant_time_compare() is deprecated. "
+ "Use hmac.compare_digest() instead."
+ )
+ with self.assertWarnsMessage(RemovedInDjango70Warning, msg) as ctx:
+ constant_time_compare(b"spam", b"spam")
+ self.assertEqual(ctx.filename, __file__)
+
def test_salted_hmac(self):
tests = [
((b"salt", b"value"), {}, "b51a2e619c43b1ca4f91d15c57455521d71d61eb"),