Skip to content

Commit

Permalink
Rename DEFAULT_LOGIN_AUTHENTICATION_BACKEND to LOGIN_DEFAULT_SESSION_…
Browse files Browse the repository at this point in the history
…AUTHENTICATION_BACKEND
  • Loading branch information
apragacz committed Nov 29, 2021
1 parent 3ef10a6 commit 2879374
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rest_registration/settings_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ def __new__(
""")
),
Field(
'DEFAULT_LOGIN_AUTHENTICATION_BACKEND',
'LOGIN_DEFAULT_SESSION_AUTHENTICATION_BACKEND',
default='django.contrib.auth.backends.ModelBackend',
help=dedent("""\
This setting allows to override the backend used in the login function.
It may be useful if Django ``AUTHENTICATION_BACKENDS`` setting
does not contain ``django.contrib.auth.backends.ModelBackend``.
does contain multiple values.
The value must be a dotted import path string.
"""),
Expand Down
5 changes: 3 additions & 2 deletions rest_registration/utils/auth_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

def get_login_authentication_backend() -> str:
backends = settings.AUTHENTICATION_BACKENDS
default_login_backend = registration_settings.DEFAULT_LOGIN_AUTHENTICATION_BACKEND
default_login_backend = registration_settings.LOGIN_DEFAULT_SESSION_AUTHENTICATION_BACKEND # noqa: E501
if not backends:
raise ImproperlyConfigured("No AUTHENTICATION_BACKENDS specified")
if len(backends) == 1:
return backends[0]
if default_login_backend not in backends:
raise ImproperlyConfigured(
"DEFAULT_LOGIN_AUTHENTICATION_BACKEND is not in AUTHENTICATION_BACKENDS")
"LOGIN_DEFAULT_SESSION_AUTHENTICATION_BACKEND"
" is not in AUTHENTICATION_BACKENDS")
return default_login_backend
5 changes: 3 additions & 2 deletions tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def test_when_multiple_auth_backends_then_check_succeeds():


@override_rest_registration_settings({
'DEFAULT_LOGIN_AUTHENTICATION_BACKEND': 'nonexistent.backend',
'LOGIN_DEFAULT_SESSION_AUTHENTICATION_BACKEND': 'nonexistent.backend',
})
@override_settings(
AUTHENTICATION_BACKENDS=[
Expand All @@ -376,7 +376,8 @@ def test_when_login_auth_backend_not_in_multiple_auth_backends_then_check_fails(
])
expected_messages = {
"invalid authentication backends configuration:"
" DEFAULT_LOGIN_AUTHENTICATION_BACKEND is not in AUTHENTICATION_BACKENDS",
" LOGIN_DEFAULT_SESSION_AUTHENTICATION_BACKEND"
" is not in AUTHENTICATION_BACKENDS",
}
assert {e.msg for e in errors} == expected_messages

Expand Down

0 comments on commit 2879374

Please sign in to comment.