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
1 changed files with 6 additions and 3 deletions

View File

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