summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBo Lopker <blopker@23andme.com>2015-05-13 23:22:42 -0700
committerTim Graham <timograham@gmail.com>2015-05-15 11:24:18 -0400
commit3c659856eb9d5a45e02213f1e8f9fcbb03bd12cf (patch)
tree9398a838ae6d54f4e70b13b44ea20fb1645d5744 /tests
parent6a0d9f068f9986c8c05e689e67be7bc22c59efc6 (diff)
[1.8.x] Fixed #24799 -- Fixed session cookie deletion when using SESSION_COOKIE_DOMAIN
Backport of 2dee853ed4def42b7ef1b3b472b395055543cc00 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/sessions_tests/tests.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/sessions_tests/tests.py b/tests/sessions_tests/tests.py
index f6c5933da4..d9e6817976 100644
--- a/tests/sessions_tests/tests.py
+++ b/tests/sessions_tests/tests.py
@@ -610,6 +610,35 @@ class SessionMiddlewareTests(TestCase):
str(response.cookies[settings.SESSION_COOKIE_NAME])
)
+ @override_settings(SESSION_COOKIE_DOMAIN='.example.local')
+ def test_session_delete_on_end_with_custom_domain(self):
+ request = RequestFactory().get('/')
+ response = HttpResponse('Session test')
+ middleware = SessionMiddleware()
+
+ # Before deleting, there has to be an existing cookie
+ request.COOKIES[settings.SESSION_COOKIE_NAME] = 'abc'
+
+ # Simulate a request that ends the session
+ middleware.process_request(request)
+ request.session.flush()
+
+ # Handle the response through the middleware
+ response = middleware.process_response(request, response)
+
+ # Check that the cookie was deleted, not recreated.
+ # A deleted cookie header with a custom domain looks like:
+ # Set-Cookie: sessionid=; Domain=.example.local;
+ # expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
+ self.assertEqual(
+ 'Set-Cookie: {}={}; Domain=.example.local; expires=Thu, '
+ '01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/'.format(
+ settings.SESSION_COOKIE_NAME,
+ '""' if sys.version_info >= (3, 5) else '',
+ ),
+ str(response.cookies[settings.SESSION_COOKIE_NAME])
+ )
+
# Don't need DB flushing for these tests, so can use unittest.TestCase as base class
class CookieSessionTests(SessionTestsMixin, unittest.TestCase):