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={