From e096d56406b93220f03c495282fd6d0d297f3851 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sat, 11 Jun 2011 19:27:32 +0000 Subject: [PATCH] Fixed #16222: Test failures due to more precise cookie timings. Refs [16356]. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16376 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../formtools/wizard/tests/cookiestoragetests.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/django/contrib/formtools/wizard/tests/cookiestoragetests.py b/django/contrib/formtools/wizard/tests/cookiestoragetests.py index 74c7e822b4..6ad9bceae6 100644 --- a/django/contrib/formtools/wizard/tests/cookiestoragetests.py +++ b/django/contrib/formtools/wizard/tests/cookiestoragetests.py @@ -25,6 +25,7 @@ class TestCookieStorage(TestStorage, TestCase): self.assertRaises(SuspiciousOperation, storage.load_data) def test_reset_cookie(self): + from django.core.signing import SignatureExpired request = get_request() storage = self.get_storage()('wizard1', request, None) @@ -35,7 +36,15 @@ class TestCookieStorage(TestStorage, TestCase): cookie_signer = signing.get_cookie_signer(storage.prefix) signed_cookie_data = cookie_signer.sign(storage.encoder.encode(storage.data)) - self.assertEqual(response.cookies[storage.prefix].value, signed_cookie_data) + + # signing with different timestamps generates different signatures + self.assertNotEqual(response.cookies[storage.prefix].value, signed_cookie_data) + self.assertEqual(cookie_signer.unsign(response.cookies[storage.prefix].value), + cookie_signer.unsign(signed_cookie_data)) + self.assertRaises(SignatureExpired, + lambda: cookie_signer.unsign(value=response.cookies[storage.prefix].value, max_age=0)) + self.assertEqual(cookie_signer.unsign(value=response.cookies[storage.prefix].value, max_age=10), + cookie_signer.unsign(signed_cookie_data)) storage.init_data() storage.update_response(response)