diff --git a/docs/subsystems/auth.md b/docs/subsystems/auth.md index efe0de71a9..b39a762e6b 100644 --- a/docs/subsystems/auth.md +++ b/docs/subsystems/auth.md @@ -79,6 +79,6 @@ information on these modes, refer to their usernames (e.g. for `ldapuser1@zulip.com`, the password is `ldapuser1`). -- `FAKE_LDAP_EXTRA_USERS` in `zproject/dev_settings.py` can be used to -generate additional extra users to be added, in addition to the -8 default LDAP users. +- `FAKE_LDAP_NUM_USERS` in `zproject/dev_settings.py` can be used to +specify the number of LDAP users to be added. The default value for +the number of LDAP users is 8. diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index b34c1beac6..d0aabd8df5 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -2110,21 +2110,21 @@ class TestLDAP(ZulipTestCase): realm.save() def test_generate_dev_ldap_dir(self) -> None: - ldap_dir = generate_dev_ldap_dir('A', 2) + ldap_dir = generate_dev_ldap_dir('A', 10) self.assertEqual(len(ldap_dir), 10) regex = re.compile(r'(uid\=)+[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+(\,ou\=users\,dc\=zulip\,dc\=com)') for key, value in ldap_dir.items(): self.assertTrue(regex.match(key)) self.assertCountEqual(list(value.keys()), ['cn', 'userPassword']) - ldap_dir = generate_dev_ldap_dir('b', 1) + ldap_dir = generate_dev_ldap_dir('b', 9) self.assertEqual(len(ldap_dir), 9) regex = re.compile(r'(uid\=)+[a-zA-Z0-9_.+-]+(\,ou\=users\,dc\=zulip\,dc\=com)') for key, value in ldap_dir.items(): self.assertTrue(regex.match(key)) self.assertCountEqual(list(value.keys()), ['cn', 'userPassword']) - ldap_dir = generate_dev_ldap_dir('c', 0) + ldap_dir = generate_dev_ldap_dir('c', 8) self.assertEqual(len(ldap_dir), 8) regex = re.compile(r'(uid\=)+[a-zA-Z0-9_.+-]+(\,ou\=users\,dc\=zulip\,dc\=com)') for key, value in ldap_dir.items(): diff --git a/zproject/backends.py b/zproject/backends.py index f6a3f9b668..994a2d279c 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -107,20 +107,11 @@ def common_get_active_user(email: str, realm: Realm, return None return user_profile -def generate_dev_ldap_dir(mode: str, extra_users: int=0) -> Dict[str, Dict[str, Sequence[str]]]: +def generate_dev_ldap_dir(mode: str, num_users: int=8) -> Dict[str, Dict[str, Sequence[str]]]: mode = mode.lower() - names = [ - ("Zoe", "ldap_ZOE@zulip.com"), - ("Othello, the Moor of Venice", "ldap_othello@zulip.com"), - ("Iago", "ldap_iago@zulip.com"), - ("Prospero from The Tempest", "ldap_prospero@zulip.com"), - ("Cordelia Lear", "ldap_cordelia@zulip.com"), - ("King Hamlet", "ldap_hamlet@zulip.com"), - ("aaron", "ldap_AARON@zulip.com"), - ("Polonius", "ldap_polonius@zulip.com"), - ] - for i in range(extra_users): - names.append(('Extra User %d' % (i,), 'ldap_extrauser%d@zulip.com' % (i,))) + names = [] + for i in range(1, num_users+1): + names.append(('LDAP User %d' % (i,), 'ldapuser%d@zulip.com' % (i,))) ldap_dir = {} if mode == 'a': @@ -336,7 +327,7 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase): self.mock_initialize.return_value = self.mock_ldap self.mock_ldap.directory = generate_dev_ldap_dir(settings.FAKE_LDAP_MODE, - settings.FAKE_LDAP_EXTRA_USERS) + settings.FAKE_LDAP_NUM_USERS) def authenticate(self, username: str, password: str, realm: Optional[Realm]=None, return_data: Optional[Dict[str, Any]]=None) -> Optional[UserProfile]: diff --git a/zproject/dev_settings.py b/zproject/dev_settings.py index c68525301a..bf6dccd1bd 100644 --- a/zproject/dev_settings.py +++ b/zproject/dev_settings.py @@ -103,7 +103,7 @@ ALWAYS_SEND_ALL_HOTSPOTS = False # type: bool # In any case, the LDAP user account data is available in: # zerver/tests/fixtures/ldap_dir.json FAKE_LDAP_MODE = None # type: Optional[str] -FAKE_LDAP_EXTRA_USERS = 0 +# FAKE_LDAP_NUM_USERS = 8 if FAKE_LDAP_MODE: LDAP_APPEND_DOMAIN = None diff --git a/zproject/settings.py b/zproject/settings.py index 3c598820ed..a8cb4a5a31 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -144,7 +144,7 @@ DEFAULT_SETTINGS = { # support local development of LDAP auth without an LDAP server. # Detailed docs in zproject/dev_settings.py. 'FAKE_LDAP_MODE': None, - 'FAKE_LDAP_EXTRA_USERS': 0, + 'FAKE_LDAP_NUM_USERS': 8, # Social auth; we support providing values for some of these # settings in zulip-secrets.conf instead of settings.py in development.