diff options
| author | Anton Samarchyan <anton.samarchyan@savoirfairelinux.com> | 2016-11-30 13:37:07 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-01 09:50:08 -0500 |
| commit | 47744a0a4ed0b9e2d3f52de65abcf6cef9a14e31 (patch) | |
| tree | 2b07e1033b36b234d7be0f3bb623ce2dc3dffa10 /tests/test_client | |
| parent | e690eb405f09a9e58b9d95ae98991352602635d6 (diff) | |
Fixed #27542 -- Made Client.force_login() skip auth backends without get_user().
Diffstat (limited to 'tests/test_client')
| -rw-r--r-- | tests/test_client/auth_backends.py | 4 | ||||
| -rw-r--r-- | tests/test_client/tests.py | 11 |
2 files changed, 15 insertions, 0 deletions
diff --git a/tests/test_client/auth_backends.py b/tests/test_client/auth_backends.py index c886dce336..1bb1d96eeb 100644 --- a/tests/test_client/auth_backends.py +++ b/tests/test_client/auth_backends.py @@ -3,3 +3,7 @@ from django.contrib.auth.backends import ModelBackend class TestClientBackend(ModelBackend): pass + + +class BackendWithoutGetUserMethod(object): + pass diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py index d3eb782347..a499ee7fce 100644 --- a/tests/test_client/tests.py +++ b/tests/test_client/tests.py @@ -549,6 +549,17 @@ class ClientTest(TestCase): self.assertEqual(response.context['user'].username, 'testclient') self.assertEqual(self.u1.backend, 'django.contrib.auth.backends.ModelBackend') + @override_settings(AUTHENTICATION_BACKENDS=[ + 'test_client.auth_backends.BackendWithoutGetUserMethod', + 'django.contrib.auth.backends.ModelBackend', + ]) + def test_force_login_with_backend_missing_get_user(self): + """ + force_login() skips auth backends without a get_user() method. + """ + self.client.force_login(self.u1) + self.assertEqual(self.u1.backend, 'django.contrib.auth.backends.ModelBackend') + @override_settings(SESSION_ENGINE="django.contrib.sessions.backends.signed_cookies") def test_logout_cookie_sessions(self): self.test_logout() |
