mirror of https://github.com/zulip/zulip.git
auth: Use different defaults for name and email for fakeldap.
Fixes part of #10297. Use FAKE_LDAP_NUM_USERS which specifies the number of LDAP users instead of FAKE_LDAP_EXTRA_USERS which specified the number of extra users.
This commit is contained in:
parent
eb676e8e50
commit
69bfa8c432
|
@ -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.
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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]:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue