Skip to content

Commit 9822649

Browse files
committed
fixup! Adjusted authentication test for internal CSRF changes.
1 parent 4b8775b commit 9822649

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tests/authentication/test_authentication.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import base64
22

33
import pytest
4+
import django
45
from django.conf import settings
56
from django.contrib.auth.models import User
67
from django.http import HttpResponse
@@ -218,13 +219,21 @@ def test_post_form_session_auth_passing_csrf(self):
218219
Ensure POSTing form over session authentication with CSRF token succeeds.
219220
Regression test for #6088
220221
"""
221-
from django.middleware.csrf import (
222-
_get_new_csrf_string, _mask_cipher_secret
223-
)
222+
# Remove this shim when dropping support for Django 2.2.
223+
if django.VERSION < (3, 0):
224+
from django.middleware.csrf import _get_new_csrf_token
225+
else:
226+
from django.middleware.csrf import (
227+
_get_new_csrf_string, _mask_cipher_secret
228+
)
229+
230+
def _get_new_csrf_token():
231+
return _mask_cipher_secret(_get_new_csrf_string())
232+
224233
self.csrf_client.login(username=self.username, password=self.password)
225234

226235
# Set the csrf_token cookie so that CsrfViewMiddleware._get_token() works
227-
token = _mask_cipher_secret(_get_new_csrf_string())
236+
token = _get_new_csrf_token()
228237
self.csrf_client.cookies[settings.CSRF_COOKIE_NAME] = token
229238

230239
# Post the token matching the cookie value

0 commit comments

Comments
 (0)