dj22: set request as first argument in authenticate()
This commit is contained in:
parent
c4a0b3cde7
commit
8af8296dff
|
@ -33,7 +33,7 @@ class A2KerberosBackend(KerberosBackend):
|
|||
def provision_user(self, principal, user):
|
||||
pass
|
||||
|
||||
def authenticate(self, principal=None, request=None):
|
||||
def authenticate(self, request, principal):
|
||||
if not app_settings.ENABLE:
|
||||
return
|
||||
if not app_settings.DJANGO_BACKEND:
|
||||
|
@ -50,7 +50,7 @@ LDAPBackend._VALID_CONFIG_KEYS.append('principal_filter')
|
|||
|
||||
|
||||
class A2LdapKerberosBackend(LDAPBackend):
|
||||
def authenticate(self, principal=None, request=None):
|
||||
def authenticate(self, request, principal):
|
||||
principal = encoding.force_text(principal)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
|
@ -30,7 +30,7 @@ def test_authenticate_no_principal_filter(slapd, db):
|
|||
from authentic2_auth_kerberos.backends import A2LdapKerberosBackend
|
||||
|
||||
backend = A2LdapKerberosBackend()
|
||||
assert backend.authenticate(principal='john.doe@ENTROUVERT.COM') is None
|
||||
assert backend.authenticate(None, principal='john.doe@ENTROUVERT.COM') is None
|
||||
|
||||
|
||||
def test_authenticate_success(slapd, db, settings, django_user_model, caplog):
|
||||
|
@ -40,7 +40,7 @@ def test_authenticate_success(slapd, db, settings, django_user_model, caplog):
|
|||
settings.LDAP_AUTH_SETTINGS[0]['principal_filter'] = 'uid={username}'
|
||||
backend = A2LdapKerberosBackend()
|
||||
with caplog.at_level(logging.INFO):
|
||||
assert backend.authenticate(principal='john.doe@ENTROUVERT.COM') is not None
|
||||
assert backend.authenticate(None, principal='john.doe@ENTROUVERT.COM') is not None
|
||||
user = User.objects.get()
|
||||
assert user.username == 'john.doe@ldap'
|
||||
assert user.email == 'john.doe@example.com'
|
||||
|
@ -54,7 +54,7 @@ def test_authenticate_principal_filter_with_realm(slapd, settings, django_user_m
|
|||
settings.LDAP_AUTH_SETTINGS[0]['principal_filter'] = 'uid={username}@{realm}'
|
||||
backend = A2LdapKerberosBackend()
|
||||
with caplog.at_level(logging.INFO):
|
||||
assert backend.authenticate(principal='john.doe@ENTROUVERT.COM') is not None
|
||||
assert backend.authenticate(None, principal='john.doe@ENTROUVERT.COM') is not None
|
||||
user = User.objects.get()
|
||||
assert user.username == 'john.doe@ldap'
|
||||
assert user.email == 'john.doe@example.com'
|
||||
|
@ -67,7 +67,7 @@ def test_authenticate_bad_principal_filter(slapd, settings, django_user_model, c
|
|||
settings.LDAP_AUTH_SETTINGS[0]['principal_filter'] = 'uid={user}'
|
||||
backend = A2LdapKerberosBackend()
|
||||
with caplog.at_level(logging.INFO):
|
||||
assert backend.authenticate(principal='john.doe@ENTROUVERT.COM') is None
|
||||
assert backend.authenticate(None, principal='john.doe@ENTROUVERT.COM') is None
|
||||
assert len(caplog.records) == 1
|
||||
assert 'principal_filter does not' in caplog.text
|
||||
|
||||
|
@ -78,7 +78,7 @@ def test_authenticate_missing_realm_in_principal_filter(slapd, settings, django_
|
|||
settings.LDAP_AUTH_SETTINGS[0]['principal_filter'] = 'uid={username}'
|
||||
backend = A2LdapKerberosBackend()
|
||||
with caplog.at_level(logging.INFO):
|
||||
assert backend.authenticate(principal='foo.bar@ENTROUVERT.COM') is None
|
||||
assert backend.authenticate(None, principal='foo.bar@ENTROUVERT.COM') is None
|
||||
assert len(caplog.records) == 1
|
||||
assert 'principal foo.bar@ENTROUVERT.COM not found' in caplog.text
|
||||
|
||||
|
@ -90,7 +90,7 @@ def test_authenticate_limit_to_realm_failure(slapd, settings, django_user_model,
|
|||
settings.LDAP_AUTH_SETTINGS[0]['limit_to_realm'] = True
|
||||
backend = A2LdapKerberosBackend()
|
||||
with caplog.at_level(logging.INFO):
|
||||
assert backend.authenticate(principal='john.doe@ENTROUVERT.COM') is None
|
||||
assert backend.authenticate(None, principal='john.doe@ENTROUVERT.COM') is None
|
||||
assert not caplog.records
|
||||
|
||||
|
||||
|
@ -102,6 +102,6 @@ def test_authenticate_limit_to_realm_success(slapd, settings, django_user_model)
|
|||
settings.LDAP_AUTH_SETTINGS[0]['limit_to_realm'] = True
|
||||
settings.LDAP_AUTH_SETTINGS[0]['realm'] = 'ENTROUVERT.COM'
|
||||
backend = A2LdapKerberosBackend()
|
||||
assert backend.authenticate(principal='john.doe@ENTROUVERT.COM') is not None
|
||||
assert backend.authenticate(None, principal='john.doe@ENTROUVERT.COM') is not None
|
||||
user = User.objects.get()
|
||||
assert user.username == 'john.doe@ENTROUVERT.COM'
|
||||
|
|
Loading…
Reference in New Issue