1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #32843 -- Ensured the CSRF tests' _get_GET_csrf_cookie_request() sets the request method.

This commit is contained in:
Chris Jerdonek 2021-06-23 09:53:28 -04:00 committed by Mariusz Felisiak
parent 7ba9da815d
commit 4397d2bd6b

View File

@ -90,11 +90,14 @@ class CsrfViewMiddlewareTestMixin:
_csrf_id_cookie = MASKED_TEST_SECRET1
_csrf_id_token = MASKED_TEST_SECRET2
def _get_GET_no_csrf_cookie_request(self):
def _get_request(self):
req = TestingHttpRequest()
req.method = 'GET'
return req
def _get_GET_no_csrf_cookie_request(self):
return self._get_request()
def _get_GET_csrf_cookie_request(self, cookie=None):
raise NotImplementedError('This method must be implemented by a subclass.')
@ -859,7 +862,7 @@ class CsrfViewMiddlewareTests(CsrfViewMiddlewareTestMixin, SimpleTestCase):
"""The cookie argument defaults to the valid test cookie."""
if cookie is None:
cookie = self._csrf_id_cookie
req = TestingHttpRequest()
req = self._get_request()
req.COOKIES[settings.CSRF_COOKIE_NAME] = cookie
return req
@ -1069,7 +1072,7 @@ class CsrfViewMiddlewareUseSessionsTests(CsrfViewMiddlewareTestMixin, SimpleTest
"""The cookie argument defaults to the valid test cookie."""
if cookie is None:
cookie = self._csrf_id_cookie
req = TestingHttpRequest()
req = self._get_request()
req.session[CSRF_SESSION_KEY] = cookie
return req