Debian Codegraph @

dirsrvtests/tests/suites/acl/valueacl_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
11 from lib389.idm.user import UserAccount
12 from lib389.idm.account import Anonymous
13 from lib389.idm.organizationalunit import OrganizationalUnit
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_DELADD = "cn=Jeff Vedder,{}".format(CONTAINER_1_DELADD)
22 USER_WITH_ACI_DELADD = "cn=Sam Carter,{}".format(CONTAINER_2_DELADD)
23 FRED = "cn=FRED,ou=Accounting,{}".format(DEFAULT_SUFFIX)
24 HARRY = "cn=HARRY,ou=Accounting,{}".format(DEFAULT_SUFFIX)
25 KIRSTENVAUGHAN = "cn=Kirsten Vaughan,ou=Human Resources,{}".format(DEFAULT_SUFFIX)
26 HUMAN_OU_GLOBAL = "ou=Human Resources,{}".format(DEFAULT_SUFFIX)
27
28
29 @pytest.fixture(scope="function")
30 def aci_of_user(request, topo):
31 # Add anonymous access aci
32 ACI_TARGET = "(targetattr != \"userpassword\")(target = \"ldap:///%s\")" % (DEFAULT_SUFFIX)
33 ACI_ALLOW = "(version 3.0; acl \"Anonymous Read access\"; allow (read,search,compare)"
34 ACI_SUBJECT = "(userdn=\"ldap:///anyone\");)"
35 ANON_ACI = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
36 suffix = Domain(topo.standalone, DEFAULT_SUFFIX)
37 try:
38 suffix.add('aci', ANON_ACI)
39 except ldap.TYPE_OR_VALUE_EXISTS:
40 pass
41
42 aci_list = Domain(topo.standalone, DEFAULT_SUFFIX).get_attr_vals('aci')
43
44 def finofaci():
45 domain = Domain(topo.standalone, DEFAULT_SUFFIX)
46 domain.set('aci', None)
47 for i in aci_list:
48 domain.add("aci", i)
49
50 request.addfinalizer(finofaci)
51
52
53 @pytest.fixture(scope="function")
54 def _add_user(request, topo):
55 for i in ["Product Development", 'Accounting', "Human Resources"]:
56 ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX))
57 ou.create(properties={'ou': i})
58
59 properties = {
60 'uid': 'Jeff Vedder',
61 'cn': 'Jeff Vedder',
62 'sn': 'user',
63 'uidNumber': '1000',
64 'gidNumber': '2000',
65 'homeDirectory': '/home/' + 'JeffVedder',
66 'userPassword': 'password'
67 }
68 user = UserAccount(topo.standalone, 'cn=Jeff Vedder,{}'.format(CONTAINER_1_DELADD))
69 user.create(properties=properties)
70 user.set('secretary', 'cn=Arpitoo Borah, o=Red Hat, c=As')
71 user.set('mail', '[email protected]')
72
73 properties = {
74 'uid': 'Sam Carter',
75 'cn': 'Sam Carter',
76 'sn': 'user',
77 'uidNumber': '1000',
78 'gidNumber': '2000',
79 'homeDirectory': '/home/' + 'SamCarter',
80 'userPassword': 'password'
81 }
82 user = UserAccount(topo.standalone, 'cn=Sam Carter,{}'.format(CONTAINER_2_DELADD))
83 user.create(properties=properties)
84
85 properties = {
86 'uid': 'Kirsten Vaughan',
87 'cn': 'Kirsten Vaughan',
88 'sn': 'Kirsten Vaughan',
89 'uidNumber': '1000',
90 'gidNumber': '2000',
91 'homeDirectory': '/home/' + 'KirstenVaughan',
92 'userPassword': 'password'
93 }
94 user = UserAccount(topo.standalone, 'cn=Kirsten Vaughan, ou=Human Resources,{}'.format(DEFAULT_SUFFIX))
95 user.create(properties=properties)
96
97 properties = {
98 'uid': 'HARRY',
99 'cn': 'HARRY',
100 'sn': 'HARRY',
101 'uidNumber': '1000',
102 'gidNumber': '2000',
103 'homeDirectory': '/home/' + 'HARRY',
104 'userPassword': 'password'
105 }
106 user = UserAccount(topo.standalone, 'cn=HARRY, ou=Accounting,{}'.format(DEFAULT_SUFFIX))
107 user.create(properties=properties)
108
109 def fin():
110 for DN in [USER_DELADD, USER_WITH_ACI_DELADD, FRED, HARRY, KIRSTENVAUGHAN,
111 HUMAN_OU_GLOBAL, CONTAINER_2_DELADD,CONTAINER_1_DELADD]:
112 ua = UserAccount(topo.standalone, DN)
113 try:
114 ua.delete()
115 except:
116 pass
117
118 request.addfinalizer(fin)
119
120
121 class _ModTitleArchitectJeffVedder:
122 def __init__(self, topo, value, conn):
123 self.topo = topo
124 self.value = value
125 self.conn = conn
126 self.user = UserAccount(self.conn, USER_DELADD)
127
128 def add(self):
129 self.user.add("title", self.value)
130
131 def delete(self):
132 self.user.remove("title", self.value)
133
134
135 class _DelTitleArchitectJeffVedder:
136 def __init__(self, topo, conn):
137 self.topo = topo
138 self.conn = conn
139
140 def delete(self):
141 UserAccount(self.conn, USER_DELADD).remove("title", None)
142
143
144 class _AddTitleWithRoot:
145 def __init__(self, topo, value):
146 self.topo = topo
147 self.value = value
148 self.user = UserAccount(self.topo.standalone, USER_DELADD)
149
150 def add(self):
151 self.user.add("title", self.value)
152
153 def delete(self):
154 self.user.remove("title", self.value)
155
156
157 class _AddFREDWithRoot:
158 def __init__(self, topo, title1, title2, title3):
159 self.topo = topo
160 self.title1 = title1
161 self.title2 = title2
162 self.title3 = title3
163
164 def create(self):
165 properties = {
166 'uid': 'FRED',
167 'cn': 'FRED',
168 'sn': 'user',
169 'uidNumber': '1000',
170 'gidNumber': '2000',
171 'homeDirectory': '/home/' + 'FRED'
172 }
173 user = UserAccount(self.topo.standalone, "cn=FRED, ou=Accounting,{}".format(DEFAULT_SUFFIX))
174 user.create(properties=properties)
175 user.set("title", [self.title1, self.title2, self.title3])
176
177
178 def test_delete_an_attribute_value_we_are_not_allowed_to_delete(
179 topo, _add_user, aci_of_user
180 ):
181 """Testing the targattrfilters keyword that allows access control based on the value
182 of the attributes being added (or deleted))
183 Test that we can MODIFY:add an attribute value we are allowed to add
184
185 :id: 7c41baa6-7aa9-11e8-9bdc-8c16451d917b
186 :setup: server
187 :steps:
188 1. Add test entry
189 2. Add ACI
190 3. User should follow ACI role
191 :expectedresults:
192 1. Entry should be added
193 2. Operation should succeed
194 3. Operation should succeed
195 """
196 ACI_BODY = '(targattrfilters = "add=title:(title=architect), del=title:(title=architect)")' \
197 '(version 3.0; acl "ACI NAME"; allow (write) (userdn = "ldap:///{}") ;)'.format(USER_WITH_ACI_DELADD)
198 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
199 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
200 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
201 _ModTitleArchitectJeffVedder(topo, "engineer", conn).add()
202 _ModTitleArchitectJeffVedder(topo, "architect", conn).add()
203
204
205 def test_donot_allow_write_access_to_title_if_value_is_not_architect(
206 topo, _add_user, aci_of_user, request
207 ):
208 """Testing the targattrfilters keyword that allows access control based on the value of the
209 attributes being added (or deleted))
210 Test that we cannot MODIFY:add an attribute value we are not allowed to add
211
212 :id: 822c607e-7aa9-11e8-b2e7-8c16451d917b
213 :setup: server
214 :steps:
215 1. Add test entry
216 2. Add ACI
217 3. User should follow ACI role
218 :expectedresults:
219 1. Entry should be added
220 2. Operation should succeed
221 3. Operation should succeed
222 """
223 ACI_BODY = '(targattrfilters = "add=title:(title=architect), del=title:(title=architect)")' \
224 '(version 3.0; acl "{}"; allow (write) (userdn = "ldap:///{}") ;)'.format(request.node.name, USER_WITH_ACI_DELADD)
225 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
226 # aci will allow to add title architect
227 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
228 _ModTitleArchitectJeffVedder(topo, "architect", conn).add()
229 # aci will noo allow to add title architect1
230 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
231 _ModTitleArchitectJeffVedder(topo, "architect1", conn).add()
232
233
234 def test_delete_an_attribute_value_we_are_allowed_to_delete(
235 topo, _add_user, aci_of_user, request
236 ):
237 """Testing the targattrfilters keyword that allows access control based on the value of
238 the attributes being added (or deleted))
239 Test that we can MODIFY:delete an attribute value we are allowed to delete
240
241 :id: 86f36b34-7aa9-11e8-ab16-8c16451d917b
242 :setup: server
243 :steps:
244 1. Add test entry
245 2. Add ACI
246 3. User should follow ACI role
247 :expectedresults:
248 1. Entry should be added
249 2. Operation should succeed
250 3. Operation should succeed
251 """
252 ACI_BODY = '(targattrfilters = "add=title:(title=architect), del=title:(title=architect)")' \
253 '(version 3.0; acl "{}"; allow (write) (userdn = "ldap:///{}") ;)'.format(request.node.name, USER_WITH_ACI_DELADD)
254 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
255 _AddTitleWithRoot(topo, "architect").add()
256 # aci will allow to delete title architect
257 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
258 r1 = _ModTitleArchitectJeffVedder(topo, "architect", conn)
259 r1.delete()
260
261
262 def test_delete_an_attribute_value_we_are_not_allowed_to_deleted(
263 topo, _add_user, aci_of_user, request
264 ):
265 """Testing the targattrfilters keyword that allows access control based on the value of the
266 attributes being added (or deleted))
267 Test that we cannot MODIFY:delete an attribute value we are allowed to delete
268
269 :id: 8c9f3a90-7aa9-11e8-bf2e-8c16451d917b
270 :setup: server
271 :steps:
272 1. Add test entry
273 2. Add ACI
274 3. User should follow ACI role
275 :expectedresults:
276 1. Entry should be added
277 2. Operation should succeed
278 3. Operation should succeed
279 """
280 ACI_BODY = '(targattrfilters = "add=title:(title=architect), del=title:(title=architect)")' \
281 '(version 3.0; acl "{}"; allow (write) (userdn = "ldap:///{}") ;)'.format(request.node.name, USER_WITH_ACI_DELADD)
282 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
283 _AddTitleWithRoot(topo, "engineer").add()
284 # acl will not allow to delete title engineer
285 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
286 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
287 _ModTitleArchitectJeffVedder(topo, "engineer", conn).delete()
288
289
290 def test_allow_modify_replace(topo, _add_user, aci_of_user, request):
291 """Testing the targattrfilters keyword that allows access control based on the value of the
292 attributes being added (or deleted))
293 Test that we can MODIFY:replace an attribute if we have correct add/delete rights.
294
295 :id: 9148a234-7aa9-11e8-a1f1-8c16451d917b
296 :setup: server
297 :steps:
298 1. Add test entry
299 2. Add ACI
300 3. User should follow ACI role
301 :expectedresults:
302 1. Entry should be added
303 2. Operation should succeed
304 3. Operation should succeed
305 """
306 ACI_BODY = '(targattrfilters = "add=title:(title=engineer), del=title:(|(title=architect)' \
307 '(title=idiot))")(version 3.0; acl "{}"; ' \
308 'allow (write) (userdn = "ldap:///{}") ;)'.format(request.node.name, USER_WITH_ACI_DELADD)
309 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
310 _AddTitleWithRoot(topo, "architect").add()
311 _AddTitleWithRoot(topo, "idiot").add()
312 _AddTitleWithRoot(topo, "engineer").add()
313 # acl will not allow to delete title engineer
314 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
315 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
316 _ModTitleArchitectJeffVedder(topo, "engineer", conn).delete()
317
318
319 def test_allow_modify_delete(topo, _add_user, aci_of_user, request):
320 """Testing the targattrfilters keyword that allows access control based on the value of the
321 attributes being added (or deleted))
322 Don't Allow modify:replace because of lack of delete rights
323
324 :id: 962842d2-7aa9-11e8-b39e-8c16451d917b
325 :setup: server
326 :steps:
327 1. Add test entry
328 2. Add ACI
329 3. User should follow ACI role
330 :expectedresults:
331 1. Entry should be added
332 2. Operation should succeed
333 3. Operation should succeed
334 """
335 ACI_BODY = '(targattrfilters = "add=title:(title=engineer), del=title:(|(title=architect))")' \
336 '(version 3.0; acl "{}"; allow (write) ' \
337 '(userdn = "ldap:///{}") ;)'.format(request.node.name, USER_WITH_ACI_DELADD)
338 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
339 _AddTitleWithRoot(topo, "architect").add()
340 _AddTitleWithRoot(topo, "idiot").add()
341 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
342 _ModTitleArchitectJeffVedder(topo, "architect", conn).delete()
343 # acl will not allow to delete title idiot
344 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
345 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
346 _ModTitleArchitectJeffVedder(topo, "idiot", conn).delete()
347
348
349 def test_replace_an_attribute_if_we_lack(topo, _add_user, aci_of_user, request):
350 """Testing the targattrfilters keyword that allows access control based on the value of the
351 attributes being added (or deleted))
352 Test that we cannot MODIFY:replace an attribute if we lack
353
354 :id: 9b1e6afa-7aa9-11e8-ac5b-8c16451d917b
355 :setup: server
356 :steps:
357 1. Add test entry
358 2. Add ACI
359 3. User should follow ACI role
360 :expectedresults:
361 1. Entry should be added
362 2. Operation should succeed
363 3. Operation should succeed
364 """
365 ACI_BODY = '(targattrfilters = "add=title:(title=engineer), del=title:(|(title=architect))")' \
366 '(version 3.0; acl "{}"; allow (write) ' \
367 '(userdn = "ldap:///{}") ;)'.format(request.node.name, USER_WITH_ACI_DELADD)
368 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
369 _AddTitleWithRoot(topo, "architect").add()
370 _AddTitleWithRoot(topo, "idiot").add()
371 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
372 _ModTitleArchitectJeffVedder(topo, "architect", conn).delete()
373 # acl will not allow to delete title idiot
374 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
375 _ModTitleArchitectJeffVedder(topo, "idiot", conn).delete()
376
377
378 def test_remove_an_attribute_if_we_have_del_rights_to_all_attr_value(
379 topo, _add_user, aci_of_user, request
380 ):
381 """Testing the targattrfilters keyword that allows access control based on the value of the
382 attributes being added (or deleted))
383 Test that we can use MODIFY:delete to entirely remove an attribute if we have del rights
384 to all attr values negative case tested next.
385
386 :id: a0c9e0c4-7aa9-11e8-8880-8c16451d917b
387 :setup: server
388 :steps:
389 1. Add test entry
390 2. Add ACI
391 3. User should follow ACI role
392 :expectedresults:
393 1. Entry should be added
394 2. Operation should succeed
395 3. Operation should succeed
396 """
397 ACI_BODY = '(targattrfilters = "add=title:(title=engineer), del=title:(|(title=architect)' \
398 '(title=idiot))")(version 3.0; acl "{}"; allow (write)' \
399 ' (userdn = "ldap:///{}") ;)'.format(request.node.name, USER_WITH_ACI_DELADD)
400 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
401 _AddTitleWithRoot(topo, "architect").add()
402 _AddTitleWithRoot(topo, "idiot").add()
403 # acl will allow to delete title idiot
404 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
405 _DelTitleArchitectJeffVedder(topo,conn).delete()
406
407
408 def test_remove_an_attribute_if_we_donot_have_del_rights_to_all_attr_value(
409 topo, _add_user, aci_of_user, request
410 ):
411 """Testing the targattrfilters keyword that allows access control based on the value of the
412 attributes being added (or deleted))
413 Test that we can use MODIFY:delete to entirely remove an attribute if we have not del
414 rights to all attr values
415
416 :id: a6862eaa-7aa9-11e8-8bf9-8c16451d917b
417 :setup: server
418 :steps:
419 1. Add test entry
420 2. Add ACI
421 3. User should follow ACI role
422 :expectedresults:
423 1. Entry should be added
424 2. Operation should succeed
425 3. Operation should succeed
426 """
427 ACI_BODY = '(targattrfilters = "add=title:(title=engineer), del=title:(|(title=architect)' \
428 '(title=idiot))")(version 3.0; acl "{}"; allow (write) ' \
429 '(userdn = "ldap:///{}") ;)'.format(request.node.name, USER_WITH_ACI_DELADD)
430 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
431 _AddTitleWithRoot(topo, "architect").add()
432 _AddTitleWithRoot(topo, "sailor").add()
433 # aci will not allow to delete all titles
434 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
435 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
436 _DelTitleArchitectJeffVedder(topo, conn).delete()
437
438
439 def test_remove_an_attribute_if_we_have_del_rights_to_all_attr_values(
440 topo, _add_user, aci_of_user, request
441 ):
442 """Testing the targattrfilters keyword that allows access control based on the value of the
443 attributes being added (or deleted))
444 Test that we can use MODIFY:replace to entirely remove an attribute if we have del rights to all attr values
445
446 :id: ab04c7e8-7aa9-11e8-84db-8c16451d917b
447 :setup: server
448 :steps:
449 1. Add test entry
450 2. Add ACI
451 3. User should follow ACI role
452 :expectedresults:
453 1. Entry should be added
454 2. Operation should succeed
455 3. Operation should succeed
456 """
457 ACI_BODY = '(targattrfilters = "add=title:(title=engineer), del=title:(|(title=architect)' \
458 '(title=idiot))")(version 3.0; acl "{}"; allow (write) ' \
459 '(userdn = "ldap:///{}") ;)'.format(request.node.name, USER_WITH_ACI_DELADD)
460 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
461 _AddTitleWithRoot(topo, "architect").add()
462 _AddTitleWithRoot(topo, "idiot").add()
463 # aci allowing to delete an_attribute_if_we_have_del_rights_to_all_attr_values
464 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
465 _DelTitleArchitectJeffVedder(topo, conn).delete()
466
467
468 def test_cantnot_delete_an_entry_with_attribute_values_we_are_not_allowed_delete(
469 topo, _add_user, aci_of_user, request
470 ):
471 """Testing the targattrfilters keyword that allows access control based on the value of
472 the attributes being added (or deleted))
473 Test we cannot DELETE an entry with attribute values we are not allowed delete
474
475 :id: b525d94c-7aa9-11e8-8539-8c16451d917b
476 :setup: server
477 :steps:
478 1. Add test entry
479 2. Add ACI
480 3. User should follow ACI role
481 :expectedresults:
482 1. Entry should be added
483 2. Operation should succeed
484 3. Operation should succeed
485 """
486 ACI_BODY = '(targattrfilters = "add=title:(|(title=engineer)(title=cool dude)(title=scum)), ' \
487 'del=title:(|(title=engineer)(title=cool dude)(title=scum))")(version 3.0; ' \
488 'aci "{}"; allow (delete) userdn = "ldap:///{}";)'.format(request.node.name, USER_WITH_ACI_DELADD)
489 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
490 _AddFREDWithRoot(topo, "engineer", "cool dude", "ANuj").create()
491 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
492 # aci will not allow to delete
493 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
494 UserAccount(conn, FRED).delete()
495
496
497 def test_we_can_add_and_delete_an_entry_with_attribute_values_we_are_allowed_add_and_delete(
498 topo, _add_user, aci_of_user, request
499 ):
500 """Testing the targattrfilters keyword that allows access control based on the value of the
501 attributes being added (or deleted))
502 Test we can DELETE an entry with attribute values we are allowed delete
503
504 :id: ba138e54-7aa9-11e8-8037-8c16451d917b
505 :setup: server
506 :steps:
507 1. Add test entry
508 2. Add ACI
509 3. User should follow ACI role
510 :expectedresults:
511 1. Entry should be added
512 2. Operation should succeed
513 3. Operation should succeed
514 """
515 ACI_BODY = '(targattrfilters = "add=title:(|(title=engineer)(title=cool dude)(title=scum)), ' \
516 'del=title:(|(title=engineer)(title=cool dude)(title=scum))")(version 3.0; ' \
517 'aci "{}"; allow (delete) userdn = "ldap:///{}";)'.format(request.node.name, USER_WITH_ACI_DELADD)
518 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
519 _AddFREDWithRoot(topo, "engineer", "cool dude", "scum").create()
520 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
521 # aci will allow to delete
522 UserAccount(conn, FRED).delete()
523
524
525 def test_allow_title(topo, _add_user, aci_of_user, request):
526 """Testing the targattrfilters keyword that allows access control based on the value of the
527 attributes being added (or deleted))
528 Test that if attr appears in targetattr and in targattrfilters then targattrfilters
529 applies--ie. targattrfilters is a refinement of targattrfilters.
530
531 :id: beadf328-7aa9-11e8-bb08-8c16451d917b
532 :setup: server
533 :steps:
534 1. Add test entry
535 2. Add ACI
536 3. User should follow ACI role
537 :expectedresults:
538 1. Entry should be added
539 2. Operation should succeed
540 3. Operation should succeed
541 """
542 ACI_BODY = '(targetattr="title")(targattrfilters = "add=title:(|(title=engineer)' \
543 '(title=cool dude)(title=scum)), del=title:(|(title=engineer)(title=cool dude)' \
544 '(title=scum))")(version 3.0; aci "{}"; allow (write) ' \
545 'userdn = "ldap:///{}";)'.format(request.node.name, USER_WITH_ACI_DELADD)
546 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
547 _AddTitleWithRoot(topo, "engineer").add()
548 _AddTitleWithRoot(topo, "cool dude").add()
549 # # aci will not allow to add title topdog
550 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
551 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
552 _ModTitleArchitectJeffVedder(topo, "topdog", conn).add()
553
554
555 def test_allow_to_modify(topo, _add_user, aci_of_user, request):
556 """Testing the targattrfilters keyword that allows access control based on the value of the
557 attributes being added (or deleted))
558 Test that I can have secretary in targetattr and title in targattrfilters.
559
560 :id: c32e4704-7aa9-11e8-951d-8c16451d917b
561 :setup: server
562 :steps:
563 1. Add test entry
564 2. Add ACI
565 3. User should follow ACI role
566 :expectedresults:
567 1. Entry should be added
568 2. Operation should succeed
569 3. Operation should succeed
570 """
571 ACI_BODY = '(targetattr="secretary")(targattrfilters = "add=title:(|(title=engineer)' \
572 '(title=cool dude)(title=scum)), del=title:(|(title=engineer)(title=cool dude)' \
573 '(title=scum))")(version 3.0; aci "{}"; allow (write)' \
574 ' userdn = "ldap:///{}";)'.format(request.node.name, USER_WITH_ACI_DELADD)
575 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
576 _AddTitleWithRoot(topo, "engineer").add()
577 _AddTitleWithRoot(topo, "cool dude").add()
578 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
579 user = UserAccount(conn, USER_DELADD)
580 # aci will allow to add 'secretary', "cn=emporte quoi
581 user.add('secretary', "cn=emporte quoi, {}".format(DEFAULT_SUFFIX))
582 assert user.get_attr_val('secretary')
583
584
585 def test_selfwrite_does_not_confer_write_on_a_targattrfilters_atribute(topo, _add_user, aci_of_user, request):
586 """Testing the targattrfilters keyword that allows access control based on the value of
587 the attributes being added (or deleted))
588 Selfwrite does not confer "write" on a targattrfilters atribute.
589
590 :id: c7b9ec2e-7aa9-11e8-ba4a-8c16451d917b
591 :setup: server
592 :steps:
593 1. Add test entry
594 2. Add ACI
595 3. User should follow ACI role
596 :expectedresults:
597 1. Entry should be added
598 2. Operation should succeed
599 3. Operation should succeed
600 """
601 ACI_BODY = '(targattrfilters = "add=title:(|(title=engineer)(title=cool dude)(title=scum)), ' \
602 'del=title:(|(title=engineer)(title=cool dude)(title=scum))")(version 3.0; ' \
603 'aci "{}"; allow (selfwrite) userdn = "ldap:///{}";)'.format(request.node.name, USER_WITH_ACI_DELADD)
604 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
605 # aci will not allow to add selfwrite_does_not_confer_write_on_a_targattrfilters_atribute
606 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
607 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
608 _ModTitleArchitectJeffVedder(topo, "engineer", conn).add()
609
610
611 def test_selfwrite_continues_to_give_rights_to_attr_in_targetattr_list(
612 topo, _add_user, aci_of_user, request
613 ):
614 """Testing the targattrfilters keyword that allows access control based on the value of
615 the attributes being added (or deleted))
616 Selfwrite continues to give rights to attr in targetattr list.
617
618 :id: cd287680-7aa9-11e8-a8e2-8c16451d917b
619 :setup: server
620 :steps:
621 1. Add test entry
622 2. Add ACI
623 3. User should follow ACI role
624 :expectedresults:
625 1. Entry should be added
626 2. Operation should succeed
627 3. Operation should succeed
628 """
629 ACI_BODY = '(targetattr="secretary")(targattrfilters = "add=title:(|(title=engineer)' \
630 '(title=cool dude)(title=scum)), del=title:(|(title=engineer)(title=cool dude)' \
631 '(title=scum))")(version 3.0; aci "{}"; allow (selfwrite) ' \
632 'userdn = "ldap:///{}";)'.format(request.node.name, USER_WITH_ACI_DELADD)
633 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
634 # selfwrite_continues_to_give_rights_to_attr_in_targetattr_list
635 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
636 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
637 _ModTitleArchitectJeffVedder(topo, "engineer", conn).add()
638
639
640 def test_add_an_attribute_value_we_are_allowed_to_add_with_ldapanyone(
641 topo, _add_user, aci_of_user, request
642 ):
643 """Testing the targattrfilters keyword that allows access control based on the value of the
644 attributes being added (or deleted))
645 Test that we can MODIFY:add an attribute value we are allowed to add with ldap:///anyone
646
647 :id: d1e1d7ac-7aa9-11e8-b968-8c16451d917b
648 :setup: server
649 :steps:
650 1. Add test entry
651 2. Add ACI
652 3. User should follow ACI role
653 :expectedresults:
654 1. Entry should be added
655 2. Operation should succeed
656 3. Operation should succeed
657 """
658 ACI_BODY = '(targattrfilters = "add=title:(title=architect), del=title:(title=architect)")' \
659 '(version 3.0; acl "{}"; allow (write) userdn = "ldap:///anyone";)'.format(request.node.name)
660 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
661 _AddTitleWithRoot(topo, "engineer").add()
662 # aci will allow to add title architect
663 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
664 _ModTitleArchitectJeffVedder(topo, "architect", conn).add()
665
666
667 def test_hierarchy(topo, _add_user, aci_of_user, request):
668 """Testing the targattrfilters keyword that allows access control based on the value of
669 the attributes being added (or deleted))
670 Test that with two targattrfilters in the hierarchy that the general one applies.
671 This is the correct behaviour, even if it's a bit confusing
672
673 :id: d7ae354a-7aa9-11e8-8b0d-8c16451d917b
674 :setup: server
675 :steps:
676 1. Add test entry
677 2. Add ACI
678 3. User should follow ACI role
679 :expectedresults:
680 1. Entry should be added
681 2. Operation should succeed
682 3. Operation should succeed
683 """
684 ACI_BODY = '(targattrfilters = "add=title:(title=arch*)")(version 3.0; acl "{}"; ' \
685 'allow (write) (userdn = "ldap:///anyone") ;)'.format(request.node.name)
686 ACI_BODY1 = '(targattrfilters = "add=title:(title=architect)")(version 3.0; ' \
687 'acl "{}"; allow (write) (userdn = "ldap:///anyone") ;)'.format(request.node.name)
688 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
689 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY1)
690 _AddTitleWithRoot(topo, "engineer").add()
691 # aci will allow to add title architect
692 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
693 _ModTitleArchitectJeffVedder(topo, "architect", conn).add()
694 # aci will not allow to add title architect
695 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
696 _ModTitleArchitectJeffVedder(topo, "engineer", conn).add()
697
698
699 def test_targattrfilters_and_search_permissions_and_that_ldapmodify_works_as_expected(
700 topo, _add_user, aci_of_user, request
701 ):
702 """Testing the targattrfilters keyword that allows access control based on the value of the
703 attributes being added (or deleted))
704 Test that we can have targattrfilters and search permissions and that ldapmodify works as expected.
705
706 :id: ddae7a22-7aa9-11e8-ad6b-8c16451d917b
707 :setup: server
708 :steps:
709 1. Add test entry
710 2. Add ACI
711 3. User should follow ACI role
712 :expectedresults:
713 1. Entry should be added
714 2. Operation should succeed
715 3. Operation should succeed
716 """
717 ACI_BODY = '(targetattr="secretary || objectclass || mail")(targattrfilters = "add=title:' \
718 '(title=arch*)")(version 3.0; acl "{}"; ' \
719 'allow (write,read,search,compare) (userdn = "ldap:///anyone") ;)'.format(request.node.name)
720 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
721 # aci will allow to add title architect
722 conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
723 _ModTitleArchitectJeffVedder(topo, "architect", conn).add()
724
725
726 def test_targattrfilters_and_search_permissions_and_that_ldapmodify_works_as_expected_two(
727 topo, _add_user, aci_of_user, request
728 ):
729 """Testing the targattrfilters keyword that allows access control based on the value of
730 the attributes being added (or deleted))
731 Test that we can have targattrfilters and search permissions and that ldapsearch works as expected.
732
733 :id: e25d116e-7aa9-11e8-81d8-8c16451d917b
734 :setup: server
735 :steps:
736 1. Add test entry
737 2. Add ACI
738 3. User should follow ACI role
739 :expectedresults:
740 1. Entry should be added
741 2. Operation should succeed
742 3. Operation should succeed
743 """
744 ACI_BODY = '(targetattr="secretary || objectclass || mail")(targattrfilters = ' \
745 '"add=title:(title=arch*)")(version 3.0; acl "{}"; allow ' \
746 '(write,read,search,compare) (userdn = "ldap:///anyone") ;)'.format(request.node.name)
747 Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
748 conn = Anonymous(topo.standalone).bind()
749 user = UserAccount(conn, USER_DELADD)
750 #targattrfilters_and_search_permissions_and_that_ldapmodify_works_as_expected
751 assert user.get_attr_vals('secretary')
752 assert user.get_attr_vals('mail')
753 assert user.get_attr_vals('objectclass')
754
755
756 if __name__ == "__main__":
757 CURRENT_FILE = os.path.realpath(__file__)
758 pytest.main("-s -v %s" % CURRENT_FILE)