forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auth: Remove short_name from LDAP API.
As best I can tell, we fetched this field and then ignored it, so unlike the last few commits, this is more a code cleanup than a functional change.
- Loading branch information
Showing
5 changed files
with
28 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3403,7 +3403,7 @@ def totp(*args: Any, **kwargs: Any) -> int: | |
|
||
# Setup LDAP | ||
self.init_default_ldap_database() | ||
ldap_user_attr_map = {'full_name': 'cn', 'short_name': 'sn'} | ||
ldap_user_attr_map = {'full_name': 'cn'} | ||
with self.settings( | ||
AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',), | ||
TWO_FACTOR_CALL_GATEWAY='two_factor.gateways.fake.Fake', | ||
|
@@ -4204,9 +4204,9 @@ class _LDAPUser: | |
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',)) | ||
def test_get_or_build_user_when_user_does_not_exist(self) -> None: | ||
class _LDAPUser: | ||
attrs = {'fn': ['Full Name'], 'sn': ['Short Name']} | ||
attrs = {'fn': ['Full Name']} | ||
|
||
ldap_user_attr_map = {'full_name': 'fn', 'short_name': 'sn'} | ||
ldap_user_attr_map = {'full_name': 'fn'} | ||
|
||
with self.settings(AUTH_LDAP_USER_ATTR_MAP=ldap_user_attr_map): | ||
backend = self.backend | ||
|
@@ -4219,9 +4219,9 @@ class _LDAPUser: | |
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',)) | ||
def test_get_or_build_user_when_user_has_invalid_name(self) -> None: | ||
class _LDAPUser: | ||
attrs = {'fn': ['<invalid name>'], 'sn': ['Short Name']} | ||
attrs = {'fn': ['<invalid name>']} | ||
|
||
ldap_user_attr_map = {'full_name': 'fn', 'short_name': 'sn'} | ||
ldap_user_attr_map = {'full_name': 'fn'} | ||
|
||
with self.settings(AUTH_LDAP_USER_ATTR_MAP=ldap_user_attr_map): | ||
backend = self.backend | ||
|
@@ -4232,9 +4232,9 @@ class _LDAPUser: | |
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',)) | ||
def test_get_or_build_user_when_realm_is_deactivated(self) -> None: | ||
class _LDAPUser: | ||
attrs = {'fn': ['Full Name'], 'sn': ['Short Name']} | ||
attrs = {'fn': ['Full Name']} | ||
|
||
ldap_user_attr_map = {'full_name': 'fn', 'short_name': 'sn'} | ||
ldap_user_attr_map = {'full_name': 'fn'} | ||
|
||
with self.settings(AUTH_LDAP_USER_ATTR_MAP=ldap_user_attr_map): | ||
backend = self.backend | ||
|
@@ -4305,7 +4305,7 @@ def test_login_failure_when_domain_does_not_match(self) -> None: | |
|
||
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',)) | ||
def test_login_success_with_different_subdomain(self) -> None: | ||
ldap_user_attr_map = {'full_name': 'cn', 'short_name': 'sn'} | ||
ldap_user_attr_map = {'full_name': 'cn'} | ||
|
||
Realm.objects.create(string_id='acme') | ||
with self.settings( | ||
|
@@ -4695,30 +4695,26 @@ def test_user_not_present(self) -> None: | |
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',)) | ||
def test_normal_query(self) -> None: | ||
with self.settings(AUTH_LDAP_USER_ATTR_MAP={'full_name': 'cn', | ||
'short_name': 'sn', | ||
'avatar': 'jpegPhoto', | ||
'custom_profile_field__birthday': 'birthDate', | ||
'custom_profile_field__phone_number': 'nonExistentAttr', | ||
}): | ||
values = query_ldap(self.example_email('hamlet')) | ||
self.assertEqual(len(values), 5) | ||
self.assertEqual(len(values), 4) | ||
self.assertIn('full_name: King Hamlet', values) | ||
self.assertIn('short_name: Hamlet', values) | ||
self.assertIn('avatar: (An avatar image file)', values) | ||
self.assertIn('custom_profile_field__birthday: 1900-09-08', values) | ||
self.assertIn('custom_profile_field__phone_number: LDAP field not present', values) | ||
|
||
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',)) | ||
def test_query_email_attr(self) -> None: | ||
with self.settings(AUTH_LDAP_USER_ATTR_MAP={'full_name': 'cn', | ||
'short_name': 'sn'}, | ||
with self.settings(AUTH_LDAP_USER_ATTR_MAP={'full_name': 'cn'}, | ||
LDAP_EMAIL_ATTR='mail'): | ||
# This will look up the user by email in our test dictionary, | ||
# should successfully find hamlet's ldap entry. | ||
values = query_ldap(self.example_email('hamlet')) | ||
self.assertEqual(len(values), 3) | ||
self.assertEqual(len(values), 2) | ||
self.assertIn('full_name: King Hamlet', values) | ||
self.assertIn('short_name: Hamlet', values) | ||
self.assertIn('email: [email protected]', values) | ||
|
||
class TestZulipAuthMixin(ZulipTestCase): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,7 +138,7 @@ def test_day1_email_context(self) -> None: | |
"(uid=%(email)s)")) | ||
def test_day1_email_ldap_case_a_login_credentials(self) -> None: | ||
self.init_default_ldap_database() | ||
ldap_user_attr_map = {'full_name': 'cn', 'short_name': 'sn'} | ||
ldap_user_attr_map = {'full_name': 'cn'} | ||
|
||
with self.settings(AUTH_LDAP_USER_ATTR_MAP=ldap_user_attr_map): | ||
self.login_with_return("[email protected]", | ||
|
@@ -155,7 +155,7 @@ def test_day1_email_ldap_case_a_login_credentials(self) -> None: | |
'zproject.backends.ZulipDummyBackend')) | ||
def test_day1_email_ldap_case_b_login_credentials(self) -> None: | ||
self.init_default_ldap_database() | ||
ldap_user_attr_map = {'full_name': 'cn', 'short_name': 'sn'} | ||
ldap_user_attr_map = {'full_name': 'cn'} | ||
|
||
with self.settings( | ||
LDAP_APPEND_DOMAIN='zulip.com', | ||
|
@@ -175,7 +175,7 @@ def test_day1_email_ldap_case_b_login_credentials(self) -> None: | |
'zproject.backends.ZulipDummyBackend')) | ||
def test_day1_email_ldap_case_c_login_credentials(self) -> None: | ||
self.init_default_ldap_database() | ||
ldap_user_attr_map = {'full_name': 'cn', 'short_name': 'sn'} | ||
ldap_user_attr_map = {'full_name': 'cn'} | ||
|
||
with self.settings( | ||
LDAP_EMAIL_ATTR='mail', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters