| 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 |
from lib389.dbgen import dbgen_users, get_index |
| 13 |
from lib389.idm.organizationalunit import OrganizationalUnit |
| 14 |
from lib389.idm.user import UserAccount, UserAccounts |
| 15 |
from lib389.tasks import ImportTask |
| 16 |
from test389.topologies import topology_st as topo |
| 17 |
|
| 18 |
log = logging.getLogger(__name__) |
| 19 |
|
| 20 |
SUFFIX = "dc=Example,DC=COM" |
| 21 |
SUBTREE = "ou=People,dc=Example,DC=COM" |
| 22 |
NEW_SUBTREE = "ou=humans,dc=Example,DC=COM" |
| 23 |
USER_DN = "uid=tUser,ou=People,dc=Example,DC=COM" |
| 24 |
NEW_USER_DN = "uid=tUser,ou=humans,dc=Example,DC=COM" |
| 25 |
NEW_USER_NORM_DN = "uid=tUser,ou=humans,dc=example,dc=com" |
| 26 |
|
| 27 |
IMPORT_LDIF_NAME = "ds_entrydn_import.ldif" |
| 28 |
NUM_IMPORT_ENTRIES = 10 |
| 29 |
IMPORT_ENTRY_NAME = "importuser" |
| 30 |
IMPORT_PARENT = f"ou=people,{SUFFIX}" |
| 31 |
|
| 32 |
|
| 33 |
def _import_user_dns(): |
| 34 |
"""DNs produced by dbgen_users(generic=True, entry_name=IMPORT_ENTRY_NAME).""" |
| 35 |
return [ |
| 36 |
f"uid={IMPORT_ENTRY_NAME}{get_index(i, NUM_IMPORT_ENTRIES)},{IMPORT_PARENT}" |
| 37 |
for i in range(1, NUM_IMPORT_ENTRIES + 1) |
| 38 |
] |
| 39 |
|
| 40 |
|
| 41 |
def test_dsentrydn(topo): |
| 42 |
"""Test that the dsentrydn attribute is properly maintained and preserves the case of the DN |
| 43 |
|
| 44 |
:id: f0f2fe6b-c70d-4de1-a9a9-06dda74e7c30 |
| 45 |
:setup: Standalone Instance |
| 46 |
:steps: |
| 47 |
1. Create user and make sure dsentrydn is set to the correct value/case |
| 48 |
2. Moddn of "ou=people" and check dsentrydn is correct for parent and the children |
| 49 |
3. Check the DN matches dsEntryDN |
| 50 |
4. Disable nsslapd-return-original-entrydn |
| 51 |
5. Check the DN matches normalized DN |
| 52 |
:expectedresults: |
| 53 |
1. Success |
| 54 |
2. Success |
| 55 |
3. Success |
| 56 |
4. Success |
| 57 |
5. Success |
| 58 |
""" |
| 59 |
|
| 60 |
inst = topo.standalone |
| 61 |
inst.config.replace('nsslapd-return-original-entrydn', 'on') |
| 62 |
|
| 63 |
# Create user and makes sure "dsEntryDN" is set correctly |
| 64 |
users = UserAccounts(inst, SUFFIX) |
| 65 |
user_properties = { |
| 66 |
'uid': 'tUser', |
| 67 |
'givenname': 'test', |
| 68 |
'cn': 'Test User', |
| 69 |
'sn': 'user', |
| 70 |
'userpassword': 'password', |
| 71 |
'uidNumber': '1000', |
| 72 |
'gidNumber': '2000', |
| 73 |
'homeDirectory': '/home/tUser' |
| 74 |
} |
| 75 |
user = users.create(properties=user_properties) |
| 76 |
assert user.get_attr_val_utf8('dsentrydn') == USER_DN |
| 77 |
|
| 78 |
# Move subtree ou=people to ou=humans |
| 79 |
ou = OrganizationalUnit(inst, SUBTREE) |
| 80 |
ou.rename("ou=humans", SUFFIX) # NEW_SUBTREE |
| 81 |
|
| 82 |
# check dsEntryDN is properly updated to new subtree |
| 83 |
ou = OrganizationalUnit(inst, NEW_SUBTREE) |
| 84 |
assert ou.get_attr_val_utf8('dsentrydn') == NEW_SUBTREE |
| 85 |
|
| 86 |
user = UserAccount(inst, NEW_USER_DN) |
| 87 |
assert user.get_attr_val_utf8('dsentrydn') == NEW_USER_DN |
| 88 |
|
| 89 |
# Check DN returned to client matches "dsEntryDN" |
| 90 |
users = UserAccounts(inst, SUFFIX, rdn="ou=humans").list() |
| 91 |
for user in users: |
| 92 |
if user.rdn.startswith("tUser"): |
| 93 |
assert user.dn == NEW_USER_DN |
| 94 |
break |
| 95 |
|
| 96 |
# Disable 'nsslapd-return-original-entrydn' and check DN is normalized |
| 97 |
inst.config.replace('nsslapd-return-original-entrydn', 'off') |
| 98 |
inst.restart() |
| 99 |
users = UserAccounts(inst, SUFFIX, rdn="ou=humans").list() |
| 100 |
for user in users: |
| 101 |
if user.rdn.startswith("tUser"): |
| 102 |
assert user.dn == NEW_USER_NORM_DN |
| 103 |
break |
| 104 |
|
| 105 |
|
| 106 |
def test_dsentrydn_import_ldif(topo, request): |
| 107 |
"""Imported entries receive dsEntryDN matching their DN |
| 108 |
|
| 109 |
:id: 8457793e-8374-4435-b6b7-701b58246d91 |
| 110 |
:setup: Standalone Instance |
| 111 |
:steps: |
| 112 |
1. Generate an LDIF with 10 users under ou=people using dbgen_users |
| 113 |
2. Import the LDIF into the suffix |
| 114 |
3. Verify each imported entry has dsentrydn set to its DN |
| 115 |
:expectedresults: |
| 116 |
1. LDIF file is created with 10 user entries |
| 117 |
2. Online import completes successfully |
| 118 |
3. All 10 entries have dsentrydn matching their DN |
| 119 |
""" |
| 120 |
inst = topo.standalone |
| 121 |
|
| 122 |
ldif_path = os.path.join(inst.get_ldif_dir(), IMPORT_LDIF_NAME) |
| 123 |
dbgen_users( |
| 124 |
inst, |
| 125 |
NUM_IMPORT_ENTRIES, |
| 126 |
ldif_path, |
| 127 |
SUFFIX, |
| 128 |
generic=True, |
| 129 |
entry_name=IMPORT_ENTRY_NAME, |
| 130 |
parent=IMPORT_PARENT, |
| 131 |
) |
| 132 |
|
| 133 |
import_task = ImportTask(inst) |
| 134 |
import_task.import_suffix_from_ldif(ldiffile=ldif_path, suffix=SUFFIX) |
| 135 |
import_task.wait() |
| 136 |
|
| 137 |
for dn in _import_user_dns(): |
| 138 |
user = UserAccount(inst, dn) |
| 139 |
assert user.exists(), dn |
| 140 |
assert user.get_attr_val_utf8('dsentrydn') == dn |
| 141 |
|
| 142 |
|
| 143 |
if __name__ == '__main__': |
| 144 |
# Run isolated |
| 145 |
# -s for DEBUG mode |
| 146 |
CURRENT_FILE = os.path.realpath(__file__) |
| 147 |
pytest.main(["-s", CURRENT_FILE]) |
| 148 |
|