forked from EnterpriseyIntranet/nextcloud-API
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_ldap.py
76 lines (61 loc) · 2.89 KB
/
test_ldap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import re
from unittest.mock import patch
from .base import BaseTestCase
from nextcloud.api_wrappers.user_ldap import UserLDAP
class TestUserLDAP(BaseTestCase):
def setUp(self):
super(TestUserLDAP, self).setUp()
self.nxc.enable_app('user_ldap')
def test_crud_ldap_config(self):
res = self.nxc.create_ldap_config()
assert res.is_ok
config_id = res.data['configID']
# test get config by id
res = self.nxc.get_ldap_config(config_id)
assert res.is_ok
config_data = res.data
# test edit config
param_to_change = "ldapPagingSize"
old_param_value = config_data[param_to_change]
new_param_value = 777
assert old_param_value != new_param_value
res = self.nxc.edit_ldap_config(config_id, data={param_to_change: new_param_value})
assert res.is_ok
new_config_data = self.nxc.get_ldap_config(config_id).data
assert str(new_config_data[param_to_change]) == str(new_param_value)
# test showPassword param
ldap_password_param = "ldapAgentPassword"
ldap_password_value = "test_password"
self.nxc.edit_ldap_config(config_id, {ldap_password_param: ldap_password_value})
config_data_without_password = self.nxc.get_ldap_config(config_id).data
assert config_data_without_password[ldap_password_param] == "***"
config_data_with_password = self.nxc.get_ldap_config(config_id, show_password=1).data
assert config_data_with_password[ldap_password_param] == ldap_password_value
# test delete config
res = self.nxc.delete_ldap_config(config_id)
assert res.is_ok
res = self.nxc.get_ldap_config(config_id)
assert res.status_code == self.NOT_FOUND_CODE
def test_ldap_setters_getters(self):
res = self.nxc.create_ldap_config()
assert res.is_ok
assert res.status_code == 200
config_id = res.data['configID']
for ldap_key in UserLDAP.CONFIG_KEYS:
key_name = re.sub('ldap', '', ldap_key)
key_name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', key_name).lower()
getter_name = "get_ldap_{}".format(key_name)
setter_name = "set_ldap_{}".format(key_name)
# test if method exist
assert hasattr(self.nxc, setter_name)
assert hasattr(self.nxc, getter_name)
# test getter
getter_value = getattr(self.nxc, getter_name)(config_id)
config_value = self.nxc.get_ldap_config(config_id).data[ldap_key]
assert getter_value == config_value
# test setter
value = 1
with patch.object(UserLDAP, 'edit_ldap_config', return_value=1) as mock_method:
setter_method = getattr(self.nxc, setter_name)
setter_method(config_id, value)
mock_method.assert_called_with(config_id, data={ldap_key: value})