Debian Codegraph @

dirsrvtests/tests/suites/clu/dsidm_group_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
10 import pytest
11 import json
12 import logging
13 import os
14
15 from lib389 import DEFAULT_SUFFIX
16 from lib389.cli_idm.group import (list, get, get_dn, create, delete, modify, rename,
17 members, add_member, remove_member)
18 from test389.topologies import topology_st
19 from lib389.cli_base import FakeArgs
20 from lib389.utils import ds_is_older, ensure_str, is_a_dn
21 from lib389.idm.group import Groups
22 from . import check_value_in_log_and_reset
23
24 pytestmark = pytest.mark.tier0
25
26 logging.getLogger(__name__).setLevel(logging.DEBUG)
27 log = logging.getLogger(__name__)
28
29
30 group_name = "test_group_2000"
31
32 @pytest.fixture(scope="function")
33 def create_test_group(topology_st, request):
34 groups = Groups(topology_st.standalone, DEFAULT_SUFFIX)
35
36 log.info('Create test group')
37 if groups.exists(group_name):
38 test_group = groups.get(group_name)
39 test_group.delete()
40
41 properties = FakeArgs()
42 properties.cn = group_name
43 create(topology_st.standalone, DEFAULT_SUFFIX, topology_st.logcap.log, properties)
44 test_group = groups.get(group_name)
45
46 def fin():
47 log.info('Delete test group')
48 if test_group.exists():
49 test_group.delete()
50
51 request.addfinalizer(fin)
52
53
54 @pytest.fixture(scope="function")
55 def add_description(topology_st, request):
56 args = FakeArgs()
57 args.selector = group_name
58 args.changes = ['add:description:{}'.format(group_name)]
59 modify(topology_st.standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
60
61
62 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
63 def test_dsidm_group_create(topology_st):
64 """ Test dsidm group create option
65
66 :id: 56e31cf5-0fbf-4693-b8d3-bc6f545d7734
67 :setup: Standalone instance
68 :steps:
69 1. Run dsidm group create
70 2. Check that a message is provided on creation
71 3. Check that created group exists
72 :expectedresults:
73 1. Success
74 2. Success
75 3. Success
76 """
77
78 standalone = topology_st.standalone
79 output = 'Successfully created {}'.format(group_name)
80
81 args = FakeArgs()
82 args.cn = group_name
83 args.description = "my description"
84
85 log.info('Test dsidm group create')
86 create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
87 check_value_in_log_and_reset(topology_st, check_value=output)
88
89 log.info('Check that group is present')
90 groups = Groups(standalone, DEFAULT_SUFFIX)
91 new_group = groups.get(group_name)
92 assert new_group.exists()
93 assert new_group.present('description', 'my description')
94
95 log.info('Clean up for next test')
96 new_group.delete()
97
98
99 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
100 def test_dsidm_group_delete(topology_st, create_test_group):
101 """ Test dsidm group delete option
102
103 :id: d285db5d-8efd-4775-b5f4-47bf27106da6
104 :setup: Standalone instance
105 :steps:
106 1. Run dsidm group delete on a created group
107 2. Check that a message is provided on deletion
108 3. Check that group does not exist
109 :expectedresults:
110 1. Success
111 2. Success
112 3. Success
113 """
114
115 standalone = topology_st.standalone
116 groups = Groups(standalone, DEFAULT_SUFFIX)
117 test_group = groups.get(group_name)
118 output = 'Successfully deleted {}'.format(test_group.dn)
119
120 args = FakeArgs()
121 args.dn = test_group.dn
122
123 log.info('Test dsidm group delete')
124 delete(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
125 check_value_in_log_and_reset(topology_st, check_value=output)
126
127 log.info('Check that group does not exist')
128 assert not test_group.exists()
129
130
131 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
132 def test_dsidm_group_modify(topology_st, create_test_group):
133 """ Test dsidm group modify option
134
135 :id: 43611907-b477-4793-9ed6-8cf2d43ddd6b
136 :setup: Standalone instance
137 :steps:
138 1. Run dsidm group modify add description value
139 2. Run dsidm group modify replace description value
140 3. Run dsidm group modify delete description value
141 :expectedresults:
142 1. description value is present
143 2. description value is replaced with the new one
144 3. description value is deleted
145 """
146
147 standalone = topology_st.standalone
148 groups = Groups(standalone, DEFAULT_SUFFIX)
149 test_group = groups.get(group_name)
150 output = 'Successfully modified {}'.format(test_group.dn)
151
152 args = FakeArgs()
153 args.selector = group_name
154
155 log.info('Test dsidm group modify add')
156 args.changes = ['add:description:test']
157 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
158 check_value_in_log_and_reset(topology_st, check_value=output)
159 assert test_group.present('description', 'test')
160
161 log.info('Test dsidm group modify replace')
162 args.changes = ['replace:description:replaced']
163 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
164 check_value_in_log_and_reset(topology_st, check_value=output)
165 assert test_group.present('description', 'replaced')
166
167 log.info('Test dsidm group modify delete')
168 args.changes = ['delete:description:replaced']
169 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
170 check_value_in_log_and_reset(topology_st, check_value=output)
171 assert not test_group.present('description', 'replaced')
172
173
174 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
175 def test_dsidm_group_list(topology_st, create_test_group):
176 """ Test dsidm group list option
177
178 :id: e10c9430-1ea5-4b81-98c0-524f4f7da0e6
179 :setup: Standalone instance
180 :steps:
181 1. Run dsidm group list option without json
182 2. Check the output content is correct
183 3. Run dsidm group list option with json
184 4. Check the output content is correct
185 5. Delete the group
186 6. Check the group is not in the list with json
187 7. Check the group is not in the list without json
188 :expectedresults:
189 1. Success
190 2. Success
191 3. Success
192 4. Success
193 5. Success
194 6. Success
195 7. Success
196 """
197
198 standalone = topology_st.standalone
199 args = FakeArgs()
200 args.json = False
201 args.full_dn = False
202 json_list = ['type',
203 'list',
204 'items']
205
206 log.info('Empty the log file to prevent false data to check about group')
207 topology_st.logcap.flush()
208
209 log.info('Test dsidm group list without json')
210 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
211 check_value_in_log_and_reset(topology_st, check_value=group_name)
212
213 log.info('Test dsidm group list with json')
214 args.json = True
215 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
216 check_value_in_log_and_reset(topology_st, content_list=json_list, check_value=group_name)
217
218 log.info('Test full_dn option with list')
219 args.full_dn = True
220 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
221 result = topology_st.logcap.get_raw_outputs()
222 json_result = json.loads(result[0])
223 assert is_a_dn(json_result['items'][0])
224 args.full_dn = False
225
226 log.info('Delete the group')
227 groups = Groups(standalone, DEFAULT_SUFFIX)
228 testgroup = groups.get(group_name)
229 testgroup.delete()
230
231 log.info('Test empty dsidm group list with json')
232 topology_st.logcap.flush()
233 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
234 check_value_in_log_and_reset(topology_st, content_list=json_list, check_value_not=group_name)
235
236 log.info('Test empty dsidm group list without json')
237 args.json = False
238 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
239 check_value_in_log_and_reset(topology_st, check_value_not=group_name)
240
241
242 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
243 def test_dsidm_group_get_dn(topology_st, create_test_group):
244 """ Test dsidm group get_dn option
245
246 :id: c1d22d33-6431-45c6-9cd1-703225d8db50
247 :setup: Standalone instance
248 :steps:
249 1. Run dsidm group get_dn for created group without json
250 2. Check the output content is correct
251 3. Run dsidm group get_dn for created group with json
252 4. Check the output content is correct
253 :expectedresults:
254 1. Success
255 2. Success
256 3. Success
257 4. Success
258 """
259
260 standalone = topology_st.standalone
261 groups = Groups(standalone, DEFAULT_SUFFIX)
262 test_group = groups.get(group_name)
263 args = FakeArgs()
264 args.dn = test_group.dn
265 args.json = False
266
267 log.info('Empty the log file to prevent false data to check about group')
268 topology_st.logcap.flush()
269
270 log.info('Test dsidm group get_dn without json')
271 get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
272 check_value_in_log_and_reset(topology_st, content_list=group_name)
273
274 log.info('Test dsidm group get_dn with json')
275 args.json = True
276 get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
277 check_value_in_log_and_reset(topology_st, content_list=group_name)
278
279
280 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
281 def test_dsidm_group_get_rdn(topology_st, create_test_group, add_description):
282 """ Test dsidm group get option
283
284 :id: 8578005b-9dbf-4aa9-bcd4-1431f44bbff7
285 :setup: Standalone instance
286 :steps:
287 1. Run dsidm get option for created group with json
288 2. Check the output content is correct
289 3. Run dsidm get option for created group without json
290 4. Check the json content is correct
291 :expectedresults:
292 1. Success
293 2. Success
294 3. Success
295 4. Success
296 """
297
298 standalone = topology_st.standalone
299 groups = Groups(standalone, DEFAULT_SUFFIX)
300 test_group = groups.get(group_name)
301
302 group_content = ['dn: {}'.format(test_group.dn),
303 'cn: {}'.format(test_group.rdn),
304 'description: {}'.format(test_group.rdn),
305 'objectClass: top',
306 'objectClass: groupOfNames',
307 'objectClass: nsMemberOf']
308
309 json_content = ['attrs',
310 'objectclass',
311 'top',
312 'groupOfNames',
313 'nsMemberOf',
314 'cn',
315 test_group.rdn,
316 'description',
317 'creatorsname',
318 'cn=directory manager',
319 'modifiersname',
320 'createtimestamp',
321 'modifytimestamp',
322 'nsuniqueid',
323 'parentid',
324 'entryid',
325 'entryuuid',
326 'dsentrydn',
327 'entrydn',
328 test_group.dn]
329
330 args = FakeArgs()
331 args.json = False
332 args.selector = group_name
333
334 log.info('Empty the log file to prevent false data to check about group')
335 topology_st.logcap.flush()
336
337 log.info('Test dsidm group get without json')
338 get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
339 check_value_in_log_and_reset(topology_st, content_list=group_content)
340
341 log.info('Test dsidm group get with json')
342 args.json = True
343 get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
344 check_value_in_log_and_reset(topology_st, content_list=json_content)
345
346
347 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
348 def test_dsidm_group_rename(topology_st, create_test_group, add_description):
349 """ Test dsidm group rename option
350
351 :id: 9d4b4509-3adf-41b1-8e67-d23529b251b6
352 :setup: Standalone instance
353 :steps:
354 1. Run dsidm group rename option on created group
355 2. Check the group does not have another cn attribute with the old rdn
356 3. Check the old group is deleted
357 :expectedresults:
358 1. Success
359 2. Success
360 3. Success
361 """
362
363 standalone = topology_st.standalone
364 groups = Groups(standalone, DEFAULT_SUFFIX)
365 test_group = groups.get(group_name)
366
367 args = FakeArgs()
368 args.selector = group_name
369 args.new_name = 'new_group'
370 args.keep_old_rdn = False
371
372 log.info('Test dsidm group rename')
373 rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
374 new_group = groups.get(args.new_name)
375 output = 'Successfully renamed to {}'.format(new_group.dn)
376 check_value_in_log_and_reset(topology_st, check_value=output)
377
378 log.info('Verify the new group does not have cn attribute with the old rdn')
379 assert not new_group.present('cn', group_name)
380 assert new_group.get_attr_val_utf8('description') == group_name
381
382 log.info('Verify old group dn does not exist')
383 assert not test_group.exists()
384
385 log.info('Clean up')
386 new_group.delete()
387
388
389 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
390 def test_dsidm_group_rename_keep_old_rdn(topology_st, create_test_group, add_description):
391 """ Test dsidm group rename option with keep-old-rdn
392
393 :id: 2c0d623b-9dab-4ca3-ae32-de4332a2ed4d
394 :setup: Standalone instance
395 :steps:
396 1. Run dsidm group rename option on created group with keep-old-rdn
397 2. Check the group has another cn attribute with the old rdn
398 3. Check the old group is deleted
399 :expectedresults:
400 1. Success
401 2. Success
402 3. Success
403 """
404
405 standalone = topology_st.standalone
406 groups = Groups(standalone, DEFAULT_SUFFIX)
407 test_group = groups.get(group_name)
408
409 args = FakeArgs()
410 args.selector = group_name
411 args.new_name = 'new_group'
412 args.keep_old_rdn = True
413
414 log.info('Test dsidm group rename with keep-old-rdn')
415 rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
416 new_group = groups.get(args.new_name)
417 output = 'Successfully renamed to {}'.format(new_group.dn)
418 check_value_in_log_and_reset(topology_st, check_value=output)
419
420 log.info('Verify the new group has cn attribute with the old rdn')
421 assert new_group.present('cn', group_name)
422 assert new_group.get_attr_val_utf8('description') == group_name
423
424 log.info('Verify old group dn does not exist')
425 assert not test_group.exists()
426
427 log.info('Clean up')
428 new_group.delete()
429
430
431 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
432 def test_dsidm_group_members_add_remove(topology_st, create_test_group):
433 """ Test dsidm group members, add_member and remove_members options
434
435 :id: c0839a0a-5519-4762-927c-6cb2accff2fe
436 :setup: Standalone instance
437 :steps:
438 1. Show members of a group using dsidm group members
439 2. Add member to the group using dsidm group add_member
440 3. Verify the added member is associated with the group using dsidm group member
441 4. Remove the member from the group using dsidm group remove_member
442 5. Verify the member is no longer associated with the group using dsidm group member
443 :expectedresults:
444 1. Group has no members
445 2. Member is successfully added
446 3. Shows previously added member
447 4. Member is successfully removed
448 5. Group has no members
449 """
450
451 standalone = topology_st.standalone
452
453 member = 'uid=new_member'
454 output_no_member = 'No members to display'
455 output_with_member = 'dn: {}'.format(member)
456 output_add_member = 'added member: {}'.format(member)
457 output_remove_member = 'removed member: {}'.format(member)
458
459 args = FakeArgs()
460 args.cn = group_name
461 args.json = False
462
463 log.info('Test dsidm group members to show no associated members')
464 members(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
465 check_value_in_log_and_reset(topology_st, check_value=output_no_member)
466
467 log.info('Test dsidm group add_member')
468 args.dn = member
469 add_member(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
470 check_value_in_log_and_reset(topology_st, check_value=output_add_member)
471
472 log.info('Verify the added member is associated with the group')
473 members(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
474 check_value_in_log_and_reset(topology_st, check_value=output_with_member)
475
476 # Test json
477 args.json = True
478 members(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
479 result = topology_st.logcap.get_raw_outputs()
480 json_result = json.loads(result[0])
481 assert len(json_result['members']) == 1
482 args.json = False
483
484 log.info('Test dsidm group remove_member')
485 remove_member(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
486 check_value_in_log_and_reset(topology_st, check_value=output_remove_member)
487
488 log.info('Verify the added member is no longer associated with the group')
489 members(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
490 check_value_in_log_and_reset(topology_st, check_value=output_no_member)
491
492 # Test json
493 args.json = True
494 members(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
495 result = topology_st.logcap.get_raw_outputs()
496 json_result = json.loads(result[0])
497 assert len(json_result['members']) == 0
498 args.json = False
499
500
501 if __name__ == '__main__':
502 # Run isolated
503 # -s for DEBUG mode
504 CURRENT_FILE = os.path.realpath(__file__)
505 pytest.main("-s %s" % CURRENT_FILE)