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:23:41 -0400
commit2dee853ed4def42b7ef1b3b472b395055543cc00 (patch)
tree6c33b2e26bac9aff0ca4375313404823080a0493 /tests
parentae635cc365581889454d2b3c278b3e3a38bd7809 (diff)
Fixed #24799 -- Fixed session cookie deletion when using SESSION_COOKIE_DOMAIN
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 62804e4dc0..1420199698 100644
--- a/tests/sessions_tests/tests.py
+++ b/tests/sessions_tests/tests.py
@@ -613,6 +613,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):