Debian Codegraph @

ansible_collections/netapp_eseries/santricity/tests/unit/modules/test_na_santricity_ldap.py

raw symbols SCIP
1 # (c) 2020, NetApp, Inc
2 # BSD-3 Clause (see COPYING or https://opensource.org/licenses/BSD-3-Clause)
3 from __future__ import absolute_import, division, print_function
4 __metaclass__ = type
5 from contextlib import contextmanager
6 from ansible.module_utils.testing import patch_module_args
7 from ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_ldap import NetAppESeriesLdap
8 from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
9 AnsibleFailJson, AnsibleExitJson, ModuleTestCase
10 )
11 from ansible_collections.community.internal_test_tools.tests.unit.compat import mock
12
13
14 class LdapTest(ModuleTestCase):
15 REQUIRED_PARAMS = {
16 "api_username": "admin",
17 "api_password": "password",
18 "api_url": "http://localhost",
19 "ssid": "1"}
20 REQ_FUNC = "ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_ldap.NetAppESeriesLdap.request"
21 BASE_REQ_FUNC = "ansible_collections.netapp_eseries.santricity.plugins.module_utils.santricity.request"
22
23 GET_DOMAINS = {"version": "3",
24 "ldapDomains": [{"id": "test1",
25 "bindLookupUser": {"password": "***", "user": "CN=cn,OU=accounts,DC=test1,DC=example,DC=com"},
26 "groupAttributes": ["memberOf"],
27 "ldapUrl": "ldap://test.example.com:389",
28 "names": ["test.example.com"],
29 "roleMapCollection": [{"groupRegex": ".*", "ignoreCase": False, "name": "storage.monitor"}],
30 "searchBase": "OU=accounts,DC=test,DC=example,DC=com",
31 "userAttribute": "sAMAccountName"},
32 {"id": "test2",
33 "bindLookupUser": {"password": "***", "user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com"},
34 "groupAttributes": ["memberOf"],
35 "ldapUrl": "ldap://test2.example.com:389",
36 "names": ["test2.example.com"],
37 "roleMapCollection": [{"groupRegex": ".*", "ignoreCase": False, "name": "storage.admin"},
38 {"groupRegex": ".*", "ignoreCase": False, "name": "support.admin"},
39 {"groupRegex": ".*", "ignoreCase": False, "name": "security.admin"},
40 {"groupRegex": ".*", "ignoreCase": False, "name": "storage.monitor"}],
41 "searchBase": "OU=accounts,DC=test2,DC=example,DC=com",
42 "userAttribute": "sAMAccountName"}]}
43
44 @contextmanager
45 def _set_args(self, args=None):
46 module_args = self.REQUIRED_PARAMS.copy()
47 if args is not None:
48 module_args.update(args)
49 with patch_module_args(module_args):
50 yield
51
52 def test_valid_options_pass(self):
53 """Verify valid options."""
54 options_list = [{"state": "disabled"},
55 {"state": "absent", "identifier": "test_domain"},
56 {"state": "present", "identifier": "test_domain", "server_url": "ldap://test.example.com:389",
57 "search_base": "ou=accounts,DC=test,DC=example,DC=com"},
58 {"state": "present", "identifier": "test_domain", "server_url": "ldap://test.example.com:389",
59 "search_base": "ou=accounts,DC=test,DC=example,DC=com", "bind_user": "admin", "bind_password": "adminpass"},
60 {"state": "present", "identifier": "test_domain", "server_url": "ldap://test.example.com:389",
61 "search_base": "ou=accounts,DC=test,DC=example,DC=com", "bind_user": "admin", "bind_password": "adminpass",
62 "names": ["name1", "name2"], "group_attributes": ["group_attr1", "group_attr1"], "user_attribute": "user_attr"}]
63
64 for options in options_list:
65 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
66 with self._set_args(options):
67 ldap = NetAppESeriesLdap()
68 for options in options_list:
69 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": False})]):
70 with self._set_args(options):
71 ldap = NetAppESeriesLdap()
72
73 def test_get_domain_pass(self):
74 """Verify get_domain returns expected data structure."""
75 options = {"state": "present", "identifier": "test_domain", "server_url": "ldap://test.example.com:389",
76 "search_base": "ou=accounts,DC=test,DC=example,DC=com", "bind_user": "admin", "bind_password": "adminpass",
77 "names": ["name1", "name2"], "group_attributes": ["group_attr1", "group_attr1"], "user_attribute": "user_attr"}
78 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
79 with mock.patch(self.REQ_FUNC, return_value=(200, self.GET_DOMAINS)):
80 with self._set_args(options):
81 ldap = NetAppESeriesLdap()
82 self.assertEqual(ldap.get_domains(), self.GET_DOMAINS["ldapDomains"])
83
84 def test_get_domain_fail(self):
85 """Verify get_domain throws expected exceptions."""
86 options = {"state": "present", "identifier": "test_domain", "server_url": "ldap://test.example.com:389",
87 "search_base": "ou=accounts,DC=test,DC=example,DC=com", "bind_user": "admin", "bind_password": "adminpass",
88 "names": ["name1", "name2"], "group_attributes": ["group_attr1", "group_attr1"], "user_attribute": "user_attr"}
89 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
90 with mock.patch(self.REQ_FUNC, return_value=Exception()):
91 with self.assertRaisesRegex(AnsibleFailJson, "Failed to retrieve current LDAP configuration."):
92 with self._set_args(options):
93 ldap = NetAppESeriesLdap()
94 ldap.get_domains()
95
96 def test_build_request_body_pass(self):
97 """Verify build_request_body builds expected data structure."""
98 options_list = [{"state": "present", "identifier": "test_domain", "server_url": "ldap://test.example.com:389",
99 "search_base": "ou=accounts,DC=test,DC=example,DC=com"},
100 {"state": "present", "identifier": "test_domain", "server_url": "ldap://test.example.com:389",
101 "search_base": "ou=accounts,DC=test,DC=example,DC=com", "bind_user": "admin", "bind_password": "adminpass"},
102 {"state": "present", "identifier": "test_domain", "server_url": "ldap://test.example.com:389",
103 "search_base": "ou=accounts,DC=test,DC=example,DC=com", "bind_user": "admin", "bind_password": "adminpass",
104 "names": ["name1", "name2"], "group_attributes": ["group_attr1", "group_attr1"], "user_attribute": "user_attr"}]
105 expectation_list = [{'id': 'test_domain', 'groupAttributes': ['memberOf'], 'ldapUrl': 'ldap://test.example.com:389', 'names': ['test.example.com'],
106 'roleMapCollection': [], 'searchBase': 'ou=accounts,DC=test,DC=example,DC=com', 'userAttribute': 'sAMAccountName'},
107 {'id': 'test_domain', 'groupAttributes': ['memberOf'], 'ldapUrl': 'ldap://test.example.com:389', 'names': ['test.example.com'],
108 'roleMapCollection': [], 'searchBase': 'ou=accounts,DC=test,DC=example,DC=com', 'userAttribute': 'sAMAccountName',
109 'bindLookupUser': {'password': 'adminpass', 'user': 'admin'}},
110 {'id': 'test_domain', 'groupAttributes': ['group_attr1', 'group_attr1'], 'ldapUrl': 'ldap://test.example.com:389',
111 'names': ['name1', 'name2'], 'roleMapCollection': [], 'searchBase': 'ou=accounts,DC=test,DC=example,DC=com',
112 'userAttribute': 'user_attr', 'bindLookupUser': {'password': 'adminpass', 'user': 'admin'}}]
113 for index in range(len(options_list)):
114 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
115 with self._set_args(options_list[index]):
116 ldap = NetAppESeriesLdap()
117 ldap.build_request_body()
118 self.assertEqual(ldap.body, expectation_list[index])
119
120 def test_are_changes_required_pass(self):
121 """Verify build_request_body builds expected data structure."""
122 options_list = [{"state": "present", "identifier": "test_domain", "server_url": "ldap://test.example.com:389",
123 "search_base": "ou=accounts,DC=test,DC=example,DC=com"},
124 {"state": "present", "identifier": "test_domain", "server_url": "ldap://test.example.com:389",
125 "search_base": "ou=accounts,DC=test,DC=example,DC=com", "bind_user": "admin", "bind_password": "adminpass"},
126 {"state": "present", "identifier": "test_domain", "server_url": "ldap://test.example.com:389",
127 "search_base": "ou=accounts,DC=test,DC=example,DC=com", "bind_user": "admin", "bind_password": "adminpass",
128 "names": ["name1", "name2"], "group_attributes": ["group_attr1", "group_attr1"], "user_attribute": "user_attr"}]
129
130 for index in range(len(options_list)):
131 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
132 with self._set_args(options_list[index]):
133 ldap = NetAppESeriesLdap()
134 ldap.get_domains = lambda: self.GET_DOMAINS["ldapDomains"]
135 self.assertTrue(ldap.are_changes_required())
136
137 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
138 with self._set_args({"state": "disabled"}):
139 ldap = NetAppESeriesLdap()
140 ldap.get_domains = lambda: self.GET_DOMAINS["ldapDomains"]
141 self.assertTrue(ldap.are_changes_required())
142 self.assertEqual(ldap.existing_domain_ids, ["test1", "test2"])
143
144 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
145 with self._set_args({"state": "absent", "identifier": "test_domain"}):
146 ldap = NetAppESeriesLdap()
147 ldap.get_domains = lambda: self.GET_DOMAINS["ldapDomains"]
148 self.assertFalse(ldap.are_changes_required())
149
150 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
151 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
152 "search_base": "ou=accounts,DC=test2,DC=example,DC=com",
153 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
154 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
155 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
156 ldap = NetAppESeriesLdap()
157 ldap.build_request_body()
158 ldap.get_domains = lambda: self.GET_DOMAINS["ldapDomains"]
159 ldap.add_domain = lambda temporary, skip_test: {"id": "ANSIBLE_TMP_DOMAIN"}
160
161 with mock.patch(self.REQ_FUNC, return_value=(200, [{"id": "test2", "result": {"authenticationTestResult": "ok"}},
162 {"id": "ANSIBLE_TMP_DOMAIN", "result": {"authenticationTestResult": "ok"}}])):
163 self.assertFalse(ldap.are_changes_required())
164
165 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
166 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
167 "search_base": "ou=accounts,DC=test,DC=example,DC=com",
168 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
169 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
170 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
171 ldap = NetAppESeriesLdap()
172 ldap.build_request_body()
173 ldap.get_domains = lambda: self.GET_DOMAINS["ldapDomains"]
174 ldap.add_domain = lambda temporary, skip_test: {"id": "ANSIBLE_TMP_DOMAIN"}
175
176 with mock.patch(self.REQ_FUNC, return_value=(200, [{"id": "test2", "result": {"authenticationTestResult": "fail"}},
177 {"id": "ANSIBLE_TMP_DOMAIN", "result": {"authenticationTestResult": "ok"}}])):
178 self.assertTrue(ldap.are_changes_required())
179
180 def test_are_changes_required_fail(self):
181 """Verify are_changes_required throws expected exception."""
182 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
183 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
184 "search_base": "ou=accounts,DC=test2,DC=example,DC=com",
185 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
186 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
187 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
188 ldap = NetAppESeriesLdap()
189 ldap.build_request_body()
190 ldap.get_domains = lambda: self.GET_DOMAINS["ldapDomains"]
191 ldap.add_domain = lambda temporary, skip_test: {"id": "ANSIBLE_TMP_DOMAIN"}
192 with self.assertRaisesRegex(AnsibleFailJson, "Failed to authenticate bind credentials!"):
193 with mock.patch(self.REQ_FUNC, return_value=(200, [{"id": "test2", "result": {"authenticationTestResult": "fail"}},
194 {"id": "ANSIBLE_TMP_DOMAIN", "result": {"authenticationTestResult": "fail"}}])):
195 ldap.are_changes_required()
196
197 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
198 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
199 "search_base": "ou=accounts,DC=test2,DC=example,DC=com",
200 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
201 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
202 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
203 ldap = NetAppESeriesLdap()
204 ldap.build_request_body()
205 ldap.get_domains = lambda: self.GET_DOMAINS["ldapDomains"]
206 ldap.add_domain = lambda temporary, skip_test: {"id": "ANSIBLE_TMP_DOMAIN"}
207 with self.assertRaisesRegex(AnsibleFailJson, "Failed to authenticate bind credentials!"):
208 with mock.patch(self.REQ_FUNC, return_value=(200, [{"id": "test2", "result": {"authenticationTestResult": "ok"}},
209 {"id": "ANSIBLE_TMP_DOMAIN", "result": {"authenticationTestResult": "fail"}}])):
210 ldap.are_changes_required()
211
212 def test_add_domain_pass(self):
213 """Verify add_domain returns expected data."""
214 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
215 "search_base": "ou=accounts,DC=test,DC=example,DC=com",
216 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
217 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
218 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
219 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
220 ldap = NetAppESeriesLdap()
221 ldap.build_request_body()
222 with mock.patch(self.REQ_FUNC, return_value=(200, {"ldapDomains": [{"id": "test2"}]})):
223 self.assertEqual(ldap.add_domain(), {"id": "test2"})
224
225 def test_add_domain_fail(self):
226 """Verify add_domain returns expected data."""
227 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
228 "search_base": "ou=accounts,DC=test,DC=example,DC=com",
229 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
230 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
231 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
232 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
233 ldap = NetAppESeriesLdap()
234 ldap.build_request_body()
235 with self.assertRaisesRegex(AnsibleFailJson, "Failed to create LDAP domain."):
236 with mock.patch(self.REQ_FUNC, return_value=Exception()):
237 ldap.add_domain()
238
239 def test_update_domain_pass(self):
240 """Verify update_domain returns expected data."""
241 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
242 "search_base": "ou=accounts,DC=test,DC=example,DC=com",
243 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
244 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
245 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
246 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
247 ldap = NetAppESeriesLdap()
248 ldap.build_request_body()
249 ldap.domain = {"id": "test2"}
250 with mock.patch(self.REQ_FUNC, return_value=(200, None)):
251 ldap.update_domain()
252
253 def test_update_domain_fail(self):
254 """Verify update_domain returns expected data."""
255 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
256 "search_base": "ou=accounts,DC=test,DC=example,DC=com",
257 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
258 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
259 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
260 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
261 ldap = NetAppESeriesLdap()
262 ldap.build_request_body()
263 ldap.domain = {"id": "test2"}
264 with self.assertRaisesRegex(AnsibleFailJson, "Failed to update LDAP domain."):
265 with mock.patch(self.REQ_FUNC, return_value=Exception()):
266 ldap.update_domain()
267
268 def test_delete_domain_pass(self):
269 """Verify delete_domain returns expected data."""
270 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
271 "search_base": "ou=accounts,DC=test,DC=example,DC=com",
272 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
273 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
274 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
275 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
276 ldap = NetAppESeriesLdap()
277 with mock.patch(self.REQ_FUNC, return_value=(200, None)):
278 ldap.delete_domain("test2")
279
280 def test_delete_domain_fail(self):
281 """Verify delete_domain returns expected data."""
282 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
283 "search_base": "ou=accounts,DC=test,DC=example,DC=com",
284 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
285 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
286 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
287 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
288 ldap = NetAppESeriesLdap()
289 with self.assertRaisesRegex(AnsibleFailJson, "Failed to delete LDAP domain."):
290 with mock.patch(self.REQ_FUNC, return_value=Exception()):
291 ldap.delete_domain("test2")
292
293 def test_disable_domains_pass(self):
294 """Verify disable_domains completes successfully."""
295 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
296 "search_base": "ou=accounts,DC=test,DC=example,DC=com",
297 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
298 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
299 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
300 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
301 ldap = NetAppESeriesLdap()
302 ldap.delete_domain = lambda x: None
303 ldap.existing_domain_ids = ["id1", "id2", "id3"]
304 ldap.disable_domains()
305
306 def test_apply_pass(self):
307 """Verify apply exits as expected."""
308 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
309 "search_base": "ou=accounts,DC=test,DC=example,DC=com",
310 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
311 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
312 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
313 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
314 ldap = NetAppESeriesLdap()
315 ldap.build_request_body = lambda: None
316 ldap.are_changes_required = lambda: False
317 with self.assertRaisesRegex(AnsibleExitJson, "No changes have been made to the LDAP configuration."):
318 ldap.apply()
319
320 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
321 "search_base": "ou=accounts,DC=test,DC=example,DC=com",
322 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
323 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
324 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
325 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
326 ldap = NetAppESeriesLdap()
327 ldap.build_request_body = lambda: None
328 ldap.are_changes_required = lambda: True
329 ldap.add_domain = lambda: None
330 ldap.domain = {}
331 with self.assertRaisesRegex(AnsibleExitJson, "LDAP domain has been added."):
332 ldap.apply()
333
334 with self._set_args({"state": "present", "identifier": "test2", "server_url": "ldap://test2.example.com:389",
335 "search_base": "ou=accounts,DC=test,DC=example,DC=com",
336 "bind_user": "CN=cn,OU=accounts,DC=test2,DC=example,DC=com", "bind_password": "adminpass",
337 "role_mappings": {".*": ["storage.admin", "support.admin", "security.admin", "storage.monitor"]},
338 "names": ["test2.example.com"], "group_attributes": ["memberOf"], "user_attribute": "sAMAccountName"}):
339 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
340 ldap = NetAppESeriesLdap()
341 ldap.build_request_body = lambda: None
342 ldap.are_changes_required = lambda: True
343 ldap.update_domain = lambda: None
344 ldap.domain = {"id": "test"}
345 with self.assertRaisesRegex(AnsibleExitJson, "LDAP domain has been updated."):
346 ldap.apply()
347
348 with self._set_args({"state": "absent", "identifier": "test2"}):
349 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
350 ldap = NetAppESeriesLdap()
351 ldap.build_request_body = lambda: None
352 ldap.are_changes_required = lambda: True
353 ldap.delete_domain = lambda x: None
354 ldap.domain = {"id": "test"}
355 with self.assertRaisesRegex(AnsibleExitJson, "LDAP domain has been removed."):
356 ldap.apply()
357
358 with self._set_args({"state": "disabled"}):
359 with mock.patch(self.BASE_REQ_FUNC, side_effect=[(200, {"version": "04.10.0000.0001"}), (200, {"runningAsProxy": True})]):
360 ldap = NetAppESeriesLdap()
361 ldap.build_request_body = lambda: None
362 ldap.are_changes_required = lambda: True
363 ldap.disable_domain = lambda: None
364 ldap.domain = {"id": "test"}
365 with self.assertRaisesRegex(AnsibleExitJson, "All LDAP domains have been removed."):
366 ldap.apply()