summaryrefslogtreecommitdiff
path: root/tests/auth_tests/test_views.py
diff options
context:
space:
mode:
authorJay Cox <jaycox@linear3d.com>2015-04-23 23:24:38 -0700
committerTim Graham <timograham@gmail.com>2015-05-02 19:45:14 -0400
commiteef95ea96faef0b7dbbe0c8092202b74f68a899b (patch)
treefb8888a4aa7328b148f0e2b3c87590639d34c81c /tests/auth_tests/test_views.py
parent0894643e40327e48397573b7844585618200442b (diff)
Fixed #24696 -- Made CSRF_COOKIE computation lazy.
Only compute the CSRF_COOKIE when it is actually used. This is a significant speedup for clients not using cookies. Changed result of the “test_token_node_no_csrf_cookie” test: It gets a valid CSRF token now which seems like the correct behavior. Changed auth_tests.test_views.LoginTest.test_login_csrf_rotate to use get_token() to trigger CSRF cookie inclusion instead of changing request.META["CSRF_COOKIE_USED"] directly.
Diffstat (limited to 'tests/auth_tests/test_views.py')
-rw-r--r--tests/auth_tests/test_views.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py
index 5ebe9f2938..033d083e18 100644
--- a/tests/auth_tests/test_views.py
+++ b/tests/auth_tests/test_views.py
@@ -23,7 +23,7 @@ from django.core import mail
from django.core.urlresolvers import NoReverseMatch, reverse, reverse_lazy
from django.db import connection
from django.http import HttpRequest, QueryDict
-from django.middleware.csrf import CsrfViewMiddleware
+from django.middleware.csrf import CsrfViewMiddleware, get_token
from django.test import (
TestCase, ignore_warnings, modify_settings, override_settings,
)
@@ -606,7 +606,8 @@ class LoginTest(AuthViewsTestCase):
# TestClient isn't used here as we're testing middleware, essentially.
req = HttpRequest()
CsrfViewMiddleware().process_view(req, login_view, (), {})
- req.META["CSRF_COOKIE_USED"] = True
+ # get_token() triggers CSRF token inclusion in the response
+ get_token(req)
resp = login_view(req)
resp2 = CsrfViewMiddleware().process_response(req, resp)
csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None)