Debian Codegraph @

dirsrvtests/tests/suites/clu/dsidm_role_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2025 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
10 import json
11 import logging
12 import os
13
14 from lib389 import DEFAULT_SUFFIX
15 from lib389.cli_idm.role import (
16 list, get, get_dn,
17 create_managed, create_filtered, create_nested,
18 delete, modify, rename, entry_status, subtree_status, lock, unlock
19 )
20 from test389.topologies import topology_st
21 from lib389.cli_base import FakeArgs
22 from lib389.utils import ds_is_older, is_a_dn
23 from lib389.idm.role import Roles, ManagedRoles, FilteredRoles, NestedRoles
24 from . import check_value_in_log_and_reset, check_value_in_log
25
26
27 pytestmark = pytest.mark.tier0
28
29 logging.getLogger(__name__).setLevel(logging.DEBUG)
30 log = logging.getLogger(__name__)
31
32 managed_role_name = 'test_managed_role'
33 filtered_role_name = 'test_filtered_role'
34 nested_role_name = 'test_nested_role'
35
36
37 @pytest.fixture(scope="function")
38 def create_test_managed_role(topology_st, request):
39 managed_roles = ManagedRoles(topology_st.standalone, DEFAULT_SUFFIX)
40
41 log.info('Create test managed role')
42 if managed_roles.exists(managed_role_name):
43 test_managed_role = managed_roles.get(managed_role_name)
44 test_managed_role.delete()
45
46 properties = FakeArgs()
47 properties.cn = managed_role_name
48 create_managed(topology_st.standalone, DEFAULT_SUFFIX, topology_st.logcap.log, properties)
49 test_managed_role = managed_roles.get(managed_role_name)
50
51 def fin():
52 log.info('Delete test managed role')
53 if test_managed_role.exists():
54 test_managed_role.delete()
55
56 request.addfinalizer(fin)
57
58
59 @pytest.fixture(scope="function")
60 def create_test_filtered_role(topology_st, request):
61 filtered_roles = FilteredRoles(topology_st.standalone, DEFAULT_SUFFIX)
62
63 log.info('Create test filtered role')
64 if filtered_roles.exists(filtered_role_name):
65 test_filtered_role = filtered_roles.get(filtered_role_name)
66 test_filtered_role.delete()
67
68 properties = FakeArgs()
69 properties.cn = filtered_role_name
70 properties.nsrolefilter = "(cn=*)"
71 create_filtered(topology_st.standalone, DEFAULT_SUFFIX, topology_st.logcap.log, properties)
72 test_filtered_role = filtered_roles.get(filtered_role_name)
73
74 def fin():
75 log.info('Delete test filtered role')
76 if test_filtered_role.exists():
77 test_filtered_role.delete()
78
79 request.addfinalizer(fin)
80
81
82 @pytest.fixture(scope="function")
83 def create_test_nested_role(topology_st, create_test_managed_role, request):
84 managed_roles = ManagedRoles(topology_st.standalone, DEFAULT_SUFFIX)
85 managed_role = managed_roles.get(managed_role_name)
86
87 nested_roles = NestedRoles(topology_st.standalone, DEFAULT_SUFFIX)
88
89 log.info('Create test nested role')
90 if nested_roles.exists(nested_role_name):
91 test_nested_role = nested_roles.get(nested_role_name)
92 test_nested_role.delete()
93
94 properties = FakeArgs()
95 properties.cn = nested_role_name
96 properties.nsroledn = managed_role.dn
97 create_nested(topology_st.standalone, DEFAULT_SUFFIX, topology_st.logcap.log, properties)
98 test_nested_role = nested_roles.get(nested_role_name)
99
100 def fin():
101 log.info('Delete test nested role')
102 if test_nested_role.exists():
103 test_nested_role.delete()
104
105 request.addfinalizer(fin)
106
107
108 @pytest.fixture(scope="function")
109 def add_description(topology_st, request):
110 managed_roles = ManagedRoles(topology_st.standalone, DEFAULT_SUFFIX)
111 test_managed_role = managed_roles.get(managed_role_name)
112 args = FakeArgs()
113 args.dn = test_managed_role.dn
114 args.selector = managed_role_name
115 args.changes = ['add:description:{}'.format(managed_role_name)]
116 modify(topology_st.standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
117
118
119 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
120 def test_dsidm_role_create_managed(topology_st):
121 """ Test dsidm role create-managed option
122
123 :id: 8a7f221d-ceae-4d64-acd5-eb02b714a883
124 :setup: Standalone instance
125 :steps:
126 1. Run dsidm role create-managed
127 2. Check that correct message is provided on creation
128 3. Check that created role exists
129 :expectedresults:
130 1. Success
131 1. Success
132 1. Success
133 """
134
135 standalone = topology_st.standalone
136 output = 'Successfully created {}'.format(managed_role_name)
137
138 args = FakeArgs()
139 args.cn = managed_role_name
140
141 log.info('Test dsidm role create-managed')
142 create_managed(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
143 check_value_in_log_and_reset(topology_st, check_value=output)
144
145 log.info('Check that the managed role exists and has proper objectclasses')
146 managed_roles = ManagedRoles(standalone, DEFAULT_SUFFIX)
147 new_managed_role = managed_roles.get(managed_role_name)
148 assert new_managed_role.exists()
149 assert new_managed_role.present('objectClass', 'nsSimpleRoleDefinition')
150 assert new_managed_role.present('objectClass', 'nsManagedRoleDefinition')
151
152 log.info('Clean up for next test')
153 new_managed_role.delete()
154
155 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
156 def test_dsidm_role_create_filtered(topology_st):
157 """ Test dsidm role create-filtered option
158
159 :id: 8913e2f0-992f-49d9-8a82-92d584ded84f
160 :setup: Standalone instance
161 :steps:
162 1. Run dsidm role create-filtered
163 2. Check that correct message is provided on creation
164 3. Check that created role exists
165 :expectedresults:
166 1. Success
167 1. Success
168 1. Success
169 """
170
171 standalone = topology_st.standalone
172 output = 'Successfully created {}'.format(filtered_role_name)
173
174 args = FakeArgs()
175 args.cn = filtered_role_name
176 args.nsrolefilter = "(cn=*)"
177
178 log.info('Test dsidm role create-filtered')
179 create_filtered(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
180 check_value_in_log_and_reset(topology_st, check_value=output)
181
182 log.info('Check that the filtered role exists and has proper objectclasses')
183 filtered_roles = FilteredRoles(standalone, DEFAULT_SUFFIX)
184 new_filtered_role = filtered_roles.get(filtered_role_name)
185 assert new_filtered_role.exists()
186 assert new_filtered_role.present('objectClass', 'nsComplexRoleDefinition')
187 assert new_filtered_role.present('objectClass', 'nsFilteredRoleDefinition')
188
189 log.info('Clean up for next test')
190 new_filtered_role.delete()
191
192
193 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
194 def test_dsidm_role_create_nested(topology_st, create_test_managed_role):
195 """ Test dsidm role create-nested option
196
197 :id: db3b6f70-121c-466a-b28f-b4331e54b5d7
198 :setup: Standalone instance
199 :steps:
200 1. Run dsidm role create-nested
201 2. Check that correct message is provided on creation
202 3. Check that created role exists
203 :expectedresults:
204 1. Success
205 1. Success
206 1. Success
207 """
208
209 standalone = topology_st.standalone
210 output = 'Successfully created {}'.format(nested_role_name)
211
212 managed_roles = ManagedRoles(standalone, DEFAULT_SUFFIX)
213 managed_role = managed_roles.get(managed_role_name)
214
215 args = FakeArgs()
216 args.cn = nested_role_name
217 args.nsroledn = managed_role.dn
218
219 log.info('Test dsidm role create-nested')
220 create_nested(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
221 check_value_in_log_and_reset(topology_st, check_value=output)
222
223 log.info('Check that the nested role exists and has proper objectclasses')
224 nested_roles = NestedRoles(standalone, DEFAULT_SUFFIX)
225 new_nested_role = nested_roles.get(nested_role_name)
226 assert new_nested_role.exists()
227 assert new_nested_role.present('objectClass', 'nsComplexRoleDefinition')
228 assert new_nested_role.present('objectClass', 'nsNestedRoleDefinition')
229
230 log.info('Clean up for next test')
231 new_nested_role.delete()
232
233
234 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
235 def test_dsidm_role_delete(topology_st, create_test_managed_role):
236 """ Test dsidm role delete
237
238 :id: ade850ae-9304-4eae-ba47-38bfaf3d8747
239 :setup: Standalone instance
240 :steps:
241 1. Run dsidm role delete on a created role
242 2. Check that a message is provided on deletion
243 3. Check that role does not exist
244 :expectedresults:
245 1. Success
246 2. Success
247 3. Success
248 """
249
250 standalone = topology_st.standalone
251 managed_roles = ManagedRoles(standalone, DEFAULT_SUFFIX)
252 test_managed_role = managed_roles.get(managed_role_name)
253 output = 'Successfully deleted {}'.format(test_managed_role.dn)
254
255 args = FakeArgs()
256 args.dn = test_managed_role.dn
257
258 log.info('Test dsidm role delete')
259 delete(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
260 check_value_in_log_and_reset(topology_st, check_value=output)
261
262 log.info('Check that role does not exist')
263 args.json = False
264 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
265 assert not test_managed_role.exists()
266
267
268 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
269 def test_dsidm_role_list(topology_st, create_test_managed_role):
270 """ Test dsidm role list option
271
272 :id: a1dd201a-3a04-42aa-913c-6c22f0244ff0
273 :setup: Standalone instance
274 :steps:
275 1. Run dsidm role list option without json
276 2. Check the output content is correct
277 3. Run dsidm role list option with json
278 4. Test "full_dn" option with list
279 5. Check the output content is correct
280 6. Delete the role
281 7. Check the role is not in the list with json
282 8. Check the role is not in the list without json
283
284 :expectedresults:
285 1. Success
286 2. Success
287 3. Success
288 4. Success
289 5. Success
290 6. Success
291 7. Success
292 8. Success
293 """
294
295 standalone = topology_st.standalone
296 args = FakeArgs()
297 args.json = False
298 args.full_dn = False
299 json_list = ['type',
300 'list',
301 'items']
302
303 log.info('Empty the log file to prevent false data to check about role')
304 topology_st.logcap.flush()
305
306 log.info('Test dsidm role list without json')
307 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
308 check_value_in_log_and_reset(topology_st, check_value=managed_role_name)
309
310 log.info('Test dsidm role list with json')
311 args.json = True
312 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
313 check_value_in_log_and_reset(topology_st, content_list=json_list, check_value=managed_role_name)
314
315 log.info('Test full_dn option with list')
316 args.full_dn = True
317 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
318 result = topology_st.logcap.get_raw_outputs()
319 json_result = json.loads(result[0])
320 assert is_a_dn(json_result['items'][0])
321 args.full_dn = False
322
323 log.info('Delete the role')
324 roles = ManagedRoles(standalone, DEFAULT_SUFFIX)
325 test_role = roles.get(managed_role_name)
326 test_role.delete()
327
328 log.info('Test empty dsidm role list with json')
329 topology_st.logcap.flush()
330 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
331 result = topology_st.logcap.get_raw_outputs()
332 json_result = json.loads(result[0])
333 assert len(json_result['items']) == 0
334 check_value_in_log_and_reset(topology_st, content_list=json_list, check_value_not=managed_role_name)
335
336 log.info('Test empty dsidm role list without json')
337 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
338 check_value_in_log_and_reset(topology_st, check_value_not=managed_role_name)
339
340
341 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
342 @pytest.mark.parametrize(
343 "role_name, fixture, objectclasses",
344 [(managed_role_name, 'create_test_managed_role', ['nsSimpleRoleDefinition', 'nsManagedRoleDefinition']),
345 (filtered_role_name, 'create_test_filtered_role', ['nsComplexRoleDefinition', 'nsFilteredRoleDefinition']),
346 (nested_role_name, 'create_test_nested_role', ['nsComplexRoleDefinition', 'nsNestedRoleDefinition'])])
347 def test_dsidm_role_get(topology_st, role_name, fixture, objectclasses, request):
348 """ Test dsidm role get option for managed, filtered and nested role
349
350 :id: 814f269d-c230-4105-a215-3f55b7d8ae47
351 :setup: Standalone instance
352 :steps:
353 1. Run dsidm get option for a created role without json
354 2. Check the output content is correct
355 3. Run dsidm get option for a created role with json
356 4. Check the output content is correct
357 :expectedresults:
358 1. Success
359 2. Success
360 3. Success
361 4. Success
362 """
363
364 request.getfixturevalue(fixture)
365 standalone = topology_st.standalone
366 roles = Roles(standalone, DEFAULT_SUFFIX)
367 test_role = roles.get(role_name)
368
369 role_content = ['dn: {}'.format(test_role.dn),
370 'cn: {}'.format(test_role.rdn),
371 'objectClass: top',
372 'objectClass: ldapSubEntry',
373 'objectClass: nsRoleDefinition',
374 'objectClass: {}'.format(objectclasses[0]),
375 'objectClass: {}'.format(objectclasses[1])]
376
377 json_content = ['attrs',
378 'objectclass',
379 'top',
380 'ldapSubEntry',
381 'nsRoleDefinition',
382 objectclasses[0],
383 objectclasses[1],
384 'cn',
385 test_role.rdn,
386 'creatorsname',
387 'cn=directory manager',
388 'modifiersname',
389 'createtimestamp',
390 'modifytimestamp',
391 'nsuniqueid',
392 'parentid',
393 'entryid',
394 'entryuuid',
395 'dsentrydn',
396 'entrydn',
397 test_role.dn]
398
399 args = FakeArgs()
400 args.json = False
401 args.selector = role_name
402
403 log.info('Empty the log file to prevent false data to check about role')
404 topology_st.logcap.flush()
405
406 log.info('Test dsidm role get without json')
407 get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
408 check_value_in_log_and_reset(topology_st, content_list=role_content)
409
410 log.info('Test dsidm role get with json')
411 args.json = True
412 get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
413 check_value_in_log_and_reset(topology_st, content_list=json_content)
414
415
416 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
417 @pytest.mark.parametrize(
418 "role_name, fixture, objectclasses",
419 [(managed_role_name, 'create_test_managed_role', ['nsSimpleRoleDefinition', 'nsManagedRoleDefinition']),
420 (filtered_role_name, 'create_test_filtered_role', ['nsComplexRoleDefinition', 'nsFilteredRoleDefinition']),
421 (nested_role_name, 'create_test_nested_role', ['nsComplexRoleDefinition', 'nsNestedRoleDefinition'])])
422 def test_dsidm_role_get_by_dn(topology_st, role_name, fixture, objectclasses, request):
423 """ Test dsidm role get-by-dn option for managed, filtered and nested role
424
425 :id: 5fe4cb2b-dc26-43fd-b6a2-c507be689d31
426 :setup: Standalone instance
427 :steps:
428 1. Run dsidm get-by-dn option for a created role without json
429 2. Check the output content is correct
430 3. Run dsidm get-by-dn option for a created role with json
431 4. Check the output content is correct
432 :expectedresults:
433 1. Success
434 2. Success
435 3. Success
436 4. Success
437 """
438
439 request.getfixturevalue(fixture)
440 standalone = topology_st.standalone
441
442 roles = Roles(standalone, DEFAULT_SUFFIX)
443 test_role = roles.get(role_name)
444
445 role_content = ['dn: {}'.format(test_role.dn),
446 'cn: {}'.format(test_role.rdn),
447 'objectClass: top',
448 'objectClass: ldapSubEntry',
449 'objectClass: nsRoleDefinition',
450 'objectClass: {}'.format(objectclasses[0]),
451 'objectClass: {}'.format(objectclasses[1])]
452
453 json_content = ['attrs',
454 'objectclass',
455 'top',
456 'ldapSubEntry',
457 'nsRoleDefinition',
458 objectclasses[0],
459 objectclasses[1],
460 'cn',
461 test_role.rdn,
462 'creatorsname',
463 'cn=directory manager',
464 'modifiersname',
465 'createtimestamp',
466 'modifytimestamp',
467 'nsuniqueid',
468 'parentid',
469 'entryid',
470 'entryuuid',
471 'dsentrydn',
472 'entrydn',
473 test_role.dn]
474
475 args = FakeArgs()
476 args.dn = test_role.dn
477 args.json = False
478 args.selector = test_role.dn
479
480 log.info('Empty the log file to prevent false data to check about role')
481 topology_st.logcap.flush()
482
483 log.info('Test dsidm role get-by-dn without json')
484 get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
485 check_value_in_log_and_reset(topology_st, content_list=role_content)
486
487 log.info('Test dsidm role get-by-dn with json')
488 args.json = True
489 get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
490 check_value_in_log_and_reset(topology_st, content_list=json_content)
491 # verify influence of changing cli_idm/__init__.py _generic_get_dn on line 144
492
493
494 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
495 def test_dsidm_role_modify_by_dn(topology_st, create_test_managed_role):
496 """ Test dsidm role modify-by-dn
497
498 :id: 7670f70b-eb8e-40bd-aeaf-4ae5ea7ddee0
499 :setup: Standalone instance
500 :steps:
501 1. Run dsidm role modify-by-dn add:description:value
502 2. Run dsidm role modify-by-dn replace:description:newvalue
503 3. Run dsidm role modify-by-dn delete:description:newvalue
504 :expectedresults:
505 1. Description value is present
506 2. Description value is replaced with the new one
507 3. Description value is deleted
508 """
509
510 standalone = topology_st.standalone
511 roles = Roles(standalone, DEFAULT_SUFFIX)
512 test_role = roles.get(managed_role_name)
513 output = 'Successfully modified {}'.format(test_role.dn)
514
515 args = FakeArgs()
516 args.dn = test_role.dn
517 args.selector = managed_role_name
518
519 log.info('Test dsidm role modify-by-dn add')
520 args.changes = ['add:description:test managed role']
521 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
522 check_value_in_log_and_reset(topology_st, check_value=output)
523 assert test_role.present('description', 'test managed role')
524
525 log.info('Test dsidm role modify-by-dn replace')
526 args.changes = ['replace:description:modified managed role']
527 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
528 check_value_in_log_and_reset(topology_st, check_value=output)
529 assert test_role.present('description', 'modified managed role')
530 assert not test_role.present('description', 'test managed role')
531
532 log.info('Test dsidm role modify-by-dn delete')
533 args.changes = ['delete:description:modified managed role']
534 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
535 check_value_in_log_and_reset(topology_st, check_value=output)
536 assert not test_role.present('description', 'modified managed role')
537
538
539 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
540 def test_dsidm_role_rename_by_dn(topology_st, create_test_managed_role, add_description):
541 """ Test dsidm role rename-by-dn
542
543 :id: 3a5295ad-dd9d-4819-aa1c-44f7a785a7d5
544 :setup: Standalone instance
545 :steps:
546 1. Run dsidm role rename-by-dn option on existing role
547 2. Check the role does not have another cn attribute with the old rdn
548 3. Verify the role with original name does not exist
549 :expectedresults:
550 1. Success
551 2. Success
552 3. Success
553 """
554
555 standalone = topology_st.standalone
556 roles = Roles(standalone, DEFAULT_SUFFIX)
557 test_role = roles.get(managed_role_name)
558
559 args = FakeArgs()
560 args.dn = test_role.dn
561 args.new_name = 'renamed_role'
562 args.new_dn = 'cn=renamed_role,{}'.format(DEFAULT_SUFFIX)
563 args.keep_old_rdn = False
564
565 log.info('Test dsidm role rename-by-dn')
566 rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
567 new_role = roles.get(args.new_name)
568 output = 'Successfully renamed to {}'.format(new_role.dn)
569 check_value_in_log_and_reset(topology_st, check_value=output)
570
571 log.info('Verify the new role does not have a cn attribute with the old rdn')
572 assert not new_role.present('cn', managed_role_name)
573 assert new_role.present('description', managed_role_name)
574
575 log.info('Verify the old role does not exist')
576 assert not test_role.exists()
577
578
579 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
580 def test_dsidm_role_rename_by_dn_keep_old_rdn(topology_st, create_test_managed_role, add_description):
581 """ Test dsidm role rename-by-dn with keep-old-rdn option
582
583 :id: 7c2c55cd-7d3c-4562-8b6e-4f64590fb5f0
584 :setup: Standalone instance
585 :steps:
586 1. Run dsidm role rename-by-dn option on existing role
587 2. Check the role has another cn attribute with the old rdn
588 3. Verify the role with original name does not exist
589 :expectedresults:
590 1. Success
591 2. Success
592 3. Success
593 """
594
595 standalone = topology_st.standalone
596 roles = Roles(standalone, DEFAULT_SUFFIX)
597 test_role = roles.get(managed_role_name)
598
599 args = FakeArgs()
600 args.dn = test_role.dn
601 args.new_name = 'renamed_role_keep_rdn'
602 args.new_dn = 'cn=renamed_role_keep_rdn,{}'.format(DEFAULT_SUFFIX)
603 args.keep_old_rdn = True
604
605 log.info('Test dsidm role rename-by-dn')
606 rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
607 new_role = roles.get(args.new_name)
608 output = 'Successfully renamed to {}'.format(new_role.dn)
609 check_value_in_log_and_reset(topology_st, check_value=output)
610
611 log.info('Verify the new role does not have a cn attribute with the old rdn')
612 assert new_role.present('cn', managed_role_name)
613 assert new_role.present('description', managed_role_name)
614
615 log.info('Verify the old role does not exist')
616 assert not test_role.exists()
617
618
619 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
620 def test_dsidm_role_lock_unlock_entrystatus(topology_st, create_test_managed_role):
621 """ Test dsidm role lock option
622
623 :id: 26b03489-81eb-4a00-bf2c-115f58ced07d
624 :setup: Standalone instance
625 :steps:
626 1. Run dsidm role entry-status on an existing role with no locking done previously without json
627 2. Run dsidm role entry-status on an existing role with no locking done previously with json
628 3. Run dsidm role lock on an existing role
629 4. Verify new roles for the purposes of maintaining locked roles were created
630 5. Verify locked role is member of the nested role for locked roles
631 6. Verify the role is locked by running dsidm role entry-status on the role without json
632 7. Verify the role is locked by running dsidm role entry-status on the role with json
633 8. Run dsidm role unlock on the locked role
634 9. Verify the auxiliary roles still exist
635 10. Verify the unlocked role is not associated with auxiliary roles
636 11. Verify the role is unlocked by running dsidm role entry-status on the role without json
637 12. Verify the role is unlocked by running dsidm role entry-status on the role with json
638 :expectedresults:
639 1. Success
640 2. Success
641 3. Success
642 4. Success
643 5. Success
644 6. Success
645 7. Success
646 8. Success
647 9. Success
648 10. Success
649 11. Success
650 12. Success
651 """
652
653 standalone = topology_st.standalone
654 roles = Roles(standalone, DEFAULT_SUFFIX)
655 test_role = roles.get(managed_role_name)
656
657 args = FakeArgs()
658 args.dn = test_role.dn
659 args.json = False
660
661 lock_output = 'Entry {} is locked'.format(test_role.dn)
662 unlock_output = 'Entry {} is unlocked'.format(test_role.dn)
663 entry_dn_output = 'Entry DN: {}'.format(test_role.dn)
664 entry_locked_output = 'Entry State: directly locked through nsDisabledRole'
665 entry_unlocked_output = 'Entry State: activated'
666 probably_activated = "probably activated or nsDisabledRole setup and its CoS entries are not\n" \
667 "in a valid state or there is no access to the settings."
668 entry_never_locked_output = 'Entry State: {}'.format(probably_activated)
669
670 entry_locked_content = ['dn',
671 test_role.dn,
672 'state',
673 'directly locked through nsDisabledRole']
674
675 entry_unlocked_content = ['dn',
676 test_role.dn,
677 'state',
678 'activated']
679
680 entry_never_locked_content = ['dn',
681 test_role.dn,
682 'state',
683 repr(probably_activated).strip("'")]
684
685 log.info('Test dsidm role entry-status when no role has been disabled before')
686 entry_status(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
687 check_value_in_log(topology_st, check_value=entry_dn_output)
688 check_value_in_log_and_reset(topology_st, check_value=entry_never_locked_output)
689
690 log.info('Test dsidm role entry-status when no role has been disabled before')
691 args.json = True
692 entry_status(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
693 check_value_in_log_and_reset(topology_st, content_list=entry_never_locked_content)
694
695 log.info('Test dsidm role lock on a managed role')
696 args.json = False
697 lock(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
698 check_value_in_log_and_reset(topology_st, check_value=lock_output)
699
700 log.info('Test new auxiliary roles for locked roles are created')
701 disabled_role = roles.get('nsDisabledRole')
702 managed_disabled_role = roles.get('nsManagedDisabledRole')
703 assert managed_disabled_role.exists()
704 assert disabled_role.exists()
705
706 log.info('Verify the locked role is a nsRoleDN attribute of auxiliary nsDisabledRole')
707 assert disabled_role.present('nsRoleDN', test_role.dn)
708
709 log.info('Test dsidm role entry-status to verify activation status of the locked role')
710 entry_status(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
711 check_value_in_log(topology_st, check_value=entry_dn_output)
712 check_value_in_log_and_reset(topology_st, check_value=entry_locked_output)
713
714 log.info('Test dsidm role entry-status to verify activation status of the locked role')
715 args.json = True
716 entry_status(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
717 check_value_in_log_and_reset(topology_st, content_list=entry_locked_content)
718
719 log.info('Test dsidm role unlock on a locked managed role')
720 args.json = False
721 unlock(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
722 check_value_in_log_and_reset(topology_st, check_value=unlock_output)
723
724 log.info('Verify auxiliary roles still exist')
725 assert managed_disabled_role.exists()
726 assert disabled_role.exists()
727
728 log.info('Verify the unlocked role is not associated with auxiliary roles')
729 assert not disabled_role.present('nsRoleDN', test_role.dn)
730
731 log.info('Test dsidm role entry-status to verify activation status of the unlocked role')
732 entry_status(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
733 check_value_in_log(topology_st, check_value=entry_dn_output)
734 check_value_in_log_and_reset(topology_st, check_value=entry_unlocked_output)
735
736 log.info('Test dsidm role entry-status to verify activation status of the unlocked role - json')
737 args.json = True
738 entry_status(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
739 check_value_in_log_and_reset(topology_st, content_list=entry_unlocked_content)
740
741 log.info('Clean up')
742 test_role.delete()
743 disabled_role.delete()
744 managed_disabled_role.delete()
745
746
747 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
748 def test_dsidm_role_subtree_status(topology_st, create_test_managed_role):
749 """ Test dsidm role subtree-status option
750
751 :id: 0057a93f-edfc-43db-a151-1c3a553c08f2
752 :setup: Standalone instance
753 :steps:
754 1. Run subtree-status on existing role
755 2. Check the output is correct
756 :expectedresults:
757 1. Success
758 2. Success
759 """
760
761 standalone = topology_st.standalone
762 roles = Roles(standalone, DEFAULT_SUFFIX)
763 test_role = roles.get(managed_role_name)
764
765 args = FakeArgs()
766 args.dn = test_role.dn
767 args.json = False
768 args.basedn = DEFAULT_SUFFIX
769 output = 'Entry DN: {}'.format(test_role.dn)
770
771 log.info('Test dsidm role subtree-status')
772 topology_st.logcap.flush()
773 subtree_status(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
774 result = topology_st.logcap.get_raw_outputs()
775 check_value_in_log_and_reset(topology_st, check_value=output)
776
777 log.info('Test dsidm role subtree-status - json')
778 args.json = True
779 subtree_status(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
780 result = topology_st.logcap.get_raw_outputs()
781 json_result = json.loads(result[0])
782 found = False
783 for entry in json_result['entries']:
784 if entry['dn'] == test_role.dn:
785 found = True
786 break
787 assert found
788
789 log.info('Clean up')
790 test_role.delete()
791
792
793 if __name__ == '__main__':
794 # Run isolated
795 # -s for DEBUG mode
796 CURRENT_FILE = os.path.realpath(__file__)
797 pytest.main("-s {}".format(CURRENT_FILE))