mirror of
https://github.com/django/django.git
synced 2025-10-27 23:56:08 +00:00
Fixed #22804 -- Added warning for unsafe value of 'sep' in Signer
Thanks Jaap Roes for completing the patch.
This commit is contained in:
committed by
Tim Graham
parent
6bd8462380
commit
0d71349773
@@ -1,6 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
import warnings
|
||||
|
||||
from django.core import signing
|
||||
from django.test import SimpleTestCase
|
||||
@@ -112,6 +113,23 @@ class TestSigner(SimpleTestCase):
|
||||
s = signing.Signer(binary_key)
|
||||
self.assertEqual('foo:6NB0fssLW5RQvZ3Y-MTerq2rX7w', s.sign('foo'))
|
||||
|
||||
def test_valid_sep(self):
|
||||
separators = ['/', '*sep*', ',']
|
||||
for sep in separators:
|
||||
signer = signing.Signer('predictable-secret', sep=sep)
|
||||
self.assertEqual('foo%ssH9B01cZcJ9FoT_jEVkRkNULrl8' % sep, signer.sign('foo'))
|
||||
|
||||
def test_invalid_sep(self):
|
||||
"""should warn on invalid separator"""
|
||||
separators = ['', '-', 'abc']
|
||||
for sep in separators:
|
||||
with warnings.catch_warnings(record=True) as recorded:
|
||||
warnings.simplefilter('always')
|
||||
signing.Signer(sep=sep)
|
||||
self.assertEqual(len(recorded), 1)
|
||||
msg = str(recorded[0].message)
|
||||
self.assertTrue(msg.startswith('Unsafe Signer separator'))
|
||||
|
||||
|
||||
class TestTimestampSigner(SimpleTestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user