diff --git a/django/contrib/messages/storage/cookie.py b/django/contrib/messages/storage/cookie.py
index 2cc6fa6..45a20d0 100644
a
|
b
|
class CookieStorage(BaseStorage):
|
75 | 75 | response.set_cookie(self.cookie_name, encoded_data, |
76 | 76 | domain=settings.SESSION_COOKIE_DOMAIN) |
77 | 77 | else: |
78 | | response.delete_cookie(self.cookie_name) |
| 78 | response.delete_cookie(self.cookie_name, |
| 79 | domain=settings.SESSION_COOKIE_DOMAIN) |
79 | 80 | |
80 | 81 | def _store(self, messages, response, remove_oldest=True, *args, **kwargs): |
81 | 82 | """ |
diff --git a/django/contrib/messages/tests/cookie.py b/django/contrib/messages/tests/cookie.py
index d567175..c8ec558 100644
a
|
b
|
from django.contrib.messages.storage.cookie import CookieStorage, \
|
4 | 4 | MessageEncoder, MessageDecoder |
5 | 5 | from django.contrib.messages.storage.base import Message |
6 | 6 | from django.utils import simplejson as json |
| 7 | from django.conf import settings |
7 | 8 | |
8 | 9 | |
9 | 10 | def set_cookie_data(storage, messages, invalid=False, encode_empty=False): |
… |
… |
def stored_cookie_messages_count(storage, response):
|
39 | 40 | |
40 | 41 | class CookieTest(BaseTest): |
41 | 42 | storage_class = CookieStorage |
| 43 | |
| 44 | def setUp(self): |
| 45 | super(CookieTest, self).setUp() |
| 46 | self.old_SESSION_COOKIE_DOMAIN = settings.SESSION_COOKIE_DOMAIN |
| 47 | settings.SESSION_COOKIE_DOMAIN = '.lawrence.com' |
| 48 | |
| 49 | def tearDown(self): |
| 50 | super(CookieTest, self).tearDown() |
| 51 | settings.SESSION_COOKIE_DOMAIN = self.old_SESSION_COOKIE_DOMAIN |
42 | 52 | |
43 | 53 | def stored_messages_count(self, storage, response): |
44 | 54 | return stored_cookie_messages_count(storage, response) |
… |
… |
class CookieTest(BaseTest):
|
50 | 60 | set_cookie_data(storage, example_messages) |
51 | 61 | # Test that the message actually contains what we expect. |
52 | 62 | self.assertEqual(list(storage), example_messages) |
53 | | |
| 63 | |
| 64 | def test_domain(self): |
| 65 | """ |
| 66 | Ensure that CookieStorage honors SESSION_COOKIE_DOMAIN. |
| 67 | Refs #15618. |
| 68 | """ |
| 69 | # Test before the messages have been consumed |
| 70 | storage = self.get_storage() |
| 71 | response = self.get_response() |
| 72 | storage.add(constants.INFO, 'test') |
| 73 | storage.update(response) |
| 74 | self.assertTrue('test' in response.cookies['messages'].value) |
| 75 | self.assertEqual(response.cookies['messages']['domain'], '.lawrence.com') |
| 76 | self.assertEqual(response.cookies['messages']['expires'], '') |
| 77 | |
| 78 | # Test after the messages have been consumed |
| 79 | storage = self.get_storage() |
| 80 | response = self.get_response() |
| 81 | storage.add(constants.INFO, 'test') |
| 82 | for m in storage: |
| 83 | pass # Iterate through the storage to simulate consumption of messages. |
| 84 | storage.update(response) |
| 85 | self.assertEqual(response.cookies['messages'].value, '') |
| 86 | self.assertEqual(response.cookies['messages']['domain'], '.lawrence.com') |
| 87 | self.assertEqual(response.cookies['messages']['expires'], 'Thu, 01-Jan-1970 00:00:00 GMT') |
| 88 | |
54 | 89 | def test_get_bad_cookie(self): |
55 | 90 | request = self.get_request() |
56 | 91 | storage = self.storage_class(request) |