From 4397d2bd6be1e0eb264b3807f8ae8c0d3cbc116e Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Wed, 23 Jun 2021 09:53:28 -0400 Subject: [PATCH] Fixed #32843 -- Ensured the CSRF tests' _get_GET_csrf_cookie_request() sets the request method. --- tests/csrf_tests/tests.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/csrf_tests/tests.py b/tests/csrf_tests/tests.py index b6e94a7717..f3ee9cdedd 100644 --- a/tests/csrf_tests/tests.py +++ b/tests/csrf_tests/tests.py @@ -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