Debian Codegraph @

dirsrvtests/tests/suites/acl/search_real_part2_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.account import Accounts
13 from lib389.idm.organizationalunit import OrganizationalUnits
14 from test389.topologies import topology_st as topo
15 from lib389.idm.domain import Domain
16
17 pytestmark = pytest.mark.tier1
18
19 CONTAINER_1_DELADD = "ou=Product Development,{}".format(DEFAULT_SUFFIX)
20 CONTAINER_2_DELADD = "ou=Accounting,{}".format(DEFAULT_SUFFIX)
21 USER_ANUJ = "uid=Anuj Borah,{}".format(CONTAINER_1_DELADD)
22 USER_ANANDA = "uid=Ananda Borah,{}".format(CONTAINER_2_DELADD)
23
24
25 @pytest.fixture(scope="function")
26 def aci_of_user(request, topo):
27 # Add anonymous access aci
28 ACI_TARGET = "(targetattr != \"userpassword\")(target = \"ldap:///%s\")" % (DEFAULT_SUFFIX)
29 ACI_ALLOW = "(version 3.0; acl \"Anonymous Read access\"; allow (read,search,compare)"
30 ACI_SUBJECT = "(userdn=\"ldap:///anyone\");)"
31 ANON_ACI = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
32 suffix = Domain(topo.standalone, DEFAULT_SUFFIX)
33 try:
34 suffix.add('aci', ANON_ACI)
35 except ldap.TYPE_OR_VALUE_EXISTS:
36 pass
37
38 aci_list = Domain(topo.standalone, DEFAULT_SUFFIX).get_attr_vals('aci')
39
40 def finofaci():
41 domain = Domain(topo.standalone, DEFAULT_SUFFIX)
42 domain.set('aci', None)
43 for i in aci_list:
44 domain.add("aci", i)
45 pass
46
47 request.addfinalizer(finofaci)
48
49
50 @pytest.fixture(scope="module")
51 def add_test_user(request, topo):
52 topo.standalone.config.loglevel((ErrorLog.ACL_SUMMARY,))
53
54 ous = OrganizationalUnits(topo.standalone, DEFAULT_SUFFIX)
55 for i in ['Product Development', 'Accounting']:
56 ous.create(properties={'ou': i})
57
58 users = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn='ou=Product Development')
59 users.create(properties={
60 'uid': 'Anuj Borah',
61 'cn': 'Anuj Borah',
62 'sn': 'user',
63 'uidNumber': '1000',
64 'gidNumber': '2000',
65 'homeDirectory': '/home/' + 'AnujBorah',
66 'userPassword': PW_DM
67 })
68
69 users = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn='ou=Accounting')
70 users.create(properties={
71 'uid': 'Ananda Borah',
72 'cn': 'Ananda Borah',
73 'sn': 'user',
74 'uidNumber': '1000',
75 'gidNumber': '2000',
76 'homeDirectory': '/home/' + 'AnandaBorah',
77 'userPassword': PW_DM
78 })
79
80
81 def test_deny_all_access_with__target_set_on_non_leaf(topo, add_test_user, aci_of_user):
82 """Search Test 11 Deny all access with != target set on non-leaf
83
84 :id: f1c5d72a-6e11-11e8-aa9d-8c16451d917b
85 :setup: Standalone Instance
86 :steps:
87 1. Add Entry
88 2. Add ACI
89 3. Bind with test USER_ANUJ
90 4. Try search
91 5. Delete Entry,test USER_ANUJ, ACI
92 :expectedresults:
93 1. Operation should success
94 2. Operation should success
95 3. Operation should success
96 4. Operation should Fail
97 5. Operation should success
98 """
99 ACI_TARGET = "(target != ldap:///{})(targetattr=\"*\")".format(CONTAINER_2_DELADD)
100 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny absolute (all)'
101 ACI_SUBJECT = 'userdn="ldap:///anyone";)'
102 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
103 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
104 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
105 # After binding with USER_ANANDA , aci will limit the search to itself
106 assert 1 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
107 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
108 # After binding with USER_ANUJ , aci will limit the search to itself
109 assert 1 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
110 # After binding with root , the actual number of users will be given
111 assert 4 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(cn=*)'))
112
113
114 def test_deny_all_access_with__target_set_on_wildcard_non_leaf(
115 topo, add_test_user, aci_of_user
116 ):
117 """Search Test 12 Deny all access with != target set on wildcard non-leaf
118
119 :id: 02f34640-6e12-11e8-a382-8c16451d917b
120 :setup: Standalone Instance
121 :steps:
122 1. Add Entry
123 2. Add ACI
124 3. Bind with test USER_ANUJ
125 4. Try search
126 5. Delete Entry,test USER_ANUJ, ACI
127 :expectedresults:
128 1. Operation should success
129 2. Operation should success
130 3. Operation should success
131 4. Operation should Fail
132 5. Operation should success
133 """
134 ACI_TARGET = "(target != ldap:///ou=Product*,{})(targetattr=\"*\")".format(
135 DEFAULT_SUFFIX)
136 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny absolute (all)'
137 ACI_SUBJECT = 'userdn="ldap:///anyone";)'
138 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
139 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
140 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
141 # aci will limit the search to ou=Product it will block others
142 assert 1 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
143 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
144 # aci will limit the search to ou=Product it will block others
145 assert 1 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
146 # with root , aci will give actual no of users , without any limit.
147 assert 4 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(cn=*)'))
148
149
150 def test_deny_all_access_with__target_set_on_wildcard_leaf(
151 topo, add_test_user, aci_of_user
152 ):
153 """Search Test 13 Deny all access with != target set on wildcard leaf
154
155 :id: 16c54d76-6e12-11e8-b5ba-8c16451d917b
156 :setup: Standalone Instance
157 :steps:
158 1. Add Entry
159 2. Add ACI
160 3. Bind with test USER_ANUJ
161 4. Try search
162 5. Delete Entry,test USER_ANUJ, ACI
163 :expectedresults:
164 1. Operation should success
165 2. Operation should success
166 3. Operation should success
167 4. Operation should Fail
168 5. Operation should success
169 """
170 ACI_TARGET = "(target != ldap:///uid=Anuj*, ou=*,{})(targetattr=\"*\")".format(
171 DEFAULT_SUFFIX)
172 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny absolute (all)'
173 ACI_SUBJECT = 'userdn="ldap:///anyone";)'
174 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
175 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
176 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
177 # aci will limit the search to cn=Jeff it will block others
178 assert 1 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
179 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
180 # aci will limit the search to cn=Jeff it will block others
181 assert 1 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
182 # with root there is no aci blockage
183 assert 4 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(cn=*)'))
184
185
186 def test_deny_all_access_with_targetfilter_using_equality_search(
187 topo, add_test_user, aci_of_user
188 ):
189 """Search Test 14 Deny all access with targetfilter using equality search
190
191 :id: 27255e04-6e12-11e8-8e35-8c16451d917b
192 :setup: Standalone Instance
193 :steps:
194 1. Add Entry
195 2. Add ACI
196 3. Bind with test USER_ANUJ
197 4. Try search
198 5. Delete Entry,test USER_ANUJ, ACI
199 :expectedresults:
200 1. Operation should success
201 2. Operation should success
202 3. Operation should success
203 4. Operation should Fail
204 5. Operation should success
205 """
206 ACI_TARGET = '(targetfilter ="(uid=Anuj Borah)")(target = ldap:///{})(targetattr="*")'.format(
207 DEFAULT_SUFFIX)
208 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny absolute (all)'
209 ACI_SUBJECT = 'userdn="ldap:///anyone";)'
210 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
211 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
212 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
213 # aci will block the search to cn=Jeff
214 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(uid=Anuj Borah)'))
215 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
216 # aci will block the search to cn=Jeff
217 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(uid=Anuj Borah)'))
218 # with root there is no blockage
219 assert 1 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(uid=Anuj Borah)'))
220
221
222 def test_deny_all_access_with_targetfilter_using_equality_search_two(
223 topo, add_test_user, aci_of_user
224 ):
225 """Test that Search Test 15 Deny all access with targetfilter using != equality search
226
227 :id: 3966bcd4-6e12-11e8-83ce-8c16451d917b
228 :setup: Standalone Instance
229 :steps:
230 1. Add Entry
231 2. Add ACI
232 3. Bind with test USER_ANUJ
233 4. Try search
234 5. Delete Entry,test USER_ANUJ, ACI
235 :expectedresults:
236 1. Operation should success
237 2. Operation should success
238 3. Operation should success
239 4. Operation should Fail
240 5. Operation should success
241 """
242 ACI_TARGET = '(targetfilter !="(uid=Anuj Borah)")(target = ldap:///{})(targetattr="*")'.format(
243 DEFAULT_SUFFIX)
244 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny absolute (all)'
245 ACI_SUBJECT = 'userdn="ldap:///anyone";)'
246 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
247 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
248 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
249 # aci will limit the search to cn=Jeff it will block others
250 assert 1 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
251 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
252 # aci will limit the search to cn=Jeff it will block others
253 assert 1 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
254 # with root there is no blockage
255 assert 4 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(cn=*)'))
256
257
258 def test_deny_all_access_with_targetfilter_using_substring_search(
259 topo, add_test_user, aci_of_user
260 ):
261 """Test that Search Test 16 Deny all access with targetfilter using substring search
262
263 :id: 44d7b4ba-6e12-11e8-b420-8c16451d917b
264 :setup: Standalone Instance
265 :steps:
266 1. Add Entry
267 2. Add ACI
268 3. Bind with test USER_ANUJ
269 4. Try search
270 5. Delete Entry,test USER_ANUJ, ACI
271 :expectedresults:
272 1. Operation should success
273 2. Operation should success
274 3. Operation should success
275 4. Operation should Fail
276 5. Operation should success
277 """
278 ACI_TARGET = '(targetfilter ="(uid=Anu*)")(target = ldap:///{})(targetattr="*")'.format(
279 DEFAULT_SUFFIX)
280 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny absolute (all)'
281 ACI_SUBJECT = 'userdn="ldap:///anyone";)'
282 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
283 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
284 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
285 # aci block anything cn=j*
286 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=Anu*)'))
287 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
288 # aci block anything cn=j*
289 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=Anu*)'))
290 # with root there is no blockage
291 assert 1 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(cn=Anu*)'))
292
293
294 def test_deny_all_access_with_targetfilter_using_substring_search_two(
295 topo, add_test_user, aci_of_user
296 ):
297 """Test that Search Test 17 Deny all access with targetfilter using != substring search
298
299 :id: 55b12d98-6e12-11e8-8cf4-8c16451d917b
300 :setup: Standalone Instance
301 :steps:
302 1. Add Entry
303 2. Add ACI
304 3. Bind with test USER_ANUJ
305 4. Try search
306 5. Delete Entry,test USER_ANUJ, ACI
307 :expectedresults:
308 1. Operation should success
309 2. Operation should success
310 3. Operation should success
311 4. Operation should Fail
312 5. Operation should success
313 """
314 ACI_TARGET = '(targetfilter !="(uid=Anu*)")(target = ldap:///{})(targetattr="*")'.format(
315 DEFAULT_SUFFIX
316 )
317 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny (all)'
318 ACI_SUBJECT = 'userdn="ldap:///anyone";)'
319 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
320 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
321 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
322 # aci allow anything cn=j*, it will block others
323 assert 1 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(uid=*)'))
324 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
325 # aci allow anything cn=j*, it will block others
326 assert 1 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(uid=*)'))
327 # with root there is no blockage
328 assert 3 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(uid=*)'))
329
330
331 def test_deny_all_access_with_targetfilter_using_boolean_or_of_two_equality_search(
332 topo, add_test_user, aci_of_user, request
333 ):
334 """Search Test 18 Deny all access with targetfilter using boolean OR of two equality search
335
336 :id: 29cc35fa-793f-11e8-988f-8c16451d917b
337 :setup: Standalone Instance
338 :steps:
339 1. Add Entry
340 2. Add ACI
341 3. Bind with test USER_ANUJ
342 4. Try search
343 5. Delete Entry,test USER_ANUJ, ACI
344 :expectedresults:
345 1. Operation should success
346 2. Operation should success
347 3. Operation should success
348 4. Operation should Fail
349 5. Operation should success
350 """
351 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci",'(target = ldap:///{})(targetattr = "*")'
352 '(targetfilter = (|(cn=scarter)(cn=jvaughan)))(version 3.0; acl "{}"; '
353 'deny absolute (all) (userdn = "ldap:///anyone") ;)'.format(DEFAULT_SUFFIX, request.node.name))
354 UserAccount(topo.standalone, USER_ANANDA).set("cn", "scarter")
355 UserAccount(topo.standalone, USER_ANUJ).set("cn", "jvaughan")
356 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
357 # aci will deny_all_access_with_targetfilter_using_boolean_or_of_two_equality_search
358 user = UserAccount(conn, USER_ANANDA)
359 assert len(user.get_attr_val_utf8('uid')) == 0
360 # aci will deny_all_access_with_targetfilter_using_boolean_or_of_two_equality_search
361 user = UserAccount(conn, USER_ANUJ)
362 assert len(user.get_attr_val_utf8('uid')) == 0
363 # with root no blockage
364 assert UserAccount(topo.standalone, USER_ANANDA).get_attr_val_utf8('uid') == 'Ananda Borah'
365 # with root no blockage
366 assert UserAccount(topo.standalone, USER_ANUJ).get_attr_val_utf8('uid') == 'Anuj Borah'
367
368
369 def test_deny_all_access_to__userdn_two(topo, add_test_user, aci_of_user):
370 """Search Test 19 Deny all access to != userdn
371
372 :id: 693496c0-6e12-11e8-80dc-8c16451d917b
373 :setup: Standalone Instance
374 :steps:
375 1. Add Entry
376 2. Add ACI
377 3. Bind with test USER_ANUJ
378 4. Try search
379 5. Delete Entry,test USER_ANUJ, ACI
380 :expectedresults:
381 1. Operation should success
382 2. Operation should success
383 3. Operation should success
384 4. Operation should Fail
385 5. Operation should success
386 """
387 ACI_TARGET = "(target = ldap:///{})(targetattr=\"*\")".format(DEFAULT_SUFFIX)
388 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny absolute (all)'
389 ACI_SUBJECT = 'userdn!="ldap:///{}";)'.format(USER_ANANDA)
390 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
391 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
392 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
393 # aci will not block anything for USER_ANANDA , it block other users
394 assert 4 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
395 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
396 # aci will block everything for other users
397 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
398 # with root there is no aci blockage
399 assert 4 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(cn=*)'))
400
401
402 def test_deny_all_access_with_userdn(topo, add_test_user, aci_of_user):
403 """Search Test 20 Deny all access with userdn
404
405 :id: 75aada86-6e12-11e8-bd34-8c16451d917b
406 :setup: Standalone Instance
407 :steps:
408 1. Add Entry
409 2. Add ACI
410 3. Bind with test USER_ANUJ
411 4. Try search
412 5. Delete Entry,test USER_ANUJ, ACI
413 :expectedresults:
414 1. Operation should success
415 2. Operation should success
416 3. Operation should success
417 4. Operation should Fail
418 5. Operation should success
419 """
420 ACI_TARGET = "(target = ldap:///{})(targetattr=\"*\")".format(DEFAULT_SUFFIX)
421 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny (all)'
422 ACI_SUBJECT = 'userdn="ldap:///{}";)'.format(USER_ANANDA)
423 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
424 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
425 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
426 # aci will block anything for USER_ANANDA , it not block other users
427 assert 0 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
428 conn = UserAccount(topo.standalone, USER_ANUJ).bind(PW_DM)
429 # aci will block anything for other users
430 assert 4 == len(Accounts(conn, DEFAULT_SUFFIX).filter('(cn=*)'))
431 # with root thers is no aci blockage
432 assert 4 == len(Accounts(topo.standalone, DEFAULT_SUFFIX).filter('(cn=*)'))
433
434
435 def test_deny_all_access_with_targetfilter_using_presence_search(
436 topo, add_test_user, aci_of_user
437 ):
438 """Search Test 21 Deny all access with targetfilter using presence search
439
440 :id: 85244a42-6e12-11e8-9480-8c16451d917b
441 :setup: Standalone Instance
442 :steps:
443 1. Add Entry
444 2. Add ACI
445 3. Bind with test USER_ANUJ
446 4. Try search
447 5. Delete Entry,test USER_ANUJ, ACI
448 :expectedresults:
449 1. Operation should success
450 2. Operation should success
451 3. Operation should success
452 4. Operation should Fail
453 5. Operation should success
454 """
455 user = UserAccounts(topo.standalone, DEFAULT_SUFFIX).create_test_user()
456 user.set('userPassword', PW_DM)
457
458 ACI_TARGET = '(targetfilter ="(cn=*)")(target = ldap:///{})(targetattr="*")'.format(
459 DEFAULT_SUFFIX)
460 ACI_ALLOW = '(version 3.0; acl "Name of the ACI"; deny absolute (all)'
461 ACI_SUBJECT = 'userdn="ldap:///anyone";)'
462 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
463 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
464 conn = UserAccount(topo.standalone, USER_ANANDA).bind(PW_DM)
465 # aci will eny_all_access_with_targetfilter_using_presence_search
466 user = UserAccount(conn, 'uid=test_user_1000,ou=People,{}'.format(DEFAULT_SUFFIX))
467 assert len(user.get_attr_val_utf8('cn')) == 0
468 # with root no blockage
469 assert UserAccount(topo.standalone, 'uid=test_user_1000,ou=People,{}'.format(DEFAULT_SUFFIX)).get_attr_val_utf8('cn') == 'test_user_1000'
470
471
472 if __name__ == "__main__":
473 CURRENT_FILE = os.path.realpath(__file__)
474 pytest.main("-s -v %s" % CURRENT_FILE)