Debian Codegraph @

dirsrvtests/tests/suites/acl/keywords_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2019 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ----
8
9 """
10 This test script will test wrong/correct key value with ACIs.
11 """
12
13 import os
14 import socket
15 import pytest
16
17 from lib389.idm.account import Anonymous
18 from lib389._constants import DEFAULT_SUFFIX, PW_DM
19 from lib389.idm.domain import Domain
20 from lib389.idm.organizationalunit import OrganizationalUnit
21 from lib389.idm.user import UserAccount
22
23 import ldap
24
25 pytestmark = pytest.mark.tier1
26
27 KEYWORDS_OU_KEY = "ou=Keywords,{}".format(DEFAULT_SUFFIX)
28 DNS_OU_KEY = "ou=DNS,{}".format(KEYWORDS_OU_KEY)
29 IP_OU_KEY = "ou=IP,{}".format(KEYWORDS_OU_KEY)
30 FULLIP_KEY = "uid=FULLIP_KEY,{}".format(IP_OU_KEY)
31 AUTHMETHOD_OU_KEY = "ou=Authmethod,{}".format(KEYWORDS_OU_KEY)
32 SIMPLE_1_KEY = "uid=SIMPLE_1_KEY,{}".format(AUTHMETHOD_OU_KEY)
33 FULLDNS_KEY = "uid=FULLDNS_KEY,{}".format(DNS_OU_KEY)
34 SUNDNS_KEY = "uid=SUNDNS_KEY,{}".format(DNS_OU_KEY)
35 NODNS_KEY = "uid=NODNS_KEY,{}".format(DNS_OU_KEY)
36 NETSCAPEDNS_KEY = "uid=NETSCAPEDNS_KEY,{}".format(DNS_OU_KEY)
37 NONE_1_KEY = "uid=NONE_1_KEY,{}".format(AUTHMETHOD_OU_KEY)
38 NONE_2_KEY = "uid=NONE_2_KEY,{}".format(AUTHMETHOD_OU_KEY)
39
40
41 NONE_ACI_KEY = f'(target = "ldap:///{AUTHMETHOD_OU_KEY}")' \
42 f'(targetattr="*")(version 3.0; aci "Authmethod aci"; ' \
43 f'allow(all) userdn = "ldap:///{NONE_1_KEY}" and authmethod = "none" ;)'
44
45 SIMPLE_ACI_KEY = f'(target = "ldap:///{AUTHMETHOD_OU_KEY}")' \
46 f'(targetattr="*")(version 3.0; aci "Authmethod aci"; ' \
47 f'allow(all) userdn = "ldap:///{SIMPLE_1_KEY}" and authmethod = "simple" ;)'
48
49
50 def _add_aci(topo, name):
51 """
52 This function will add ACI to DEFAULT_SUFFIX
53 """
54 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", name)
55
56
57 def test_user_binds_with_a_password_and_can_access_the_data(topo, add_user, aci_of_user):
58 """User binds with a password and can access the data as per the ACI.
59
60 :id: f6c4b6f0-7ac4-11e8-a517-8c16451d917b
61 :customerscenario: True
62 :setup: Standalone Server
63 :steps:
64 1. Add test entry
65 2. Add ACI
66 3. User should follow ACI role
67 :expectedresults:
68 1. Entry should be added
69 2. Operation should succeed
70 3. Operation should succeed
71 """
72 # Add ACI
73 _add_aci(topo, NONE_ACI_KEY)
74 # Create a new connection for this test.
75 conn = UserAccount(topo.standalone, NONE_1_KEY).bind(PW_DM)
76 # Perform Operation
77 OrganizationalUnit(conn, AUTHMETHOD_OU_KEY).replace("seeAlso", "cn=1")
78
79
80 def test_user_binds_with_a_bad_password_and_cannot_access_the_data(topo, add_user, aci_of_user):
81 """User binds with a BAD password and cannot access the data .
82
83 :id: 0397744e-7ac5-11e8-bfb1-8c16451d917b
84 :customerscenario: True
85 :setup: Standalone Server
86 :steps:
87 1. Add test entry
88 2. Add ACI
89 3. User should follow ACI role
90 :expectedresults:
91 1. Entry should be added
92 2. Operation should succeed
93 3. Operation should succeed
94 """
95 # User binds with a bad password and cannot access the data
96 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
97 UserAccount(topo.standalone, NONE_1_KEY).bind("")
98
99
100 def test_anonymous_user_cannot_access_the_data(topo, add_user, aci_of_user):
101 """Anonymous user cannot access the data
102
103 :id: 0821a55c-7ac5-11e8-b214-8c16451d917b
104 :customerscenario: True
105 :setup: Standalone Server
106 :steps:
107 1. Add test entry
108 2. Add ACI
109 3. User should follow ACI role
110 :expectedresults:
111 1. Entry should be added
112 2. Operation should succeed
113 3. Operation should succeed
114 """
115 # Add ACI
116 _add_aci(topo, NONE_ACI_KEY)
117
118 # Create a new connection for this test.
119 conn = Anonymous(topo.standalone).bind()
120 # Perform Operation
121 org = OrganizationalUnit(conn, AUTHMETHOD_OU_KEY)
122 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
123 org.replace("seeAlso", "cn=1")
124
125
126 def test_authenticated_but_has_no_rigth_on_the_data(topo, add_user, aci_of_user):
127 """User has a password. He is authenticated but has no rigth on the data.
128
129 :id: 11be7ebe-7ac5-11e8-b754-8c16451d917b
130 :customerscenario: True
131 :setup: Standalone Server
132 :steps:
133 1. Add test entry
134 2. Add ACI
135 3. User should follow ACI role
136 :expectedresults:
137 1. Entry should be added
138 2. Operation should succeed
139 3. Operation should succeed
140 """
141 # Add ACI
142 _add_aci(topo, NONE_ACI_KEY)
143
144 # Create a new connection for this test.
145 conn = UserAccount(topo.standalone, SIMPLE_1_KEY).bind(PW_DM)
146 # Perform Operation
147 org = OrganizationalUnit(conn, AUTHMETHOD_OU_KEY)
148 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
149 org.replace("seeAlso", "cn=1")
150
151
152 def test_the_bind_client_is_accessing_the_directory(topo, add_user, aci_of_user):
153 """The bind rule is evaluated to be true if the client is accessing the directory as per the ACI.
154
155 :id: 1715bfb2-7ac5-11e8-8f2c-8c16451d917b
156 :customerscenario: True
157 :setup: Standalone Server
158 :steps:
159 1. Add test entry
160 2. Add ACI
161 3. User should follow ACI role
162 :expectedresults:
163 1. Entry should be added
164 2. Operation should succeed
165 3. Operation should succeed
166 """
167 # Add ACI
168 _add_aci(topo, SIMPLE_ACI_KEY)
169
170 # Create a new connection for this test.
171 conn = UserAccount(topo.standalone, SIMPLE_1_KEY).bind(PW_DM)
172 # Perform Operation
173 OrganizationalUnit(conn, AUTHMETHOD_OU_KEY).replace("seeAlso", "cn=1")
174
175
176 def test_users_binds_with_a_password_and_can_access_the_data(
177 topo, add_user, aci_of_user):
178 """User binds with a password and can access the data as per the ACI.
179
180 :id: 1bd01cb4-7ac5-11e8-a2f1-8c16451d917b
181 :customerscenario: True
182 :setup: Standalone Server
183 :steps:
184 1. Add test entry
185 2. Add ACI
186 3. User should follow ACI role
187 :expectedresults:
188 1. Entry should be added
189 2. Operation should succeed
190 3. Operation should succeed
191 """
192 # Add ACI
193 _add_aci(topo, SIMPLE_ACI_KEY)
194
195 # Create a new connection for this test.
196 conn = UserAccount(topo.standalone, SIMPLE_1_KEY).bind(PW_DM)
197 # Perform Operation
198 OrganizationalUnit(conn, AUTHMETHOD_OU_KEY).replace("seeAlso", "cn=1")
199
200
201 def test_user_binds_without_any_password_and_cannot_access_the_data(topo, add_user, aci_of_user):
202 """User binds without any password and cannot access the data
203
204 :id: 205777fa-7ac5-11e8-ba2f-8c16451d917b
205 :customerscenario: True
206 :setup: Standalone Server
207 :steps:
208 1. Add test entry
209 2. Add ACI
210 3. User should follow ACI role
211 :expectedresults:
212 1. Entry should be added
213 2. Operation should succeed
214 3. Operation should succeed
215 """
216 # Add ACI
217 _add_aci(topo, SIMPLE_ACI_KEY)
218
219 # Create a new connection for this test.
220 conn = Anonymous(topo.standalone).bind()
221 # Perform Operation
222 org = OrganizationalUnit(conn, AUTHMETHOD_OU_KEY)
223 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
224 org.replace("seeAlso", "cn=1")
225
226 #unstable or unstatus tests, skipped for now
227 @pytest.mark.flaky(max_runs=2, min_passes=1)
228 def test_user_can_access_the_data_when_connecting_from_any_machine(
229 topo, add_user, aci_of_user
230 ):
231 """User can access the data when connecting from any machine as per the ACI.
232
233 :id: 28cbc008-7ac5-11e8-934e-8c16451d917b
234 :customerscenario: True
235 :setup: Standalone Server
236 :steps:
237 1. Add test entry
238 2. Add ACI
239 3. User should follow ACI role
240 :expectedresults:
241 1. Entry should be added
242 2. Operation should succeed
243 3. Operation should succeed
244 """
245 # Add ACI
246 Domain(topo.standalone, DEFAULT_SUFFIX)\
247 .add("aci", f'(target ="ldap:///{DNS_OU_KEY}")'
248 f'(targetattr="*")(version 3.0; aci "DNS aci"; allow(all) '
249 f'userdn = "ldap:///{FULLDNS_KEY}" and dns = "*" ;)')
250
251 # Create a new connection for this test.
252 conn = UserAccount(topo.standalone, FULLDNS_KEY).bind(PW_DM)
253 # Perform Operation
254 OrganizationalUnit(conn, DNS_OU_KEY).replace("seeAlso", "cn=1")
255
256
257 #unstable or unstatus tests, skipped for now
258 @pytest.mark.flaky(max_runs=2, min_passes=1)
259 def test_user_can_access_the_data_when_connecting_from_internal_ds_network_only(
260 topo, add_user, aci_of_user
261 ):
262 """User can access the data when connecting from internal ICNC network only as per the ACI.
263
264 :id: 2cac2136-7ac5-11e8-8328-8c16451d917b
265 :customerscenario: True
266 :setup: Standalone Server
267 :steps:
268 1. Add test entry
269 2. Add ACI
270 3. User should follow ACI role
271 :expectedresults:
272 1. Entry should be added
273 2. Operation should succeed
274 3. Operation should succeed
275 """
276 dns_name = socket.getfqdn()
277 # Add ACI
278 Domain(topo.standalone, DEFAULT_SUFFIX).\
279 add("aci", [f'(target = "ldap:///{DNS_OU_KEY}")(targetattr="*")'
280 f'(version 3.0; aci "DNS aci"; allow(all) '
281 f'userdn = "ldap:///{SUNDNS_KEY}" and '
282 f'(dns = "*redhat.com" or dns = "{dns_name}");)'])
283
284 # Create a new connection for this test.
285 conn = UserAccount(topo.standalone, SUNDNS_KEY).bind(PW_DM)
286 # Perform Operation
287 OrganizationalUnit(conn, DNS_OU_KEY).replace("seeAlso", "cn=1")
288
289 #unstable or unstatus tests, skipped for now
290 @pytest.mark.flaky(max_runs=2, min_passes=1)
291 def test_user_can_access_the_data_when_connecting_from_some_network_only(
292 topo, add_user, aci_of_user
293 ):
294 """User can access the data when connecting from some network only as per the ACI.
295
296 :id: 3098512a-7ac5-11e8-af85-8c16451d917b
297 :customerscenario: True
298 :setup: Standalone Server
299 :steps:
300 1. Add test entry
301 2. Add ACI
302 3. User should follow ACI role
303 :expectedresults:
304 1. Entry should be added
305 2. Operation should succeed
306 3. Operation should succeed
307 """
308 dns_name = socket.getfqdn()
309 # Add ACI
310 Domain(topo.standalone, DEFAULT_SUFFIX)\
311 .add("aci", f'(target = "ldap:///{DNS_OU_KEY}")'
312 f'(targetattr="*")(version 3.0; aci "DNS aci"; allow(all) '
313 f'userdn = "ldap:///{NETSCAPEDNS_KEY}" '
314 f'and dns = "{dns_name}" ;)')
315
316 # Create a new connection for this test.
317 conn = UserAccount(topo.standalone, NETSCAPEDNS_KEY).bind(PW_DM)
318 # Perform Operation
319 OrganizationalUnit(conn, DNS_OU_KEY).replace("seeAlso", "cn=1")
320
321 #unstable or unstatus tests, skipped for now
322 @pytest.mark.flaky(max_runs=2, min_passes=1)
323 def test_from_an_unauthorized_network(topo, add_user, aci_of_user):
324 """User cannot access the data when connecting from an unauthorized network as per the ACI.
325
326 :id: 34cf9726-7ac5-11e8-bc12-8c16451d917b
327 :customerscenario: True
328 :setup: Standalone Server
329 :steps:
330 1. Add test entry
331 2. Add ACI
332 3. User should follow ACI role
333 :expectedresults:
334 1. Entry should be added
335 2. Operation should succeed
336 3. Operation should succeed
337 """
338 # Add ACI
339 Domain(topo.standalone, DEFAULT_SUFFIX).\
340 add("aci", f'(target = "ldap:///{DNS_OU_KEY}")'
341 f'(targetattr="*")(version 3.0; aci "DNS aci"; allow(all) '
342 f'userdn = "ldap:///{NETSCAPEDNS_KEY}" and dns != "red.iplanet.com" ;)')
343
344 # Create a new connection for this test.
345 conn = UserAccount(topo.standalone, NETSCAPEDNS_KEY).bind(PW_DM)
346 # Perform Operation
347 OrganizationalUnit(conn, DNS_OU_KEY).replace("seeAlso", "cn=1")
348
349 #unstable or unstatus tests, skipped for now
350 @pytest.mark.flaky(max_runs=2, min_passes=1)
351 def test_user_cannot_access_the_data_when_connecting_from_an_unauthorized_network_2(
352 topo, add_user, aci_of_user):
353 """User cannot access the data when connecting from an unauthorized network as per the ACI.
354
355 :id: 396bdd44-7ac5-11e8-8014-8c16451d917b
356 :customerscenario: True
357 :setup: Standalone Server
358 :steps:
359 1. Add test entry
360 2. Add ACI
361 3. User should follow ACI role
362 :expectedresults:
363 1. Entry should be added
364 2. Operation should succeed
365 3. Operation should succeed
366 """
367 # Add ACI
368 Domain(topo.standalone, DEFAULT_SUFFIX).\
369 add("aci", f'(target = "ldap:///{DNS_OU_KEY}")'
370 f'(targetattr="*")(version 3.0; aci "DNS aci"; allow(all) '
371 f'userdn = "ldap:///{NETSCAPEDNS_KEY}" '
372 f'and dnsalias != "www.redhat.com" ;)')
373
374 # Create a new connection for this test.
375 conn = UserAccount(topo.standalone, NETSCAPEDNS_KEY).bind(PW_DM)
376 # Perform Operation
377 OrganizationalUnit(conn, DNS_OU_KEY).replace("seeAlso", "cn=1")
378
379
380 def test_user_cannot_access_the_data_if_not_from_a_certain_domain(topo, add_user, aci_of_user):
381 """User cannot access the data if not from a certain domain as per the ACI.
382
383 :id: 3d658972-7ac5-11e8-930f-8c16451d917b
384 :customerscenario: True
385 :setup: Standalone Server
386 :steps:
387 1. Add test entry
388 2. Add ACI
389 3. User should follow ACI role
390 :expectedresults:
391 1. Entry should be added
392 2. Operation should succeed
393 3. Operation should succeed
394 """
395 # Add ACI
396 Domain(topo.standalone, DEFAULT_SUFFIX).\
397 add("aci", f'(target = "ldap:///{DNS_OU_KEY}")(targetattr="*")'
398 f'(version 3.0; aci "DNS aci"; allow(all) '
399 f'userdn = "ldap:///{NODNS_KEY}" '
400 f'and dns = "RAP.rock.SALSA.house.COM" ;)')
401
402 # Create a new connection for this test.
403 conn = UserAccount(topo.standalone, NODNS_KEY).bind(PW_DM)
404 # Perform Operation
405 org = OrganizationalUnit(conn, AUTHMETHOD_OU_KEY)
406 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
407 org.replace("seeAlso", "cn=1")
408
409
410 def test_dnsalias_keyword_test_nodns_cannot(topo, add_user, aci_of_user):
411 """Dnsalias Keyword NODNS_KEY cannot assess data as per the ACI.
412
413 :id: 41b467be-7ac5-11e8-89a3-8c16451d917b
414 :customerscenario: True
415 :setup: Standalone Server
416 :steps:
417 1. Add test entry
418 2. Add ACI
419 3. User should follow ACI role
420 :expectedresults:
421 1. Entry should be added
422 2. Operation should succeed
423 3. Operation should succeed
424 """
425 # Add ACI
426 Domain(topo.standalone, DEFAULT_SUFFIX).\
427 add("aci", f'(target = "ldap:///{DNS_OU_KEY}")(targetattr="*")'
428 f'(version 3.0; aci "DNS aci"; allow(all) '
429 f'userdn = "ldap:///{NODNS_KEY}" and '
430 f'dnsalias = "RAP.rock.SALSA.house.COM" ;)')
431
432 # Create a new connection for this test.
433 conn = UserAccount(topo.standalone, NODNS_KEY).bind(PW_DM)
434 # Perform Operation
435 org = OrganizationalUnit(conn, DNS_OU_KEY)
436 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
437 org.replace("seeAlso", "cn=1")
438
439 #unstable or unstatus tests, skipped for now
440 @pytest.mark.flaky(max_runs=2, min_passes=1)
441 @pytest.mark.parametrize("ip_addr", ['127.0.0.1', "[::1]"])
442 def test_user_can_access_from_ipv4_or_ipv6_address(topo, add_user, aci_of_user, ip_addr):
443 """User can modify the data when accessing the server from the allowed IPv4 and IPv6 addresses
444
445 :id: 461e761e-7ac5-11e8-9ae4-8c16451d917b
446 :customerscenario: True
447 :parametrized: yes
448 :setup: Standalone Server
449 :steps:
450 1. Add ACI that has both IPv4 and IPv6
451 2. Connect from one of the IPs allowed in ACI
452 3. Modify an attribute
453 :expectedresults:
454 1. ACI should be added
455 2. Conection should be successful
456 3. Operation should be successful
457 """
458 # Add ACI that contains both IPv4 and IPv6
459 Domain(topo.standalone, DEFAULT_SUFFIX).\
460 add("aci", f'(target ="ldap:///{IP_OU_KEY}")(targetattr="*") '
461 f'(version 3.0; aci "IP aci"; allow(all) '
462 f'userdn = "ldap:///{FULLIP_KEY}" and (ip = "127.0.0.1" or ip = "::1");)')
463
464 # Create a new connection for this test.
465 conn = UserAccount(topo.standalone, FULLIP_KEY).bind(PW_DM, uri=f'ldap://{ip_addr}:{topo.standalone.port}')
466
467 # Perform Operation
468 OrganizationalUnit(conn, IP_OU_KEY).replace("seeAlso", "cn=1")
469
470
471 if __name__ == "__main__":
472 CURRENT_FILE = os.path.realpath(__file__)
473 pytest.main("-s -v %s" % CURRENT_FILE)