diff options
author | Florian Apolloner <florian@apolloner.eu> | 2021-04-14 13:45:24 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-04-15 07:58:48 +0200 |
commit | 539d005aa5fb496f0a648a2385465eca06c604e9 (patch) | |
tree | d2fdd48674a32cca0117bdc075752d94836daa33 /tests | |
parent | 208e72276a3e12a4e7998b9a1219bc96a16cf7b8 (diff) | |
download | django-539d005aa5fb496f0a648a2385465eca06c604e9.tar.gz |
[3.2.x] Fixed #32643 -- Fixed decoding of messages in the pre-Django 3.2 format.
Thanks Jan Pieter Waagmeester for the report.
Regression in 2d6179c819010f6a9d00835d5893c4593c0b85a0.
Backport of 4511d1459810037b91faa5b506e4f75c77aa72be from main.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/messages_tests/test_cookie.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/tests/messages_tests/test_cookie.py b/tests/messages_tests/test_cookie.py index 9f82ce93e9..e62ab664fd 100644 --- a/tests/messages_tests/test_cookie.py +++ b/tests/messages_tests/test_cookie.py @@ -1,3 +1,4 @@ +import binascii import json import random @@ -7,7 +8,7 @@ from django.contrib.messages.storage.base import Message from django.contrib.messages.storage.cookie import ( CookieStorage, MessageDecoder, MessageEncoder, ) -from django.core.signing import get_cookie_signer +from django.core.signing import b64_decode, get_cookie_signer from django.test import SimpleTestCase, override_settings from django.test.utils import ignore_warnings from django.utils.crypto import get_random_string @@ -196,10 +197,12 @@ class CookieTests(BaseTests, SimpleTestCase): # RemovedInDjango41Warning: pre-Django 3.2 encoded messages will be # invalid. storage = self.storage_class(self.get_request()) - messages = ['this', 'that'] + messages = ['this', Message(0, 'Successfully signed in as admin@example.org')] # Encode/decode a message using the pre-Django 3.2 format. encoder = MessageEncoder() value = encoder.encode(messages) + with self.assertRaises(binascii.Error): + b64_decode(value.encode()) signer = get_cookie_signer(salt=storage.key_salt) encoded_messages = signer.sign(value) decoded_messages = storage._decode(encoded_messages) |