summaryrefslogtreecommitdiff
path: root/tests/auth_tests/test_models.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auth_tests/test_models.py')
-rw-r--r--tests/auth_tests/test_models.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auth_tests/test_models.py b/tests/auth_tests/test_models.py
index 41f822fdc7..19454ade65 100644
--- a/tests/auth_tests/test_models.py
+++ b/tests/auth_tests/test_models.py
@@ -1,5 +1,7 @@
from unittest import mock
+from asgiref.sync import sync_to_async
+
from django.conf.global_settings import PASSWORD_HASHERS
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend
@@ -312,6 +314,29 @@ class AbstractUserTestCase(TestCase):
finally:
hasher.iterations = old_iterations
+ @override_settings(PASSWORD_HASHERS=PASSWORD_HASHERS)
+ async def test_acheck_password_upgrade(self):
+ user = await sync_to_async(User.objects.create_user)(
+ username="user", password="foo"
+ )
+ initial_password = user.password
+ self.assertIs(await user.acheck_password("foo"), True)
+ hasher = get_hasher("default")
+ self.assertEqual("pbkdf2_sha256", hasher.algorithm)
+
+ old_iterations = hasher.iterations
+ try:
+ # Upgrade the password iterations.
+ hasher.iterations = old_iterations + 1
+ with mock.patch(
+ "django.contrib.auth.password_validation.password_changed"
+ ) as pw_changed:
+ self.assertIs(await user.acheck_password("foo"), True)
+ self.assertEqual(pw_changed.call_count, 0)
+ self.assertNotEqual(initial_password, user.password)
+ finally:
+ hasher.iterations = old_iterations
+
class CustomModelBackend(ModelBackend):
def with_perm(