|
@@ -2,8 +2,9 @@ import datetime
|
|
|
|
|
|
from django.core import signing
|
|
|
from django.test import SimpleTestCase
|
|
|
-from django.test.utils import freeze_time
|
|
|
+from django.test.utils import freeze_time, ignore_warnings
|
|
|
from django.utils.crypto import InvalidAlgorithm
|
|
|
+from django.utils.deprecation import RemovedInDjango40Warning
|
|
|
|
|
|
|
|
|
class TestSigner(SimpleTestCase):
|
|
@@ -52,6 +53,14 @@ class TestSigner(SimpleTestCase):
|
|
|
'VzO9_jVu7R-VkqknHYNvw',
|
|
|
)
|
|
|
|
|
|
+ @ignore_warnings(category=RemovedInDjango40Warning)
|
|
|
+ def test_default_hashing_algorithm(self):
|
|
|
+ signer = signing.Signer('predictable-secret', algorithm='sha1')
|
|
|
+ signature_sha1 = signer.signature('hello')
|
|
|
+ with self.settings(DEFAULT_HASHING_ALGORITHM='sha1'):
|
|
|
+ signer = signing.Signer('predictable-secret')
|
|
|
+ self.assertEqual(signer.signature('hello'), signature_sha1)
|
|
|
+
|
|
|
def test_invalid_algorithm(self):
|
|
|
signer = signing.Signer('predictable-secret', algorithm='whatever')
|
|
|
msg = "'whatever' is not an algorithm accepted by the hashlib module."
|
|
@@ -134,6 +143,13 @@ class TestSigner(SimpleTestCase):
|
|
|
signed = 'ImEgc3RyaW5nIFx1MjAyMCI:1k1beT:ZfNhN1kdws7KosUleOvuYroPHEc'
|
|
|
self.assertEqual(signing.loads(signed), value)
|
|
|
|
|
|
+ @ignore_warnings(category=RemovedInDjango40Warning)
|
|
|
+ def test_dumps_loads_default_hashing_algorithm_sha1(self):
|
|
|
+ value = 'a string \u2020'
|
|
|
+ with self.settings(DEFAULT_HASHING_ALGORITHM='sha1'):
|
|
|
+ signed = signing.dumps(value)
|
|
|
+ self.assertEqual(signing.loads(signed), value)
|
|
|
+
|
|
|
def test_decode_detects_tampering(self):
|
|
|
"loads should raise exception for tampered objects"
|
|
|
transforms = (
|