mirror of
https://github.com/django/django.git
synced 2025-11-20 11:36:04 +00:00
Fixed #36572 -- Revert "Fixed #36546 -- Deprecated django.utils.crypto.constant_time_compare() in favor of hmac.compare_digest()."
Some checks are pending
Docs / spelling (push) Waiting to run
Docs / blacken-docs (push) Waiting to run
Docs / lint-docs (push) Waiting to run
Linters / flake8 (push) Waiting to run
Linters / isort (push) Waiting to run
Linters / black (push) Waiting to run
Tests / Windows, SQLite, Python 3.13 (push) Waiting to run
Tests / JavaScript tests (push) Waiting to run
Some checks are pending
Docs / spelling (push) Waiting to run
Docs / blacken-docs (push) Waiting to run
Docs / lint-docs (push) Waiting to run
Linters / flake8 (push) Waiting to run
Linters / isort (push) Waiting to run
Linters / black (push) Waiting to run
Tests / Windows, SQLite, Python 3.13 (push) Waiting to run
Tests / JavaScript tests (push) Waiting to run
This reverts commit 0246f47888.
This commit is contained in:
parent
c594574175
commit
d0e4dd5cdd
9 changed files with 28 additions and 48 deletions
|
|
@ -2,34 +2,25 @@ 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"))
|
||||
self.assertFalse(constant_time_compare(b"spam", b"eggs"))
|
||||
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__)
|
||||
self.assertTrue(constant_time_compare(b"spam", "spam"))
|
||||
self.assertFalse(constant_time_compare("spam", b"eggs"))
|
||||
self.assertTrue(constant_time_compare("ありがとう", "ありがとう"))
|
||||
self.assertFalse(constant_time_compare("ありがとう", "おはよう"))
|
||||
|
||||
def test_salted_hmac(self):
|
||||
tests = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue