mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Refs #32800 -- Eliminated the need for separate _get_POST_bare_secret() methods.
This commit is contained in:
parent
c8108591b9
commit
2523c32d50
@ -123,9 +123,9 @@ class CsrfViewMiddlewareTestMixin:
|
|||||||
req.method = "POST"
|
req.method = "POST"
|
||||||
return req
|
return req
|
||||||
|
|
||||||
def _get_POST_request_with_token(self):
|
def _get_POST_request_with_token(self, cookie=None):
|
||||||
req = self._get_POST_csrf_cookie_request(post_token=self._csrf_id)
|
"""The cookie argument defaults to this class's default test cookie."""
|
||||||
return req
|
return self._get_POST_csrf_cookie_request(cookie=cookie, post_token=self._csrf_id)
|
||||||
|
|
||||||
def _check_token_present(self, response, csrf_id=None):
|
def _check_token_present(self, response, csrf_id=None):
|
||||||
text = str(response.content, response.charset)
|
text = str(response.content, response.charset)
|
||||||
@ -863,16 +863,6 @@ class CsrfViewMiddlewareTests(CsrfViewMiddlewareTestMixin, SimpleTestCase):
|
|||||||
req.COOKIES[settings.CSRF_COOKIE_NAME] = cookie
|
req.COOKIES[settings.CSRF_COOKIE_NAME] = cookie
|
||||||
return req
|
return req
|
||||||
|
|
||||||
def _get_POST_bare_secret_csrf_cookie_request(self):
|
|
||||||
req = self._get_POST_no_csrf_cookie_request()
|
|
||||||
req.COOKIES[settings.CSRF_COOKIE_NAME] = TEST_SECRET
|
|
||||||
return req
|
|
||||||
|
|
||||||
def _get_POST_bare_secret_csrf_cookie_request_with_token(self):
|
|
||||||
req = self._get_POST_bare_secret_csrf_cookie_request()
|
|
||||||
req.POST['csrfmiddlewaretoken'] = self._csrf_id
|
|
||||||
return req
|
|
||||||
|
|
||||||
def test_ensures_csrf_cookie_no_middleware(self):
|
def test_ensures_csrf_cookie_no_middleware(self):
|
||||||
"""
|
"""
|
||||||
The ensure_csrf_cookie() decorator works without middleware.
|
The ensure_csrf_cookie() decorator works without middleware.
|
||||||
@ -989,7 +979,7 @@ class CsrfViewMiddlewareTests(CsrfViewMiddlewareTestMixin, SimpleTestCase):
|
|||||||
"""
|
"""
|
||||||
The csrf token is reset from a bare secret.
|
The csrf token is reset from a bare secret.
|
||||||
"""
|
"""
|
||||||
req = self._get_POST_bare_secret_csrf_cookie_request_with_token()
|
req = self._get_POST_request_with_token(cookie=TEST_SECRET)
|
||||||
mw = CsrfViewMiddleware(token_view)
|
mw = CsrfViewMiddleware(token_view)
|
||||||
mw.process_request(req)
|
mw.process_request(req)
|
||||||
resp = mw.process_view(req, token_view, (), {})
|
resp = mw.process_view(req, token_view, (), {})
|
||||||
@ -1048,11 +1038,6 @@ class CsrfViewMiddlewareUseSessionsTests(CsrfViewMiddlewareTestMixin, SimpleTest
|
|||||||
CSRF tests with CSRF_USE_SESSIONS=True.
|
CSRF tests with CSRF_USE_SESSIONS=True.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _get_POST_bare_secret_csrf_cookie_request(self):
|
|
||||||
req = self._get_POST_no_csrf_cookie_request()
|
|
||||||
req.session[CSRF_SESSION_KEY] = TEST_SECRET
|
|
||||||
return req
|
|
||||||
|
|
||||||
def _get_GET_csrf_cookie_request(self, cookie=None):
|
def _get_GET_csrf_cookie_request(self, cookie=None):
|
||||||
"""The cookie argument defaults to the valid test cookie."""
|
"""The cookie argument defaults to the valid test cookie."""
|
||||||
if cookie is None:
|
if cookie is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user