Debian Codegraph @

dirsrvtests/tests/suites/basic/modrdn_bulk_children_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2026 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 logging
10 import os
11 import pytest
12
13 from lib389._constants import DEFAULT_SUFFIX
14 from lib389.idm.organizationalunit import OrganizationalUnit, OrganizationalUnits
15 from lib389.idm.user import UserAccount, UserAccounts
16 from test389.topologies import topology_st as topo
17
18 pytestmark = pytest.mark.tier1
19
20 log = logging.getLogger(__name__)
21
22 NUM_USERS = 110
23 ORGUNIT1_RDN = 'ou=people'
24 ORGUNIT2_RDN = 'ou=orgunit2'
25 ORGUNIT1_DN = f'{ORGUNIT1_RDN},{DEFAULT_SUFFIX}'
26 ORGUNIT2_DN = f'{ORGUNIT2_RDN},{DEFAULT_SUFFIX}'
27 ORGUNIT1_UNDER_ORGUNIT2_DN = f'{ORGUNIT1_RDN},{ORGUNIT2_DN}'
28
29
30 def _expected_user_dn(uid_str, parent_dn):
31 return f'uid={uid_str},{parent_dn}'
32
33
34 def _create_orgunit_users(inst):
35 """Create uid=1..NUM_USERS under ou=people."""
36 users = UserAccounts(inst, DEFAULT_SUFFIX)
37 for uid in range(1, NUM_USERS + 1):
38 uid_str = str(uid)
39 users.create(
40 f'uid={uid_str}',
41 properties={
42 'uid': uid_str,
43 'cn': f'user {uid_str}',
44 'sn': f'user{uid_str}',
45 'uidNumber': str(1000 + uid),
46 'gidNumber': '2000',
47 'homeDirectory': f'/home/{uid_str}',
48 },
49 )
50
51
52 def test_modrdn_orgunit_moves_users_under_new_superior(topo, request):
53 """Modrdn an organizational unit to a new superior and verify child user DNs
54
55 :id: 12dae475-b778-4ba6-a48b-d713ff2c0e58
56 :setup: Standalone Instance
57 :steps:
58 1. Create 110 users under ou=people (uid=1 through uid=110)
59 2. Create ou=orgunit2 under the default suffix
60 3. Modrdn ou=people with superior ou=orgunit2
61 4. Verify every uid=1..110 has a DN under ou=people,ou=orgunit2
62 :expectedresults:
63 1. All 110 users are created
64 2. orgunit2 is created
65 3. Modrdn succeeds
66 4. All 110 user DNs are uid=N,ou=people,ou=orgunit2,<suffix> and none remain at the old location
67 """
68 inst = topo.standalone
69 ou2 = OrganizationalUnits(inst, DEFAULT_SUFFIX).create(properties={'ou': 'orgunit2'})
70 assert ou2.exists()
71
72 _create_orgunit_users(inst)
73 for uid in range(1, NUM_USERS + 1):
74 uid_str = str(uid)
75 assert UserAccount(inst, _expected_user_dn(uid_str, ORGUNIT1_DN)).exists()
76
77 people_ou = OrganizationalUnit(inst, ORGUNIT1_DN)
78 people_ou.rename(ORGUNIT1_RDN, newsuperior=ou2.dn)
79 assert OrganizationalUnit(inst, ORGUNIT1_UNDER_ORGUNIT2_DN).exists()
80 assert not OrganizationalUnit(inst, ORGUNIT1_DN).exists()
81
82 for uid in range(1, NUM_USERS + 1):
83 uid_str = str(uid)
84 expected_dn = _expected_user_dn(uid_str, ORGUNIT1_UNDER_ORGUNIT2_DN)
85 user = UserAccount(inst, expected_dn)
86 assert user.exists(), expected_dn
87 assert user.dn == expected_dn
88 old_dn = _expected_user_dn(uid_str, ORGUNIT1_DN)
89 assert not UserAccount(inst, old_dn).exists(), old_dn
90
91
92 if __name__ == '__main__':
93 # Run isolated
94 # -s for DEBUG mode
95 CURRENT_FILE = os.path.realpath(__file__)
96 pytest.main(["-s", CURRENT_FILE])