Fixed #15618 -- Fixed regression introduced in r15848 regarding not properly deleting messages cookies when honoring SESSION_COOKIE_DOMAIN. Thanks, Julien.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15885 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f5b22ed997
commit
7c738cd3e8
|
@ -75,7 +75,8 @@ class CookieStorage(BaseStorage):
|
||||||
response.set_cookie(self.cookie_name, encoded_data,
|
response.set_cookie(self.cookie_name, encoded_data,
|
||||||
domain=settings.SESSION_COOKIE_DOMAIN)
|
domain=settings.SESSION_COOKIE_DOMAIN)
|
||||||
else:
|
else:
|
||||||
response.delete_cookie(self.cookie_name)
|
response.delete_cookie(self.cookie_name,
|
||||||
|
domain=settings.SESSION_COOKIE_DOMAIN)
|
||||||
|
|
||||||
def _store(self, messages, response, remove_oldest=True, *args, **kwargs):
|
def _store(self, messages, response, remove_oldest=True, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django.contrib.messages.storage.cookie import CookieStorage, \
|
||||||
MessageEncoder, MessageDecoder
|
MessageEncoder, MessageDecoder
|
||||||
from django.contrib.messages.storage.base import Message
|
from django.contrib.messages.storage.base import Message
|
||||||
from django.utils import simplejson as json
|
from django.utils import simplejson as json
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
def set_cookie_data(storage, messages, invalid=False, encode_empty=False):
|
def set_cookie_data(storage, messages, invalid=False, encode_empty=False):
|
||||||
|
@ -40,6 +41,15 @@ def stored_cookie_messages_count(storage, response):
|
||||||
class CookieTest(BaseTest):
|
class CookieTest(BaseTest):
|
||||||
storage_class = CookieStorage
|
storage_class = CookieStorage
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(CookieTest, self).setUp()
|
||||||
|
self.old_SESSION_COOKIE_DOMAIN = settings.SESSION_COOKIE_DOMAIN
|
||||||
|
settings.SESSION_COOKIE_DOMAIN = '.lawrence.com'
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super(CookieTest, self).tearDown()
|
||||||
|
settings.SESSION_COOKIE_DOMAIN = self.old_SESSION_COOKIE_DOMAIN
|
||||||
|
|
||||||
def stored_messages_count(self, storage, response):
|
def stored_messages_count(self, storage, response):
|
||||||
return stored_cookie_messages_count(storage, response)
|
return stored_cookie_messages_count(storage, response)
|
||||||
|
|
||||||
|
@ -51,6 +61,31 @@ class CookieTest(BaseTest):
|
||||||
# Test that the message actually contains what we expect.
|
# Test that the message actually contains what we expect.
|
||||||
self.assertEqual(list(storage), example_messages)
|
self.assertEqual(list(storage), example_messages)
|
||||||
|
|
||||||
|
def test_domain(self):
|
||||||
|
"""
|
||||||
|
Ensure that CookieStorage honors SESSION_COOKIE_DOMAIN.
|
||||||
|
Refs #15618.
|
||||||
|
"""
|
||||||
|
# Test before the messages have been consumed
|
||||||
|
storage = self.get_storage()
|
||||||
|
response = self.get_response()
|
||||||
|
storage.add(constants.INFO, 'test')
|
||||||
|
storage.update(response)
|
||||||
|
self.assertTrue('test' in response.cookies['messages'].value)
|
||||||
|
self.assertEqual(response.cookies['messages']['domain'], '.lawrence.com')
|
||||||
|
self.assertEqual(response.cookies['messages']['expires'], '')
|
||||||
|
|
||||||
|
# Test after the messages have been consumed
|
||||||
|
storage = self.get_storage()
|
||||||
|
response = self.get_response()
|
||||||
|
storage.add(constants.INFO, 'test')
|
||||||
|
for m in storage:
|
||||||
|
pass # Iterate through the storage to simulate consumption of messages.
|
||||||
|
storage.update(response)
|
||||||
|
self.assertEqual(response.cookies['messages'].value, '')
|
||||||
|
self.assertEqual(response.cookies['messages']['domain'], '.lawrence.com')
|
||||||
|
self.assertEqual(response.cookies['messages']['expires'], 'Thu, 01-Jan-1970 00:00:00 GMT')
|
||||||
|
|
||||||
def test_get_bad_cookie(self):
|
def test_get_bad_cookie(self):
|
||||||
request = self.get_request()
|
request = self.get_request()
|
||||||
storage = self.storage_class(request)
|
storage = self.storage_class(request)
|
||||||
|
|
Loading…
Reference in New Issue