Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #15618 -- Fixed regression introduced in r15848 regarding not p…

…roperly 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
  • Loading branch information...
commit 7c738cd3e8f49a2e9ae951b6064aee5fc6fa3325 1 parent f5b22ed
Jannis Leidel jezdez authored
3  django/contrib/messages/storage/cookie.py
View
@@ -75,7 +75,8 @@ def _update_cookie(self, encoded_data, response):
response.set_cookie(self.cookie_name, encoded_data,
domain=settings.SESSION_COOKIE_DOMAIN)
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):
"""
35 django/contrib/messages/tests/cookie.py
View
@@ -4,6 +4,7 @@
MessageEncoder, MessageDecoder
from django.contrib.messages.storage.base import Message
from django.utils import simplejson as json
+from django.conf import settings
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):
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):
return stored_cookie_messages_count(storage, response)
@@ -51,6 +61,31 @@ def test_get(self):
# Test that the message actually contains what we expect.
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):
request = self.get_request()
storage = self.storage_class(request)
Please sign in to comment.
Something went wrong with that request. Please try again.