Debian Codegraph @

dirsrvtests/tests/suites/clu/dsidm_posixgroup_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2024 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 logging
11 import os
12 import json
13
14 from lib389 import DEFAULT_SUFFIX
15 from lib389.cli_idm.posixgroup import list, get, get_dn, create, delete, modify, rename
16 from test389.topologies import topology_st
17 from lib389.cli_base import FakeArgs
18 from lib389.utils import ds_is_older, ensure_str, is_a_dn
19 from lib389.idm.posixgroup import PosixGroups
20 from . import check_value_in_log_and_reset
21
22 pytestmark = pytest.mark.tier0
23
24 logging.getLogger(__name__).setLevel(logging.DEBUG)
25 log = logging.getLogger(__name__)
26
27 posixgroup_name = 'test_posixgroup'
28
29 @pytest.fixture(scope="function")
30 def create_test_posixgroup(topology_st, request):
31 posixgroups = PosixGroups(topology_st.standalone, DEFAULT_SUFFIX)
32
33 log.info('Create test posixgroup')
34 if posixgroups.exists(posixgroup_name):
35 test_posixgroup = posixgroups.get(posixgroup_name)
36 test_posixgroup.delete()
37
38 properties = FakeArgs()
39 properties.cn = posixgroup_name
40 properties.gidNumber = '3000'
41 create(topology_st.standalone, DEFAULT_SUFFIX, topology_st.logcap.log, properties)
42 test_posixgroup = posixgroups.get(posixgroup_name)
43
44 def fin():
45 log.info('Delete test posixgroup')
46 if test_posixgroup.exists():
47 test_posixgroup.delete()
48
49 request.addfinalizer(fin)
50
51
52 @pytest.fixture(scope="function")
53 def add_description(topology_st, request):
54 args = FakeArgs()
55 args.selector = posixgroup_name
56 args.changes = ['add:description:{}'.format(posixgroup_name)]
57 modify(topology_st.standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
58
59
60 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
61 def test_dsidm_posixgroup_create(topology_st):
62 """ Test dsidm posixgroup create option
63
64 :id: 90c988df-ff98-4004-838d-2012d77c6bd7
65 :setup: Standalone instance
66 :steps:
67 1. Run dsidm posixgroup create
68 2. Check that a message is provided on creation
69 3. Check that created posixgroup exists
70 :expectedresults:
71 1. Success
72 2. Success
73 3. Success
74 """
75
76 standalone = topology_st.standalone
77 output = 'Successfully created {}'.format(posixgroup_name)
78
79 args = FakeArgs()
80 args.cn = posixgroup_name
81 args.gidNumber = '3000'
82
83 log.info('Test dsidm posixgroup create')
84 create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
85 check_value_in_log_and_reset(topology_st, check_value=output)
86
87 log.info('Check that posixgroup is present')
88 posixgroups = PosixGroups(standalone, DEFAULT_SUFFIX)
89 new_posixgroup = posixgroups.get(posixgroup_name)
90 assert new_posixgroup.exists()
91 assert new_posixgroup.present('gidNumber', '3000')
92
93 log.info('Clean up for next test')
94 new_posixgroup.delete()
95
96
97 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
98 def test_dsidm_posixgroup_delete(topology_st, create_test_posixgroup):
99 """ Test dsidm posixgroup delete option
100
101 :id: d471c8b9-6a67-4b50-a3c7-651f1b8c1283
102 :setup: Standalone instance
103 :steps:
104 1. Run dsidm posixgroup delete on a created group
105 2. Check that a message is provided on deletion
106 3. Check that posixgroup does not exist
107 :expectedresults:
108 1. Success
109 2. Success
110 3. Success
111 """
112
113 standalone = topology_st.standalone
114 posixgroups = PosixGroups(standalone, DEFAULT_SUFFIX)
115 test_posixgroup = posixgroups.get(posixgroup_name)
116 output = 'Successfully deleted {}'.format(test_posixgroup.dn)
117
118 args = FakeArgs()
119 args.dn = test_posixgroup.dn
120
121 log.info('Test dsidm posixgroup 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 posixgroup does not exist')
126 assert not test_posixgroup.exists()
127
128
129 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
130 def test_dsidm_posixgroup_modify(topology_st, create_test_posixgroup):
131 """ Test dsidm posixgroup modify option
132
133 :id: c166ed02-56cc-4e85-bf19-d63142fac711
134 :setup: Standalone instance
135 :steps:
136 1. Run dsidm posixgroup modify add description value
137 2. Run dsidm posixgroup modify replace description value
138 3. Run dsidm posixgroup modify delete description value
139 :expectedresults:
140 1. Description value is present
141 2. Description value is replaced with the new one
142 3. Description value is deleted
143 """
144
145 standalone = topology_st.standalone
146 posixgroups = PosixGroups(standalone, DEFAULT_SUFFIX)
147 test_posixgroup = posixgroups.get(posixgroup_name)
148 output = 'Successfully modified {}'.format(test_posixgroup.dn)
149
150 args = FakeArgs()
151 args.selector = posixgroup_name
152
153 log.info('Test dsidm posixgroup modify add')
154 args.changes = ['add:description:test_posixgroup_description']
155 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
156 check_value_in_log_and_reset(topology_st, check_value=output)
157 assert test_posixgroup.present('description', 'test_posixgroup_description')
158
159 log.info('Test dsidm posixgroup modify replace')
160 args.changes = ['replace:description:new_posixgroup_description']
161 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
162 check_value_in_log_and_reset(topology_st, check_value=output)
163 assert test_posixgroup.present('description', 'new_posixgroup_description')
164
165 log.info('Test dsidm posixgroup modify delete')
166 args.changes = ['delete:description:new_posixgroup_description']
167 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
168 check_value_in_log_and_reset(topology_st, check_value=output)
169 assert not test_posixgroup.present('description', 'new_posixgroup_description')
170
171
172 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
173 def test_dsidm_posixgroup_list(topology_st, create_test_posixgroup):
174 """ Test dsidm posixgroup list option
175
176 :id: 03b72540-2c2b-405d-a918-4ca0dbddfcc5
177 :setup: Standalone instance
178 :steps:
179 1. Run dsidm posixgroup list option without json
180 2. Check the output content is correct
181 3. Run dsidm posixgroup list option with json
182 4. Check the output content is correct
183 5. Delete the posixgroup
184 6. Check the posixgroup is not in the list with json
185 7. Check the posixgroup is not in the list without json
186 :expectedresults:
187 1. Success
188 2. Success
189 3. Success
190 4. Success
191 5. Success
192 6. Success
193 7. Success
194 """
195
196 standalone = topology_st.standalone
197 args = FakeArgs()
198 args.json = False
199 args.full_dn = False
200 json_list = ['type',
201 'list',
202 'items']
203
204 log.info('Empty the log file to prevent false data to check about posixgroup')
205 topology_st.logcap.flush()
206
207 log.info('Test dsidm posixgroup list without json')
208 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
209 check_value_in_log_and_reset(topology_st, check_value=posixgroup_name)
210
211 log.info('Test dsidm posixgroup list with json')
212 args.json = True
213 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
214 check_value_in_log_and_reset(topology_st, content_list=json_list, check_value=posixgroup_name)
215
216 log.info('Test full_dn option with list')
217 args.full_dn = True
218 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
219 result = topology_st.logcap.get_raw_outputs()
220 json_result = json.loads(result[0])
221 assert is_a_dn(json_result['items'][0])
222 args.full_dn = False
223
224 log.info('Delete the posixgroup')
225 posixgroups = PosixGroups(standalone, DEFAULT_SUFFIX)
226 test_posixgroup = posixgroups.get(posixgroup_name)
227 test_posixgroup.delete()
228
229 log.info('Test empty dsidm posixgroup list with json')
230 topology_st.logcap.flush()
231 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
232 check_value_in_log_and_reset(topology_st, content_list=json_list, check_value_not=posixgroup_name)
233
234 log.info('Test empty dsidm posixgroup list without json')
235 args.json = False
236 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
237 check_value_in_log_and_reset(topology_st, check_value_not=posixgroup_name)
238
239
240 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
241 def test_dsidm_posixgroup_get_dn(topology_st, create_test_posixgroup):
242 """ Test dsidm posixgroup get_dn option
243
244 :id: 2ca19f8c-6f26-4dff-9e1f-8801a748b23b
245 :setup: Standalone instance
246 :steps:
247 1. Run dsidm group get_dn for created group without json
248 2. Check the output content is correct
249 3. Run dsidm group get_dn for created group 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 posixgroups = PosixGroups(standalone, DEFAULT_SUFFIX)
260 test_posixgroup = posixgroups.get(posixgroup_name)
261 args = FakeArgs()
262 args.dn = test_posixgroup.dn
263 args.json = False
264
265 log.info('Empty the log file to prevent false data to check about group')
266 topology_st.logcap.flush()
267
268 log.info('Test dsidm group 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=posixgroup_name)
271
272 log.info('Test dsidm group 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=posixgroup_name)
276
277
278 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
279 def test_dsidm_posixgroup_get_rdn(topology_st, create_test_posixgroup):
280 """ Test dsidm group get option
281
282 :id: 54fe642d-bbaf-480e-8bb0-a7dc50f8f594
283 :setup: Standalone instance
284 :steps:
285 1. Run dsidm get option for created group with json
286 2. Check the output content is correct
287 3. Run dsidm get option for created group 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 posixgroups = PosixGroups(standalone, DEFAULT_SUFFIX)
298 test_posixgroup = posixgroups.get(posixgroup_name)
299
300 posixgroup_content = ['dn: {}'.format(test_posixgroup.dn),
301 'cn: {}'.format(test_posixgroup.rdn),
302 'gidNumber: 3000',
303 'objectClass: top',
304 'objectClass: groupOfNames',
305 'objectClass: posixGroup',
306 'objectClass: nsMemberOf']
307
308 json_content = ['attrs',
309 'objectclass',
310 'top',
311 'groupOfNames',
312 'posixGroup',
313 'nsMemberOf',
314 'cn',
315 test_posixgroup.rdn,
316 'gidnumber',
317 '3000',
318 'creatorsname',
319 'cn=directory manager',
320 'modifiersname',
321 'createtimestamp',
322 'modifytimestamp',
323 'nsuniqueid',
324 'parentid',
325 'entryid',
326 'entryuuid',
327 'dsentrydn',
328 'entrydn',
329 test_posixgroup.dn]
330
331 args = FakeArgs()
332 args.json = False
333 args.selector = posixgroup_name
334
335 log.info('Empty the log file to prevent false data to check about posixgroup')
336 topology_st.logcap.flush()
337
338 log.info('Test dsidm posixgroup get without json')
339 get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
340 check_value_in_log_and_reset(topology_st, content_list=posixgroup_content)
341
342 log.info('Test dsidm posixgroup get with json')
343 args.json = True
344 get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
345 check_value_in_log_and_reset(topology_st, content_list=json_content)
346
347
348 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
349 def test_dsidm_posixgroup_rename(topology_st, create_test_posixgroup, add_description):
350 """ Test dsidm posixgroup rename option
351
352 :id: 1919805e-efd6-41da-91e7-59c011546993
353 :setup: Standalone instance
354 :steps:
355 1. Run dsidm posixgroup rename option on created posixgroup
356 2. Check the group does not have another cn attribute with the old rdn
357 3. Check the old group is deleted
358 :expectedresults:
359 1. Success
360 2. Success
361 3. Success
362 """
363
364 standalone = topology_st.standalone
365 posixgroups = PosixGroups(standalone, DEFAULT_SUFFIX)
366 test_posixgroup = posixgroups.get(posixgroup_name)
367
368 args = FakeArgs()
369 args.selector = posixgroup_name
370 args.new_name = 'new_posixgroup'
371 args.keep_old_rdn = False
372
373 log.info('Test dsidm posixgroup rename')
374 rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
375 new_posixgroup = posixgroups.get(args.new_name)
376 output = 'Successfully renamed to {}'.format(new_posixgroup.dn)
377 check_value_in_log_and_reset(topology_st, check_value=output)
378
379 log.info('Verify the new posixgroup does not have cn attribute with the old rdn')
380 assert not new_posixgroup.present('cn', posixgroup_name)
381 assert new_posixgroup.get_attr_val_utf8('description') == posixgroup_name
382
383 log.info('Verify old posixgroup dn does not exist')
384 assert not test_posixgroup.exists()
385
386 log.info('Clean up')
387 new_posixgroup.delete()
388
389
390 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
391 def test_dsidm_posixgroup_rename_keep_old_rdn(topology_st, create_test_posixgroup, add_description):
392 """ Test dsidm posixgroup rename option with keep-old-rdn
393
394 :id: 80b5faf0-dd84-4853-a21a-739388c112f5
395 :setup: Standalone instance
396 :steps:
397 1. Run dsidm posixgroup rename option on created posixgroup with keep-old-rdn
398 2. Check the group has another cn attribute with the old rdn
399 3. Check the old group is deleted
400 :expectedresults:
401 1. Success
402 2. Success
403 3. Success
404 """
405
406 standalone = topology_st.standalone
407 posixgroups = PosixGroups(standalone, DEFAULT_SUFFIX)
408 test_posixgroup = posixgroups.get(posixgroup_name)
409
410 args = FakeArgs()
411 args.selector = posixgroup_name
412 args.new_name = 'new_posixgroup'
413 args.keep_old_rdn = True
414
415 log.info('Test dsidm posixgroup rename with keep-old-rdn')
416 rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
417 new_posixgroup = posixgroups.get(args.new_name)
418 output = 'Successfully renamed to {}'.format(new_posixgroup.dn)
419 check_value_in_log_and_reset(topology_st, check_value=output)
420
421 log.info('Verify the new posixgroup has cn attribute with the old rdn')
422 assert new_posixgroup.present('cn', posixgroup_name)
423 assert new_posixgroup.get_attr_val_utf8('description') == posixgroup_name
424
425 log.info('Verify old posixgroup dn does not exist')
426 assert not test_posixgroup.exists()
427
428 log.info('Clean up')
429 new_posixgroup.delete()
430
431
432 if __name__ == '__main__':
433 # Run isolated
434 # -s for DEBUG mode
435 CURRENT_FILE = os.path.realpath(__file__)
436 pytest.main("-s %s" % CURRENT_FILE)