mirror of https://github.com/zulip/zulip.git
test_settings: Migrate ldap tests to the new format.
This commit is contained in:
parent
efba7290fd
commit
e9df17884a
|
@ -2,12 +2,11 @@ import ujson
|
||||||
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
from mock import patch
|
|
||||||
from typing import Any, Dict, Union
|
from typing import Any, Dict, Union
|
||||||
|
|
||||||
from zerver.lib.initial_password import initial_password
|
from zerver.lib.initial_password import initial_password
|
||||||
from zerver.lib.test_classes import ZulipTestCase
|
from zerver.lib.test_classes import ZulipTestCase
|
||||||
from zerver.lib.test_helpers import MockLDAP, get_test_image_file
|
from zerver.lib.test_helpers import get_test_image_file
|
||||||
from zerver.lib.users import get_all_api_keys
|
from zerver.lib.users import get_all_api_keys
|
||||||
from zerver.models import get_realm, UserProfile, \
|
from zerver.models import get_realm, UserProfile, \
|
||||||
get_user_profile_by_api_key
|
get_user_profile_by_api_key
|
||||||
|
@ -185,24 +184,13 @@ class ChangeSettingsTest(ZulipTestCase):
|
||||||
|
|
||||||
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',
|
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',
|
||||||
'zproject.backends.EmailAuthBackend',
|
'zproject.backends.EmailAuthBackend',
|
||||||
'zproject.backends.ZulipDummyBackend'),
|
'zproject.backends.ZulipDummyBackend'))
|
||||||
AUTH_LDAP_BIND_PASSWORD='',
|
|
||||||
AUTH_LDAP_USER_DN_TEMPLATE='uid=%(user)s,ou=users,dc=zulip,dc=com')
|
|
||||||
def test_change_password_ldap_backend(self) -> None:
|
def test_change_password_ldap_backend(self) -> None:
|
||||||
ldap_user_attr_map = {'full_name': 'fn', 'short_name': 'sn'}
|
self.init_default_ldap_database()
|
||||||
ldap_patcher = patch('django_auth_ldap.config.ldap.initialize')
|
ldap_user_attr_map = {'full_name': 'cn', 'short_name': 'sn'}
|
||||||
mock_initialize = ldap_patcher.start()
|
|
||||||
mock_ldap = MockLDAP()
|
|
||||||
mock_initialize.return_value = mock_ldap
|
|
||||||
|
|
||||||
mock_ldap.directory = {
|
|
||||||
'uid=hamlet,ou=users,dc=zulip,dc=com': {
|
|
||||||
'userPassword': ['ldappassword', ],
|
|
||||||
'fn': ['New LDAP fullname']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.login(self.example_email("hamlet"))
|
self.login(self.example_email("hamlet"))
|
||||||
|
|
||||||
with self.settings(LDAP_APPEND_DOMAIN="zulip.com",
|
with self.settings(LDAP_APPEND_DOMAIN="zulip.com",
|
||||||
AUTH_LDAP_USER_ATTR_MAP=ldap_user_attr_map):
|
AUTH_LDAP_USER_ATTR_MAP=ldap_user_attr_map):
|
||||||
result = self.client_patch(
|
result = self.client_patch(
|
||||||
|
@ -216,7 +204,7 @@ class ChangeSettingsTest(ZulipTestCase):
|
||||||
result = self.client_patch(
|
result = self.client_patch(
|
||||||
"/json/settings",
|
"/json/settings",
|
||||||
dict(
|
dict(
|
||||||
old_password='ldappassword',
|
old_password='testing', # hamlet's password in ldap
|
||||||
new_password="ignored",
|
new_password="ignored",
|
||||||
))
|
))
|
||||||
self.assert_json_error(result, "Your Zulip password is managed in LDAP")
|
self.assert_json_error(result, "Your Zulip password is managed in LDAP")
|
||||||
|
|
Loading…
Reference in New Issue