From 19b609155479f967a41ffc20a58bb09229f1e64b Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Wed, 22 Sep 2021 10:06:10 +0200 Subject: [PATCH] Adjusted authentication test for internal CSRF changes. Private _get_new_csrf_token() was removed in https://github.com/django/django/commit/231de683d86374c2b74da2185efc6ddfb5eb3341. --- tests/authentication/test_authentication.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/authentication/test_authentication.py b/tests/authentication/test_authentication.py index a73e0d79c..d771aaf8b 100644 --- a/tests/authentication/test_authentication.py +++ b/tests/authentication/test_authentication.py @@ -1,5 +1,6 @@ import base64 +import django import pytest from django.conf import settings from django.contrib.auth.models import User @@ -218,7 +219,16 @@ class SessionAuthTests(TestCase): Ensure POSTing form over session authentication with CSRF token succeeds. Regression test for #6088 """ - from django.middleware.csrf import _get_new_csrf_token + # Remove this shim when dropping support for Django 2.2. + if django.VERSION < (3, 0): + from django.middleware.csrf import _get_new_csrf_token + else: + from django.middleware.csrf import ( + _get_new_csrf_string, _mask_cipher_secret + ) + + def _get_new_csrf_token(): + return _mask_cipher_secret(_get_new_csrf_string()) self.csrf_client.login(username=self.username, password=self.password)