mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #32191 -- Added Signer.sign_object()/unsign_object().
Co-authored-by: Craig Smith <hello@craigiansmith.com.au>
This commit is contained in:
committed by
Mariusz Felisiak
parent
5bcba16c01
commit
102d92fc09
@@ -122,6 +122,22 @@ class TestSigner(SimpleTestCase):
|
||||
with self.assertRaises(signing.BadSignature):
|
||||
signer.unsign(transform(signed_value))
|
||||
|
||||
def test_sign_unsign_object(self):
|
||||
signer = signing.Signer('predictable-secret')
|
||||
tests = [
|
||||
['a', 'list'],
|
||||
'a string \u2019',
|
||||
{'a': 'dictionary'},
|
||||
]
|
||||
for obj in tests:
|
||||
with self.subTest(obj=obj):
|
||||
signed_obj = signer.sign_object(obj)
|
||||
self.assertNotEqual(obj, signed_obj)
|
||||
self.assertEqual(obj, signer.unsign_object(signed_obj))
|
||||
signed_obj = signer.sign_object(obj, compress=True)
|
||||
self.assertNotEqual(obj, signed_obj)
|
||||
self.assertEqual(obj, signer.unsign_object(signed_obj))
|
||||
|
||||
def test_dumps_loads(self):
|
||||
"dumps and loads be reversible for any JSON serializable object"
|
||||
objects = [
|
||||
|
||||
Reference in New Issue
Block a user