Debian Codegraph @

dirsrvtests/tests/suites/acl/search_real_part3_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2020 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 import pytest, os, ldap
10 from lib389._constants import DEFAULT_SUFFIX, PW_DM, ErrorLog
11 from lib389.idm.user import UserAccount, UserAccounts
12 from lib389.idm.organization import Organization
13 from lib389.idm.account import Accounts, Anonymous
14 from lib389.idm.group import Group, UniqueGroup
15 from lib389.idm.organizationalunit import OrganizationalUnit
16 from lib389.idm.group import Groups
17 from test389.topologies import topology_st as topo
18 from lib389.idm.domain import Domain
19
20 pytestmark = pytest.mark.tier1
21
22 CONTAINER_1_DELADD = "ou=Product Development,{}".format(DEFAULT_SUFFIX)
23 CONTAINER_2_DELADD = "ou=Accounting,{}".format(DEFAULT_SUFFIX)
24 USER_ANUJ = "uid=Anuj Borah,{}".format(CONTAINER_1_DELADD)
25 USER_ANANDA = "uid=Ananda Borah,{}".format(CONTAINER_2_DELADD)
26
27
28 @pytest.fixture(scope="function")
29 def aci_of_user(request, topo):
30 # Add anonymous access aci
31 ACI_TARGET = "(targetattr != \"userpassword\")(target = \"ldap:///%s\")" % (DEFAULT_SUFFIX)
32 ACI_ALLOW = "(version 3.0; acl \"Anonymous Read access\"; allow (read,search,compare)"
33 ACI_SUBJECT = "(userdn=\"ldap:///anyone\");)"
34 ANON_ACI = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
35 suffix = Domain(topo.standalone, DEFAULT_SUFFIX)
36 try:
37 suffix.add('aci', ANON_ACI)
38 except ldap.TYPE_OR_VALUE_EXISTS:
39 pass
40
41 aci_list = suffix.get_attr_vals('aci')
42
43 def finofaci():
44 domain = Domain(topo.standalone, DEFAULT_SUFFIX)
45 domain.set('aci', None)
46 for i in aci_list:
47 domain.add("aci", i)
48
49 request.addfinalizer(finofaci)
50
51
52 @pytest.fixture(scope="module")
53 def add_test_user(request, topo):
54 topo.standalone.config.loglevel((ErrorLog.ACL_SUMMARY,))
55
56 for i in ['Product Development', 'Accounting']:
57 OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX)).create(properties={'ou': i})
58
59 users = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn='ou=Product Development')
60 users.create(properties={
61 'uid': 'Anuj Borah',
62 'cn': 'Anuj Borah',
63 'sn': 'user',
64 'uidNumber': '1000',
65 'gidNumber': '2000',
66 'homeDirectory': '/home/' + 'AnujBorah',
67 'userPassword': PW_DM
68 })
69
70 users = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn='ou=Accounting')
71 users.create(properties={
72 'uid': 'Ananda Borah',
73 'cn': 'Ananda Borah',
74 'sn': 'user',
75 'uidNumber': '1000',
76 'gidNumber': '2000',
77 'homeDirectory': '/home/' + 'AnandaBorah',
78 'userPassword': PW_DM
79 })
80
81
82 def test_deny_search_access_to_userdn_with_ldap_url(topo, add_test_user, aci_of_user):
83 """Search Test 23 Deny search access to userdn with LDAP URL
84
85 :id: 94f082d8-6e12-11e8-be72-8c16451d917b
86 :setup: Standalone Instance
87 :steps:
88 1. Add Entry
89 2. Add ACI
90 3. Bind with test USER_ANUJ
91 4. Try search
92 5. Delete Entry,test USER_ANUJ, ACI
93 :expectedresults:
94 1. Operation should success
95 2. Operation should success
96 3. Operation should success
97 4. Operation should Fail
98 5. Operation should success
99 """
100 ACI_TARGET = '(target = ldap:///{})(targetattr="*")'.format(DEFAULT_SUFFIX)
101 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny (search)'
102 ACI_SUBJECT = (
103 'userdn="ldap:///%s";)' % "{}??sub?(&(roomnumber=3445))".format(DEFAULT_SUFFIX)
104 )
105 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
106 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
107 UserAccount(topo.standalone, USER_ANANDA).set('roomnumber', '3445')
108 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
109 # aci will block all users having roomnumber=3445
110 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
111 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
112 # aci will block roomnumber=3445 for all users USER_ANUJ does not have roomnumber
113 assert 4 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
114 # with root there is no aci blockage
115 UserAccount(topo.standalone, USER_ANANDA).remove('roomnumber', '3445')
116
117
118 def test_deny_search_access_to_userdn_with_ldap_url_two(topo, add_test_user, aci_of_user):
119 """Search Test 24 Deny search access to != userdn with LDAP URL
120
121 :id: a1ee05d2-6e12-11e8-8260-8c16451d917b
122 :setup: Standalone Instance
123 :steps:
124 1. Add Entry
125 2. Add ACI
126 3. Bind with test USER_ANUJ
127 4. Try search
128 5. Delete Entry,test USER_ANUJ, ACI
129 :expectedresults:
130 1. Operation should success
131 2. Operation should success
132 3. Operation should success
133 4. Operation should Fail
134 5. Operation should success
135 """
136 ACI_TARGET = '(target = ldap:///{})(targetattr="*")'.format(DEFAULT_SUFFIX)
137 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny (search)'
138 ACI_SUBJECT = (
139 'userdn != "ldap:///%s";)' % "{}??sub?(&(roomnumber=3445))".format(DEFAULT_SUFFIX)
140 )
141 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
142 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
143 UserAccount(topo.standalone, USER_ANANDA).set('roomnumber', '3445')
144 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
145 # aci will not block all users having roomnumber=3445 , it will block others
146 assert 4 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
147 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
148 # aci will not block all users having roomnumber=3445 , it will block others
149 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
150 # with root there is no aci blockage
151 UserAccount(topo.standalone, USER_ANANDA).remove('roomnumber', '3445')
152
153
154 def test_deny_search_access_to_userdn_with_ldap_url_matching_all_users(
155 topo, add_test_user, aci_of_user
156 ):
157 """Search Test 25 Deny search access to userdn with LDAP URL matching all users
158
159 :id: b37f72ae-6e12-11e8-9c98-8c16451d917b
160 :setup: Standalone Instance
161 :steps:
162 1. Add Entry
163 2. Add ACI
164 3. Bind with test USER_ANUJ
165 4. Try search
166 5. Delete Entry,test USER_ANUJ, ACI
167 :expectedresults:
168 1. Operation should success
169 2. Operation should success
170 3. Operation should success
171 4. Operation should Fail
172 5. Operation should success
173 """
174 ACI_TARGET = '(target = ldap:///{})(targetattr="*")'.format(DEFAULT_SUFFIX)
175 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny (search)'
176 ACI_SUBJECT = 'userdn = "ldap:///%s";)' % "{}??sub?(&(cn=*))".format(DEFAULT_SUFFIX)
177 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
178 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
179 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
180 # aci will block all users LDAP URL matching all users
181 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
182 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
183 # aci will block all users LDAP URL matching all users
184 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
185 # with root there is no aci blockage
186 assert 4 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(cn=*)'))
187
188
189 def test_deny_read_access_to_a_dynamic_group(topo, add_test_user, aci_of_user):
190 """Search Test 26 Deny read access to a dynamic group
191
192 :id: c0c5290e-6e12-11e8-a900-8c16451d917b
193 :setup: Standalone Instance
194 :steps:
195 1. Add Entry
196 2. Add ACI
197 3. Bind with test USER_ANUJ
198 4. Try search
199 5. Delete Entry,test USER_ANUJ, ACI
200 :expectedresults:
201 1. Operation should success
202 2. Operation should success
203 3. Operation should success
204 4. Operation should Fail
205 5. Operation should success
206 """
207 groups = Groups(topo.standalone, DEFAULT_SUFFIX)
208 group_properties = {"cn": "group1", "description": "testgroup"}
209 group = groups.create(properties=group_properties)
210 group.add('objectClass', 'groupOfURLS')
211 group.set('memberURL', "ldap:///{}??sub?(&(ou=Accounting)(cn=Sam*))".format(DEFAULT_SUFFIX))
212 group.add_member(USER_ANANDA)
213
214 ACI_TARGET = '(target = ldap:///{})(targetattr = "*")'.format(DEFAULT_SUFFIX)
215 ACI_ALLOW = '(version 3.0; acl "All rights for %s"; deny(read)' % "Unknown"
216 ACI_SUBJECT = 'groupdn = "ldap:///cn=group1,ou=Groups,{}";)'.format(DEFAULT_SUFFIX)
217 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
218 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
219 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
220 # aci will block all 'memberURL', "ldap:///{}??sub?(&(ou=Accounting)(cn=Sam*))".format(DEFAULT_SUFFIX)
221 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
222 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
223 # USER_ANUJ is not a member
224 assert 4 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
225 group.delete()
226
227
228 def test_deny_read_access_to_dynamic_group_with_host_port_set_on_ldap_url(
229 topo, add_test_user, aci_of_user
230 ):
231 """Search Test 27 Deny read access to dynamic group with host:port set on LDAP URL
232
233 :id: ceb62158-6e12-11e8-8c36-8c16451d917b
234 :setup: Standalone Instance
235 :steps:
236 1. Add Entry
237 2. Add ACI
238 3. Bind with test USER_ANUJ
239 4. Try search
240 5. Delete Entry,test USER_ANUJ, ACI
241 :expectedresults:
242 1. Operation should success
243 2. Operation should success
244 3. Operation should success
245 4. Operation should Fail
246 5. Operation should success
247 """
248 groups = Groups(topo.standalone, DEFAULT_SUFFIX)
249 group = groups.create(properties={"cn": "group1",
250 "description": "testgroup"
251 })
252 group.add('objectClass', 'groupOfURLS')
253 group.set('memberURL', "ldap:///localhost:38901/{}??sub?(&(ou=Accounting)(cn=Sam*))".format(DEFAULT_SUFFIX))
254 group.add_member(USER_ANANDA)
255
256 ACI_TARGET = '(target = ldap:///{})(targetattr = "*")'.format(DEFAULT_SUFFIX)
257 ACI_ALLOW = '(version 3.0; acl "All rights for %s"; deny(read)' % "Unknown"
258 ACI_SUBJECT = 'groupdn = "ldap:///cn=group1,ou=Groups,{}";)'.format(DEFAULT_SUFFIX)
259 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
260 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
261 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
262 # aci will block 'memberURL', "ldap:///localhost:38901/dc=example,dc=com??sub?(&(ou=Accounting)(cn=Sam*))"
263 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
264 # with root there is no aci blockage
265 assert 4 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(cn=*)'))
266 group.delete()
267
268
269 def test_deny_read_access_to_dynamic_group_with_scope_set_to_one_in_ldap_url(
270 topo, add_test_user, aci_of_user
271 ):
272 """Search Test 28 Deny read access to dynamic group with scope set to "one" in LDAP URL
273
274 :id: ddb30432-6e12-11e8-94db-8c16451d917b
275 :setup: Standalone Instance
276 :steps:
277 1. Add Entry
278 2. Add ACI
279 3. Bind with test USER_ANUJ
280 4. Try search
281 5. Delete Entry,test USER_ANUJ, ACI
282 :expectedresults:
283 1. Operation should success
284 2. Operation should success
285 3. Operation should success
286 4. Operation should Fail
287 5. Operation should success
288 """
289 groups = Groups(topo.standalone, DEFAULT_SUFFIX)
290 group = groups.create(properties={"cn": "group1",
291 "description": "testgroup"
292 })
293 group.add('objectClass', 'groupOfURLS')
294 group.set('memberURL', "ldap:///{}??sub?(&(ou=Accounting)(cn=Sam*))".format(DEFAULT_SUFFIX))
295 group.add_member(USER_ANANDA)
296
297 ACI_TARGET = '(targetattr = "*")'
298 ACI_ALLOW = '(version 3.0; acl "All rights for %s"; deny(read) ' % "Unknown"
299 ACI_SUBJECT = 'groupdn != "ldap:///cn=group1,ou=Groups,{}";)'.format(DEFAULT_SUFFIX)
300 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
301 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
302 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
303 # aci will allow only 'memberURL', "ldap:///{dc=example,dc=com??sub?(&(ou=Accounting)(cn=Sam*))"
304 assert 4 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
305 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
306 # aci will allow only 'memberURL', "ldap:///{dc=example,dc=com??sub?(&(ou=Accounting)(cn=Sam*))"
307 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
308 group.delete()
309
310
311 def test_deny_read_access_to_dynamic_group_two(topo, add_test_user, aci_of_user):
312 """Search Test 29 Deny read access to != dynamic group
313
314 :id: eae2a6c6-6e12-11e8-80f3-8c16451d917b
315 :setup: Standalone Instance
316 :steps:
317 1. Add Entry
318 2. Add ACI
319 3. Bind with test USER_ANUJ
320 4. Try search
321 5. Delete Entry,test USER_ANUJ, ACI
322 :expectedresults:
323 1. Operation should success
324 2. Operation should success
325 3. Operation should success
326 4. Operation should Fail
327 5. Operation should success
328 """
329 groups = Groups(topo.standalone, DEFAULT_SUFFIX)
330 group_properties = {"cn": "group1",
331 "description": "testgroup"
332 }
333 group = groups.create(properties=group_properties)
334 group.add('objectClass', 'groupofuniquenames')
335 group.set('uniquemember', [USER_ANANDA,USER_ANUJ])
336
337 ACI_TARGET = '(targetattr = "*")'
338 ACI_ALLOW = '(version 3.0; acl "All rights for %s"; deny(read) ' % "Unknown"
339 ACI_SUBJECT = 'groupdn = "ldap:///cn=group1,ou=Groups,{}";)'.format(DEFAULT_SUFFIX)
340 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
341 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
342 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
343 # aci will block groupdn = "ldap:///cn=group1,ou=Groups,dc=example,dc=com";)
344 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
345 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
346 # aci will block groupdn = "ldap:///cn=group1,ou=Groups,dc=example,dc=com";)
347 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
348 # with root there is no aci blockage
349 assert 4 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(cn=*)'))
350 group.delete()
351
352
353 def test_deny_access_to_group_should_deny_access_to_all_uniquemember(
354 topo, add_test_user, aci_of_user, request
355 ):
356 """Search Test 38 Deny access to group should deny access to all uniquemember (including chain group)
357
358 :id: 56b470e4-7941-11e8-912b-8c16451d917b
359 :setup: Standalone Instance
360 :steps:
361 1. Add Entry
362 2. Add ACI
363 3. Bind with test USER_ANUJ
364 4. Try search
365 5. Delete Entry,test USER_ANUJ, ACI
366 :expectedresults:
367 1. Operation should success
368 2. Operation should success
369 3. Operation should success
370 4. Operation should Fail
371 5. Operation should success
372 """
373
374 grp = UniqueGroup(topo.standalone, 'cn=Nested Group 1,' + DEFAULT_SUFFIX)
375 grp.create(properties={
376 'cn': 'Nested Group 1',
377 'ou': 'groups',
378 'uniquemember': "cn=Nested Group 2, {}".format(DEFAULT_SUFFIX)
379 })
380
381 grp = UniqueGroup(topo.standalone, 'cn=Nested Group 2,' + DEFAULT_SUFFIX)
382 grp.create(properties={
383 'cn': 'Nested Group 2',
384 'ou': 'groups',
385 'uniquemember': "cn=Nested Group 3, {}".format(DEFAULT_SUFFIX)
386 })
387
388 grp = UniqueGroup(topo.standalone, 'cn=Nested Group 3,' + DEFAULT_SUFFIX)
389 grp.create(properties={
390 'cn': 'Nested Group 3',
391 'ou': 'groups',
392 'uniquemember': [USER_ANANDA, USER_ANUJ]
393 })
394
395 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", '(target = ldap:///{})(targetattr="*")'
396 '(version 3.0; acl "{}"; deny(read)(groupdn = "ldap:///cn=Nested Group 1, {}"); )'.format(DEFAULT_SUFFIX, request.node.name, DEFAULT_SUFFIX))
397 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
398 # deny_access_to_group_should_deny_access_to_all_uniquemember
399 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
400 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
401 # deny_access_to_group_should_deny_access_to_all_uniquemember
402 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
403 # with root there is no aci blockage
404 assert 4 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(cn=*)'))
405
406
407 def test_entry_with_lots_100_attributes(topo, add_test_user, aci_of_user):
408 """Search Test 39 entry with lots (>100) attributes
409
410 :id: fc155f74-6e12-11e8-96ac-8c16451d917b
411 :setup: Standalone Instance
412 :steps:
413 1. Add Entry
414 2. Bind with test USER_ANUJ
415 3. Try search
416 4. Delete Entry,test USER_ANUJ, ACI
417 :expectedresults:
418 1. Operation should success
419 3. Operation should success
420 4. Operation should success
421 5. Operation should success
422 """
423 for i in range(100):
424 user = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn='ou=People').create_test_user(uid=i)
425 user.set("userPassword", "password")
426
427 conn = UserAccount(topo.standalone, "uid=test_user_1,ou=People,{}".format(DEFAULT_SUFFIX)).bind(PW_DM)
428 # no aci no blockage
429 assert 1 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=Anuj*)'))
430 # no aci no blockage
431 assert 103 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(uid=*)'))
432 conn = Anonymous(topo.standalone).bind()
433 # anonymous_search_on_monitor_entry
434 assert 103 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(uid=*)'))
435
436
437 def test_groupdnattr_value_is_another_group(topo):
438 """Search Test 42 groupdnattr value is another group test #1
439
440 :id: 52299e16-7944-11e8-b471-8c16451d917b
441 :setup: server
442 :steps:
443 1. Add test entry
444 2. Add ACI
445 3. USER_ANUJ should follow ACI role
446 :expectedresults:
447 1. Entry should be added
448 2. Operation should succeed
449 3. Operation should succeed
450 """
451 Organization(topo.standalone).create(properties={"o": "nscpRoot"}, basedn=DEFAULT_SUFFIX)
452
453 user = UserAccount(topo.standalone, "cn=dchan,o=nscpRoot,{}".format(DEFAULT_SUFFIX))
454 user.create(properties={
455 'uid': 'dchan',
456 'cn': 'dchan',
457 'sn': 'user',
458 'uidNumber': '1000',
459 'gidNumber': '2000',
460 'homeDirectory': '/home/' + 'dchan',
461 'userPassword': PW_DM
462 })
463
464 grp = UniqueGroup(topo.standalone, 'cn=groupx,o=nscpRoot,' + DEFAULT_SUFFIX)
465 grp.create(properties={
466 'cn': 'groupx',
467 'ou': 'groups',
468 })
469 grp.set('uniquemember', 'cn=dchan,o=nscpRoot,{}'.format(DEFAULT_SUFFIX))
470 grp.set('aci', '(targetattr="*")(version 3.0; acl "Enable Group Expansion"; allow (read, search, compare) groupdnattr="ldap:///o=nscpRoot?uniquemember?sub";)')
471
472 conn = UserAccount(topo.standalone, 'cn=dchan,o=nscpRoot,{}'.format(DEFAULT_SUFFIX),).bind(PW_DM)
473 # acil will allow ldap:///o=nscpRoot?uniquemember?sub"
474 assert UserAccount(conn, 'cn=groupx,o=nscpRoot,{}'.format(DEFAULT_SUFFIX)).get_attr_val_utf8('cn') == 'groupx'
475
476
477 if __name__ == "__main__":
478 CURRENT_FILE = os.path.realpath(__file__)
479 pytest.main("-s -v %s" % CURRENT_FILE)