From 5b9b494593afa4053672c95b038a07edf6318e1b Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Mon, 30 Mar 2020 12:33:08 +0200 Subject: [PATCH] ldap auth: fixed unit test. --- modoboa/core/tests/test_ldap.py | 2 +- modoboa/lib/authbackends.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modoboa/core/tests/test_ldap.py b/modoboa/core/tests/test_ldap.py index 1e47f9c60..a1b843319 100644 --- a/modoboa/core/tests/test_ldap.py +++ b/modoboa/core/tests/test_ldap.py @@ -119,7 +119,7 @@ class LDAPAuthenticationTestCase(LDAPTestCaseMixin, ModoTestCase): }) username = "mailadmin" self.authenticate(username, "test", False) - self.check_created_user(username, "DomainAdmins", False) + self.check_created_user("mailadmin@example.com", "DomainAdmins", False) class ProfileTestCase(LDAPTestCaseMixin, ModoTestCase): diff --git a/modoboa/lib/authbackends.py b/modoboa/lib/authbackends.py index a4122b497..34b64641e 100644 --- a/modoboa/lib/authbackends.py +++ b/modoboa/lib/authbackends.py @@ -92,9 +92,13 @@ try: if attr in ldap_user.attrs: email = ldap_user.attrs[attr][0] break - if email is None and group == "SimpleUsers": - return None - username = email + if email is None: + if group == "SimpleUsers": + # Only DomainAdmins can have a username which + # is not an email address + return None + else: + username = email user, created = User.objects.get_or_create( username__iexact=username, defaults={