summaryrefslogtreecommitdiff
path: root/tests/signing
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-07-31 20:56:33 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-08-04 09:35:24 +0200
commitd907371ef99a1e4ca6bc1660f57d81f265750984 (patch)
treec71660e797eba97a3a6a6fa48ebc3f1bfa64441b /tests/signing
parentbce4a53670668d6fd1e34685197151c17fd1b378 (diff)
downloaddjango-d907371ef99a1e4ca6bc1660f57d81f265750984.tar.gz
Fixed #31842 -- Added DEFAULT_HASHING_ALGORITHM transitional setting.
It's a transitional setting helpful in migrating multiple instance of the same project to Django 3.1+. Thanks Markus Holtermann for the report and review, Florian Apolloner for the implementation idea and review, and Carlton Gibson for the review.
Diffstat (limited to 'tests/signing')
-rw-r--r--tests/signing/tests.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/signing/tests.py b/tests/signing/tests.py
index df7cad9747..835ca4d6b2 100644
--- a/tests/signing/tests.py
+++ b/tests/signing/tests.py
@@ -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 = (