mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #30556 -- Avoided useless query and hasher call in ModelBackend.authenticate() when credentials aren't provided.
There's no need to fetch a user instance from the database unless a username and a password are provided as credentials.
This commit is contained in:
committed by
Mariusz Felisiak
parent
e065b29387
commit
3ee0834a46
@@ -226,6 +226,19 @@ class BaseModelBackendTest:
|
||||
authenticate(username='no_such_user', password='test')
|
||||
self.assertEqual(CountingMD5PasswordHasher.calls, 1)
|
||||
|
||||
@override_settings(PASSWORD_HASHERS=['auth_tests.test_auth_backends.CountingMD5PasswordHasher'])
|
||||
def test_authentication_without_credentials(self):
|
||||
CountingMD5PasswordHasher.calls = 0
|
||||
for credentials in (
|
||||
{},
|
||||
{'username': getattr(self.user, self.UserModel.USERNAME_FIELD)},
|
||||
{'password': 'test'},
|
||||
):
|
||||
with self.subTest(credentials=credentials):
|
||||
with self.assertNumQueries(0):
|
||||
authenticate(**credentials)
|
||||
self.assertEqual(CountingMD5PasswordHasher.calls, 0)
|
||||
|
||||
|
||||
class ModelBackendTest(BaseModelBackendTest, TestCase):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user