Debian Codegraph @

dirsrvtests/tests/suites/clu/dsidm_uniquegroup_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.uniquegroup 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 UniqueGroups
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 uniquegroup_name = "test_uniquegroup"
31
32
33 @pytest.fixture(scope="function")
34 def create_test_uniquegroup(topology_st, request):
35 uniquegroups = UniqueGroups(topology_st.standalone, DEFAULT_SUFFIX)
36
37 log.info('Create test uniquegroup')
38 if uniquegroups.exists(uniquegroup_name):
39 test_uniquegroup = uniquegroups.get(uniquegroup_name)
40 test_uniquegroup.delete()
41
42 properties = FakeArgs()
43 properties.cn = uniquegroup_name
44 create(topology_st.standalone, DEFAULT_SUFFIX, topology_st.logcap.log, properties)
45 test_uniquegroup = uniquegroups.get(uniquegroup_name)
46
47 def fin():
48 log.info('Delete test group')
49 if test_uniquegroup.exists():
50 test_uniquegroup.delete()
51
52 request.addfinalizer(fin)
53
54
55 @pytest.fixture(scope="function")
56 def add_description(topology_st, request):
57 args = FakeArgs()
58 args.selector = uniquegroup_name
59 args.changes = ['add:description:{}'.format(uniquegroup_name)]
60 modify(topology_st.standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
61
62
63 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
64 def test_dsidm_uniquegroup_create(topology_st):
65 """ Test dsidm uniquegroup create option
66
67 :id: 7245d28e-f6b7-4aa5-87cb-c6276f27de65
68 :setup: Standalone instance
69 :steps:
70 1. Run dsidm uniquegroup create
71 2. Check that a message is provided on creation
72 3. Check that created uniquegroup exists
73 :expectedresults:
74 1. Success
75 2. Success
76 3. Success
77 """
78
79 standalone = topology_st.standalone
80 output = 'Successfully created {}'.format(uniquegroup_name)
81
82 args = FakeArgs()
83 args.cn = uniquegroup_name
84
85 log.info('Test dsidm uniquegroup 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 uniquegroup is present')
90 uniquegroups = UniqueGroups(standalone, DEFAULT_SUFFIX)
91 new_uniquegroup = uniquegroups.get(uniquegroup_name)
92 assert new_uniquegroup.exists()
93
94 log.info('Clean up for next test')
95
96
97 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
98 def test_dsidm_uniquegroup_delete(topology_st, create_test_uniquegroup):
99 """ Test dsidm uniquegroup delete option
100
101 :id: 87a8e42a-d194-41a6-80a2-0451b9b75cf4
102 :setup: Standalone instance
103 :steps:
104 1. Run dsidm uniquegroup delete on a created uniquegroup
105 2. Check that a message is provided on deletion
106 3. Check that uniquegroup does not exist
107 :expectedresults:
108 1. Success
109 2. Success
110 3. Success
111 """
112
113 standalone = topology_st.standalone
114 uniquegroups = UniqueGroups(standalone, DEFAULT_SUFFIX)
115 test_uniquegroup = uniquegroups.get(uniquegroup_name)
116 output = 'Successfully deleted {}'.format(test_uniquegroup.dn)
117
118 args = FakeArgs()
119 args.dn = test_uniquegroup.dn
120
121 log.info('Test dsidm uniquegroup delete')
122 delete(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
123 check_value_in_log_and_reset(topology_st, check_value=output)
124
125 log.info('Check that uniquegroup does not exist')
126 assert not test_uniquegroup.exists()
127
128
129 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
130 def test_dsidm_uniquegroup_list(topology_st, create_test_uniquegroup):
131 """ Test dsidm uniquegroup list option
132
133 :id: c19cdbe5-3bde-4ba1-917a-dafd6b43e8b9
134 :setup: Standalone instance
135 :steps:
136 1. Run dsidm uniquegroup list option without json
137 2. Check the output content is correct
138 3. Run dsidm uniquegroup list option with json
139 4. Check the output content is correct
140 5. Delete the uniquegroup
141 6. Check the uniquegroup is not in the list with json
142 7. Check the uniquegroup is not in the list without json
143 :expectedresults:
144 1. Success
145 2. Success
146 3. Success
147 4. Success
148 5. Success
149 6. Success
150 7. Success
151 """
152
153 standalone = topology_st.standalone
154 args = FakeArgs()
155 args.json = False
156 args.full_dn = False
157 json_list = ['type',
158 'list',
159 'items']
160
161 log.info('Empty the log file to prevent false data to check about uniquegroup')
162 topology_st.logcap.flush()
163
164 log.info('Test dsidm uniquegroup list without json')
165 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
166 check_value_in_log_and_reset(topology_st, check_value=uniquegroup_name)
167
168 log.info('Test dsidm uniquegroup list with json')
169 args.json = True
170 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
171 check_value_in_log_and_reset(topology_st, content_list=json_list, check_value=uniquegroup_name)
172
173 log.info('Test full_dn option with list')
174 args.full_dn = True
175 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
176 result = topology_st.logcap.get_raw_outputs()
177 json_result = json.loads(result[0])
178 assert is_a_dn(json_result['items'][0])
179 args.full_dn = False
180
181 log.info('Delete the uniquegroup')
182 uniquegroups = UniqueGroups(standalone, DEFAULT_SUFFIX)
183 test_uniquegroup = uniquegroups.get(uniquegroup_name)
184 test_uniquegroup.delete()
185
186 log.info('Test empty dsidm uniquegroup list with json')
187 topology_st.logcap.flush()
188 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
189 check_value_in_log_and_reset(topology_st, content_list=json_list, check_value_not=uniquegroup_name)
190
191 log.info('Test empty dsidm uniquegroup list without json')
192 args.json = False
193 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
194 check_value_in_log_and_reset(topology_st, check_value_not=uniquegroup_name)
195
196
197 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
198 def test_dsidm_uniquegroup_modify(topology_st, create_test_uniquegroup):
199 """ Test dsidm uniquegroup modify option
200
201 :id: ab3af3cb-0194-468e-abdd-5ed0432c8127
202 :setup: Standalone instance
203 :steps:
204 1. Run dsidm uniquegroup modify add description value
205 2. Run dsidm uniquegroup modify replace description value
206 3. Run dsidm uniquegroup modify delete description value
207 :expectedresults:
208 1. description value is present
209 2. description value is replaced with the new one
210 3. description value is deleted
211 """
212
213 standalone = topology_st.standalone
214 uniquegroups = UniqueGroups(standalone, DEFAULT_SUFFIX)
215 test_uniquegroup = uniquegroups.get(uniquegroup_name)
216 output = 'Successfully modified {}'.format(test_uniquegroup.dn)
217
218 args = FakeArgs()
219 args.selector = uniquegroup_name
220
221 log.info('Test dsidm uniquegroup modify add')
222 args.changes = ['add:description:test']
223 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
224 check_value_in_log_and_reset(topology_st, check_value=output)
225 assert test_uniquegroup.present('description', 'test')
226
227 log.info('Test dsidm uniquegroup modify replace')
228 args.changes = ['replace:description:replaced']
229 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
230 check_value_in_log_and_reset(topology_st, check_value=output)
231 assert test_uniquegroup.present('description', 'replaced')
232
233 log.info('Test dsidm uniquegroup modify delete')
234 args.changes = ['delete:description:replaced']
235 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
236 check_value_in_log_and_reset(topology_st, check_value=output)
237 assert not test_uniquegroup.present('description', 'replaced')
238
239
240 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
241 def test_dsidm_uniquegroup_get_dn(topology_st, create_test_uniquegroup):
242 """ Test dsidm uniquegroup get_dn option
243
244 :id: 6fe4a86a-cc1a-424c-88ef-9aa341487419
245 :setup: Standalone instance
246 :steps:
247 1. Run dsidm uniquegroup get_dn for created uniquegroup without json
248 2. Check the output content is correct
249 3. Run dsidm uniquegroup get_dn for created uniquegroup with json
250 4. Check the output content is correct
251 :expectedresults:
252 1. Success
253 2. Success
254 3. Success
255 4. Success
256 """
257
258 standalone = topology_st.standalone
259 uniquegroups = UniqueGroups(standalone, DEFAULT_SUFFIX)
260 test_uniquegroup = uniquegroups.get(uniquegroup_name)
261 args = FakeArgs()
262 args.dn = test_uniquegroup.dn
263 args.json = False
264
265 log.info('Empty the log file to prevent false data to check about uniquegroup')
266 topology_st.logcap.flush()
267
268 log.info('Test dsidm uniquegroup get_dn without json')
269 get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
270 check_value_in_log_and_reset(topology_st, content_list=uniquegroup_name)
271
272 log.info('Test dsidm uniquegroup get_dn with json')
273 args.json = True
274 get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
275 check_value_in_log_and_reset(topology_st, content_list=uniquegroup_name)
276
277
278 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
279 def test_dsidm_uniquegroup_get_rdn(topology_st, create_test_uniquegroup, add_description):
280 """ Test dsidm uniquegroup get option
281
282 :id: dea0feda-d612-45b9-953e-a53c02055ac4
283 :setup: Standalone instance
284 :steps:
285 1. Run dsidm uniquegroup get option for created uniquegroup with json
286 2. Check the output content is correct
287 3. Run dsidm uniquegroup get option for created uniquegroup without json
288 4. Check the json content is correct
289 :expectedresults:
290 1. Success
291 2. Success
292 3. Success
293 4. Success
294 """
295
296 standalone = topology_st.standalone
297 uniquegroups = UniqueGroups(standalone, DEFAULT_SUFFIX)
298 test_uniquegroup = uniquegroups.get(uniquegroup_name)
299
300 uniquegroup_content = ['dn: {}'.format(test_uniquegroup.dn),
301 'cn: {}'.format(test_uniquegroup.rdn),
302 'description: {}'.format(test_uniquegroup.rdn),
303 'objectClass: top',
304 'objectClass: groupOfUniqueNames',
305 'objectClass: nsMemberOf']
306
307 json_content = ['attrs',
308 'objectclass',
309 'top',
310 'groupOfUniqueNames',
311 'nsMemberOf',
312 'cn',
313 test_uniquegroup.rdn,
314 'description',
315 'creatorsname',
316 'cn=directory manager',
317 'modifiersname',
318 'createtimestamp',
319 'modifytimestamp',
320 'nsuniqueid',
321 'parentid',
322 'entryid',
323 'entryuuid',
324 'dsentrydn',
325 'entrydn',
326 test_uniquegroup.dn]
327
328 args = FakeArgs()
329 args.json = False
330 args.selector = uniquegroup_name
331
332 log.info('Empty the log file to prevent false data to check about uniquegroup')
333 topology_st.logcap.flush()
334
335 log.info('Test dsidm uniquegroup get without json')
336 get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
337 check_value_in_log_and_reset(topology_st, content_list=uniquegroup_content)
338
339 log.info('Test dsidm uniquegroup get with json')
340 args.json = True
341 get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
342 check_value_in_log_and_reset(topology_st, content_list=json_content)
343
344
345 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
346 def test_dsidm_uniquegroup_get_rename(topology_st, create_test_uniquegroup, add_description):
347 """ Test dsidm uniquegroup rename option
348
349 :id: 71b24ff7-65dd-4527-a129-8db034ec1b48
350 :setup: Standalone instance
351 :steps:
352 1. Run dsidm uniquegroup rename option on created uniquegroup
353 2. Check the uniquegroup does not have another cn attribute with the old rdn
354 3. Check the old uniquegroup is deleted
355 :expectedresults:
356 1. Success
357 2. Success
358 3. Success
359 """
360
361 standalone = topology_st.standalone
362 uniquegroups = UniqueGroups(standalone, DEFAULT_SUFFIX)
363 test_uniquegroup = uniquegroups.get(uniquegroup_name)
364
365 args = FakeArgs()
366 args.selector = uniquegroup_name
367 args.new_name = 'new_uniquegroup'
368 args.keep_old_rdn = False
369
370 log.info('Test dsidm uniquegroup rename')
371 rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
372 new_uniquegroup = uniquegroups.get(args.new_name)
373 output = 'Successfully renamed to {}'.format(new_uniquegroup.dn)
374 check_value_in_log_and_reset(topology_st, check_value=output)
375
376 log.info('Verify the new uniquegroup does not have cn attribute with the old rdn')
377 assert not new_uniquegroup.present('cn', uniquegroup_name)
378 assert new_uniquegroup.get_attr_val_utf8('description') == uniquegroup_name
379
380 log.info('Verify old uniquegroup dn does not exist')
381 assert not test_uniquegroup.exists()
382
383 log.info('Clean up')
384 new_uniquegroup.delete()
385
386
387 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
388 def test_dsidm_uniquegroup_get_rename_keep_old_rdn(topology_st, create_test_uniquegroup, add_description):
389 """ Test dsidm uniquegroup rename option with keep-old-rdn
390
391 :id: 4a4a3734-7c57-4f85-9cfe-a3c24f7037bf
392 :setup: Standalone instance
393 :steps:
394 1. Run dsidm uniquegroup rename option on created uniquegroup with keep-old-rdn
395 2. Check the uniquegroup has another cn attribute with the old rdn
396 3. Check the old uniquegroup is deleted
397 :expectedresults:
398 1. Success
399 2. Success
400 3. Success
401 """
402
403 standalone = topology_st.standalone
404 uniquegroups = UniqueGroups(standalone, DEFAULT_SUFFIX)
405 test_uniquegroup = uniquegroups.get(uniquegroup_name)
406
407 args = FakeArgs()
408 args.selector = uniquegroup_name
409 args.new_name = 'new_uniquegroup'
410 args.keep_old_rdn = True
411
412 log.info('Test dsidm uniquegroup rename')
413 rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
414 new_uniquegroup = uniquegroups.get(args.new_name)
415 output = 'Successfully renamed to {}'.format(new_uniquegroup.dn)
416 check_value_in_log_and_reset(topology_st, check_value=output)
417
418 log.info('Verify the new uniquegroup does not have cn attribute with the old rdn')
419 assert new_uniquegroup.present('cn', uniquegroup_name)
420 assert new_uniquegroup.get_attr_val_utf8('description') == uniquegroup_name
421
422 log.info('Verify old uniquegroup dn does not exist')
423 assert not test_uniquegroup.exists()
424
425 log.info('Clean up')
426 new_uniquegroup.delete()
427
428
429 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
430 def test_dsidm_uniquegroup_members_add_remove(topology_st, create_test_uniquegroup):
431 """ Test dsidm uniquegroup members, add_member and remove_members options
432
433 :id: 4903f069-c7b7-4b80-844c-6fb4b320a5b4
434 :setup: Standalone instance
435 :steps:
436 1. Show members of a uniquegroup using dsidm uniquegroup members
437 2. Add member to the uniquegroup using dsidm uniquegroup add_member
438 3. Verify the added member is associated with the uniquegroup using dsidm uniquegroup member
439 4. Remove the member from the uniquegroup using dsidm uniquegroup remove_member
440 5. Verify the member is no longer associated with the uniquegroup using dsidm uniquegroup member
441 :expectedresults:
442 1. Uniquegroup has no members
443 2. Member is successfully added
444 3. Shows previously added member
445 4. Member is successfully removed
446 5. Uniquegroup has no members
447 """
448
449 standalone = topology_st.standalone
450
451 member = 'uid=new_member'
452 output_no_member = 'No members to display'
453 output_with_member = 'dn: {}'.format(member)
454 output_add_member = 'added member: {}'.format(member)
455 output_remove_member = 'removed member: {}'.format(member)
456
457 args = FakeArgs()
458 args.cn = uniquegroup_name
459 args.json = False
460
461 log.info('Test dsidm uniquegroup members to show no associated members')
462 members(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
463 check_value_in_log_and_reset(topology_st, check_value=output_no_member)
464
465 log.info('Test dsidm uniquegroup add_member')
466 args.dn = member
467 add_member(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
468 check_value_in_log_and_reset(topology_st, check_value=output_add_member)
469
470 log.info('Verify the added member is associated with the uniquegroup')
471 members(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
472 check_value_in_log_and_reset(topology_st, check_value=output_with_member)
473
474 # Test json
475 args.json = True
476 members(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
477 result = topology_st.logcap.get_raw_outputs()
478 json_result = json.loads(result[0])
479 assert len(json_result['members']) == 1
480 args.json = False
481
482 log.info('Test dsidm uniquegroup remove_member')
483 remove_member(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
484 check_value_in_log_and_reset(topology_st, check_value=output_remove_member)
485
486 log.info('Verify the added member is no longer associated with the uniquegroup')
487 members(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
488 check_value_in_log_and_reset(topology_st, check_value=output_no_member)
489
490 # Test json
491 args.json = True
492 members(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
493 result = topology_st.logcap.get_raw_outputs()
494 json_result = json.loads(result[0])
495 assert len(json_result['members']) == 0
496 args.json = False
497
498
499 if __name__ == '__main__':
500 # Run isolated
501 # -s for DEBUG mode
502 CURRENT_FILE = os.path.realpath(__file__)
503 pytest.main("-s {}".format(CURRENT_FILE))