From 7f66c3b41f0fb0fb938d7b96e20a28dccdaa2ecd Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Mon, 4 May 2026 16:26:26 -0400 Subject: Refs #36439 -- Added sync_to_async() to dummy password hasher path. Since the existing user path eventually calls sync_to_async() in acheck_password, aim for parity with the nonexistent/inactive user branch by adding sync_to_async(). Follow-up to 748ca0a146175c4868ece87f5e845a75416c30e3. --- tests/auth_tests/test_auth_backends.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py index 77eeed3d60..40d686dfc5 100644 --- a/tests/auth_tests/test_auth_backends.py +++ b/tests/auth_tests/test_auth_backends.py @@ -498,6 +498,22 @@ class BaseModelBackendTest: await aauthenticate(username="no_such_user", password="test") self.assertEqual(CountingMD5PasswordHasher.calls, 1) + async def test_aauthentication_timing_async_bridge(self): + with patch( + "django.contrib.auth.hashers.sync_to_async", + return_value=mock.AsyncMock(return_value=(True, False)), + ) as mocked_adapter: + username = getattr(self.user, self.UserModel.USERNAME_FIELD) + await aauthenticate(username=username, password="test") + mocked_adapter.assert_called_once() + + with patch( + "django.contrib.auth.sync_to_async", return_value=mock.AsyncMock() + ) as mocked_adapter: + username = getattr(self.user, self.UserModel.USERNAME_FIELD) + await aauthenticate(username="no_such_user", password="test") + mocked_adapter.assert_called_once() + @override_settings( PASSWORD_HASHERS=["auth_tests.test_auth_backends.CountingMD5PasswordHasher"] ) -- cgit v1.3