| 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 |
import pytest |
| 10 |
import ldap |
| 11 |
import logging |
| 12 |
from lib389.utils import ensure_str, ds_is_older |
| 13 |
from test389.topologies import topology_st |
| 14 |
from lib389._constants import DEFAULT_SUFFIX |
| 15 |
from lib389.plugins import MemberOfPlugin, ReferentialIntegrityPlugin |
| 16 |
from lib389.idm.user import UserAccount, UserAccounts |
| 17 |
from lib389.idm.group import Group, Groups |
| 18 |
from lib389.idm.nscontainer import nsContainers |
| 19 |
|
| 20 |
log = logging.getLogger(__name__) |
| 21 |
|
| 22 |
pytestmark = [pytest.mark.tier1, |
| 23 |
pytest.mark.skipif(ds_is_older('1.3.4'), reason="Not implemented")] |
| 24 |
|
| 25 |
SCOPE_IN_CN = 'in' |
| 26 |
SCOPE_OUT_CN = 'out' |
| 27 |
SCOPE_IN_DN = f'cn={SCOPE_IN_CN},{DEFAULT_SUFFIX}' |
| 28 |
SCOPE_OUT_DN = f'cn={SCOPE_OUT_CN},{DEFAULT_SUFFIX}' |
| 29 |
|
| 30 |
PROVISIONING_CN = "provisioning" |
| 31 |
PROVISIONING_DN = f'cn={PROVISIONING_CN},{SCOPE_IN_DN}' |
| 32 |
|
| 33 |
ACTIVE_CN = "active" |
| 34 |
STAGE_CN = "staged users" |
| 35 |
ACTIVE_DN = f"cn={ACTIVE_CN},{SCOPE_IN_DN}" |
| 36 |
STAGE_DN = f"cn={STAGE_CN},{PROVISIONING_DN}" |
| 37 |
|
| 38 |
STAGE_USER_CN = "stage guy" |
| 39 |
ACTIVE_USER_CN = "active guy" |
| 40 |
OUT_USER_CN = "out guy" |
| 41 |
|
| 42 |
STAGE_GROUP_CN = "stage group" |
| 43 |
ACTIVE_GROUP_CN = "active group" |
| 44 |
OUT_GROUP_CN = "out group" |
| 45 |
INDIRECT_ACTIVE_GROUP_CN = "indirect active group" |
| 46 |
|
| 47 |
|
| 48 |
""" |
| 49 |
Tree structure: |
| 50 |
┌─────────────────┐ |
| 51 |
│dc=example,dc=com│ |
| 52 |
└────────┬────────┘ |
| 53 |
┌─────────┴──────────────────────────┐ |
| 54 |
┌──┴───────────┐ ┌──┴───────────┐ |
| 55 |
│cn=in │ │cn=out │ |
| 56 |
|(active scope)| |(not in scope)| |
| 57 |
└──┬───────────┘ └──────────────┘ |
| 58 |
┌───────┴───────────┐ |
| 59 |
┌───┴───────┐ ┌──────┴─────────┐ |
| 60 |
│ cn=active │ │cn=provisioning │ |
| 61 |
| | |(excluded scope)| |
| 62 |
└───────────┘ └───────┬────────┘ |
| 63 |
│ |
| 64 |
┌────┴───┐ |
| 65 |
│cn=stage│ |
| 66 |
└────────┘ |
| 67 |
""" |
| 68 |
|
| 69 |
|
| 70 |
@pytest.fixture(scope='function') |
| 71 |
def containers(topology_st, request): |
| 72 |
"""Create containers for the tests""" |
| 73 |
log.info('Create containers for the tests') |
| 74 |
containers = nsContainers(topology_st.standalone, DEFAULT_SUFFIX) |
| 75 |
cont_scope_in = containers.create(properties={'cn': SCOPE_IN_CN}) |
| 76 |
cont_scope_out = containers.create(properties={'cn': SCOPE_OUT_CN}) |
| 77 |
|
| 78 |
containers_scope_in = nsContainers(topology_st.standalone, cont_scope_in.dn) |
| 79 |
cont_active = containers_scope_in.create(properties={'cn': ACTIVE_CN}) |
| 80 |
cont_provisioning = containers_scope_in.create(properties={'cn': PROVISIONING_CN}) |
| 81 |
|
| 82 |
containers_provisioning = nsContainers(topology_st.standalone, cont_provisioning.dn) |
| 83 |
cont_stage = containers_provisioning.create(properties={'cn': STAGE_CN}) |
| 84 |
|
| 85 |
def fin(): |
| 86 |
log.info('Delete containers') |
| 87 |
cont_stage.delete() |
| 88 |
cont_provisioning.delete() |
| 89 |
cont_active.delete() |
| 90 |
cont_scope_out.delete() |
| 91 |
cont_scope_in.delete() |
| 92 |
|
| 93 |
request.addfinalizer(fin) |
| 94 |
|
| 95 |
|
| 96 |
@pytest.fixture(scope='function') |
| 97 |
def active_group(topology_st, request): |
| 98 |
log.info('Create active group') |
| 99 |
active_groups = Groups(topology_st.standalone, DEFAULT_SUFFIX, |
| 100 |
rdn=f'cn={ACTIVE_CN},cn={SCOPE_IN_CN}') |
| 101 |
if active_groups.exists(ACTIVE_GROUP_CN): |
| 102 |
active_groups.get(ACTIVE_GROUP_CN).delete() |
| 103 |
|
| 104 |
active_group = active_groups.create(properties={'cn': ACTIVE_GROUP_CN}) |
| 105 |
|
| 106 |
def fin(): |
| 107 |
if active_group.exists(): |
| 108 |
log.info('Delete active group') |
| 109 |
active_group.delete() |
| 110 |
|
| 111 |
request.addfinalizer(fin) |
| 112 |
|
| 113 |
return active_group |
| 114 |
|
| 115 |
|
| 116 |
@pytest.fixture(scope='function') |
| 117 |
def stage_group(topology_st, request): |
| 118 |
log.info('Create stage group') |
| 119 |
stage_groups = Groups(topology_st.standalone, DEFAULT_SUFFIX, |
| 120 |
rdn=f'cn={STAGE_CN},cn={PROVISIONING_CN},cn={SCOPE_IN_CN}') |
| 121 |
if stage_groups.exists(STAGE_GROUP_CN): |
| 122 |
stage_groups.get(STAGE_GROUP_CN).delete() |
| 123 |
|
| 124 |
stage_group = stage_groups.create(properties={'cn': STAGE_GROUP_CN}) |
| 125 |
|
| 126 |
def fin(): |
| 127 |
if stage_group.exists(): |
| 128 |
log.info('Delete stage group') |
| 129 |
stage_group.delete() |
| 130 |
|
| 131 |
request.addfinalizer(fin) |
| 132 |
|
| 133 |
return stage_group |
| 134 |
|
| 135 |
|
| 136 |
@pytest.fixture(scope='function') |
| 137 |
def out_group(topology_st, request): |
| 138 |
log.info('Create out group') |
| 139 |
out_groups = Groups(topology_st.standalone, DEFAULT_SUFFIX, |
| 140 |
rdn=f'cn={SCOPE_OUT_CN}') |
| 141 |
if out_groups.exists(OUT_GROUP_CN): |
| 142 |
out_groups.get(OUT_GROUP_CN).delete() |
| 143 |
|
| 144 |
out_group = out_groups.create(properties={'cn': OUT_GROUP_CN}) |
| 145 |
|
| 146 |
def fin(): |
| 147 |
if out_group.exists(): |
| 148 |
log.info('Delete out group') |
| 149 |
out_group.delete() |
| 150 |
|
| 151 |
request.addfinalizer(fin) |
| 152 |
|
| 153 |
return out_group |
| 154 |
|
| 155 |
|
| 156 |
@pytest.fixture(scope='function') |
| 157 |
def indirect_active_group(topology_st, request): |
| 158 |
log.info('Create indirect active group') |
| 159 |
indirect_active_groups = Groups(topology_st.standalone, DEFAULT_SUFFIX, |
| 160 |
rdn=f'cn={ACTIVE_CN},cn={SCOPE_IN_CN}') |
| 161 |
if indirect_active_groups.exists(INDIRECT_ACTIVE_GROUP_CN): |
| 162 |
indirect_active_groups.get(INDIRECT_ACTIVE_GROUP_CN).delete() |
| 163 |
|
| 164 |
indirect_active_group = indirect_active_groups.create(properties={'cn': INDIRECT_ACTIVE_GROUP_CN}) |
| 165 |
|
| 166 |
def fin(): |
| 167 |
if indirect_active_group.exists(): |
| 168 |
log.info('Delete indirect active group') |
| 169 |
indirect_active_group.delete() |
| 170 |
|
| 171 |
request.addfinalizer(fin) |
| 172 |
|
| 173 |
return indirect_active_group |
| 174 |
|
| 175 |
|
| 176 |
@pytest.fixture(scope='function') |
| 177 |
def active_user(topology_st, request): |
| 178 |
log.info('Create active user') |
| 179 |
active_users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX, |
| 180 |
rdn=f'cn={ACTIVE_CN},cn={SCOPE_IN_CN}') |
| 181 |
if active_users.exists(ACTIVE_USER_CN): |
| 182 |
active_users.get(ACTIVE_USER_CN).delete() |
| 183 |
|
| 184 |
active_user = active_users.create(properties={'cn': ACTIVE_USER_CN, |
| 185 |
'uid': ACTIVE_USER_CN, |
| 186 |
'sn': ACTIVE_USER_CN, |
| 187 |
'uidNumber': '1', |
| 188 |
'gidNumber': '11', |
| 189 |
'homeDirectory': f'/home/{ACTIVE_USER_CN}'}) |
| 190 |
|
| 191 |
def fin(): |
| 192 |
if active_user.exists(): |
| 193 |
log.info('Delete active user') |
| 194 |
active_user.delete() |
| 195 |
|
| 196 |
request.addfinalizer(fin) |
| 197 |
|
| 198 |
return active_user |
| 199 |
|
| 200 |
|
| 201 |
@pytest.fixture(scope='function') |
| 202 |
def stage_user(topology_st, request): |
| 203 |
log.info('Create stage user') |
| 204 |
stage_users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX, |
| 205 |
rdn=f'cn={STAGE_CN},cn={PROVISIONING_CN},cn={SCOPE_IN_CN}') |
| 206 |
if stage_users.exists(STAGE_USER_CN): |
| 207 |
stage_users.get(STAGE_USER_CN).delete() |
| 208 |
|
| 209 |
stage_user = stage_users.create(properties={'cn': STAGE_USER_CN, |
| 210 |
'uid': STAGE_USER_CN, |
| 211 |
'sn': STAGE_USER_CN, |
| 212 |
'uidNumber': '2', |
| 213 |
'gidNumber': '12', |
| 214 |
'homeDirectory': f'/home/{STAGE_USER_CN}'}) |
| 215 |
|
| 216 |
def fin(): |
| 217 |
if stage_user.exists(): |
| 218 |
log.info('Delete stage user') |
| 219 |
stage_user.delete() |
| 220 |
|
| 221 |
request.addfinalizer(fin) |
| 222 |
|
| 223 |
return stage_user |
| 224 |
|
| 225 |
|
| 226 |
@pytest.fixture(scope='function') |
| 227 |
def out_user(topology_st, request): |
| 228 |
log.info('Create out user') |
| 229 |
out_users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX, |
| 230 |
rdn=f'cn={SCOPE_OUT_CN}') |
| 231 |
if out_users.exists(OUT_USER_CN): |
| 232 |
out_users.get(OUT_USER_CN).delete() |
| 233 |
|
| 234 |
out_user = out_users.create(properties={'cn': OUT_USER_CN, |
| 235 |
'uid': OUT_USER_CN, |
| 236 |
'sn': OUT_USER_CN, |
| 237 |
'uidNumber': '3', |
| 238 |
'gidNumber': '13', |
| 239 |
'homeDirectory': f'/home/{OUT_USER_CN}'}) |
| 240 |
|
| 241 |
def fin(): |
| 242 |
if out_user.exists(): |
| 243 |
log.info('Delete out user') |
| 244 |
out_user.delete() |
| 245 |
|
| 246 |
request.addfinalizer(fin) |
| 247 |
|
| 248 |
return out_user |
| 249 |
|
| 250 |
|
| 251 |
def check_memberof(user, group_dn, should_exist=True): |
| 252 |
"""Helper function to check memberOf attribute""" |
| 253 |
memberof_values = user.get_attr_vals_utf8_l('memberof') |
| 254 |
found = group_dn.lower() in memberof_values |
| 255 |
|
| 256 |
if should_exist: |
| 257 |
assert found, ( |
| 258 |
f"Expected user '{user.dn}' to be a member of group '{group_dn}', " |
| 259 |
f"but it was not found in memberOf: {memberof_values}" |
| 260 |
) |
| 261 |
else: |
| 262 |
assert not found, ( |
| 263 |
f"Did not expect user '{user.dn}' to be a member of group '{group_dn}', " |
| 264 |
f"but it was found in memberOf: {memberof_values}" |
| 265 |
) |
| 266 |
|
| 267 |
|
| 268 |
@pytest.fixture(scope='function') |
| 269 |
def config_memberof(request, topology_st): |
| 270 |
memberof = MemberOfPlugin(topology_st.standalone) |
| 271 |
memberof.enable() |
| 272 |
memberof.replace('memberOfEntryScope', SCOPE_IN_DN) |
| 273 |
memberof.replace('memberOfEntryScopeExcludeSubtree', PROVISIONING_DN) |
| 274 |
|
| 275 |
# Configure Referential Integrity plugin |
| 276 |
referint = ReferentialIntegrityPlugin(topology_st.standalone) |
| 277 |
referint.enable() |
| 278 |
referint.replace('nsslapd-pluginentryscope', SCOPE_IN_DN) |
| 279 |
referint.replace('nsslapd-plugincontainerscope', SCOPE_IN_DN) |
| 280 |
referint.replace('nsslapd-pluginExcludeEntryScope', PROVISIONING_DN) |
| 281 |
|
| 282 |
topology_st.standalone.restart() |
| 283 |
|
| 284 |
def fin(): |
| 285 |
memberof.disable() |
| 286 |
referint.disable() |
| 287 |
topology_st.standalone.restart() |
| 288 |
|
| 289 |
request.addfinalizer(fin) |
| 290 |
|
| 291 |
|
| 292 |
@pytest.mark.parametrize( |
| 293 |
"user, group, is_memberof", |
| 294 |
[("active_user", "active_group", True), |
| 295 |
("active_user", "stage_group", False), |
| 296 |
("active_user", "out_group", False), |
| 297 |
("stage_user", "active_group", False), |
| 298 |
("stage_user", "stage_group", False), |
| 299 |
("stage_user", "out_group", False), |
| 300 |
("out_user", "active_group", False), |
| 301 |
("out_user", "stage_group", False), |
| 302 |
("out_user", "out_group", False), |
| 303 |
]) |
| 304 |
def test_memberof_add_user_to_group(topology_st, containers, request, group, user, is_memberof, config_memberof): |
| 305 |
"""Verify memberOf behavior when adding/removing users to groups across scopes |
| 306 |
|
| 307 |
:id: 3f0b0f8a-1d9b-4e4b-8b8e-3a3f3a5b5b11 |
| 308 |
:setup: Standalone instance; MemberOf and Referential Integrity configured; test containers, users, and groups |
| 309 |
:steps: |
| 310 |
1. Resolve parametrized fixtures for user and group |
| 311 |
2. Add the user to the group |
| 312 |
3. Verify the group membership is present |
| 313 |
4. Verify memberOf presence or absence according to scope configuration |
| 314 |
5. Remove the user from the group |
| 315 |
6. Verify the group membership is removed |
| 316 |
7. Verify memberOf was removed |
| 317 |
:expectedresults: |
| 318 |
1. Success |
| 319 |
2. Success |
| 320 |
3. Success |
| 321 |
4. Success |
| 322 |
5. Success |
| 323 |
6. Success |
| 324 |
7. Success |
| 325 |
""" |
| 326 |
|
| 327 |
user = request.getfixturevalue(user) |
| 328 |
group = request.getfixturevalue(group) |
| 329 |
|
| 330 |
# Add user to group, verify that user is member of group and memberof attribute is updated according to the scope |
| 331 |
group.add_member(user.dn) |
| 332 |
assert group.is_member(user.dn) |
| 333 |
check_memberof(user, group.dn, is_memberof) |
| 334 |
|
| 335 |
# Remove user from group, verify that user is not member of group and memberof attribute is updated according to the scope |
| 336 |
group.remove_member(user.dn) |
| 337 |
assert not group.is_member(user.dn) |
| 338 |
check_memberof(user, group.dn, should_exist=False) |
| 339 |
|
| 340 |
|
| 341 |
def test_memberof_modrdn_active_user_in_active_group(topology_st, containers, active_group, active_user, config_memberof): |
| 342 |
"""Renaming active user within active scope preserves membership and memberOf |
| 343 |
|
| 344 |
:id: 7f3c2f3f-6a02-4d7c-a2c3-6d4f7f6a2b10 |
| 345 |
:setup: Standalone instance; MemberOf and Referential Integrity configured; active user and active group exist |
| 346 |
:steps: |
| 347 |
1. Add the active user to the active group |
| 348 |
2. Rename the user RDN within the active scope |
| 349 |
3. Verify the group membership is preserved |
| 350 |
4. Verify memberOf remains present |
| 351 |
5. Rename the user back to the original RDN |
| 352 |
6. Verify the group membership is preserved |
| 353 |
7. Verify memberOf remains present |
| 354 |
8. Remove the user from the group and verify memberOf is removed |
| 355 |
:expectedresults: |
| 356 |
1. Success |
| 357 |
2. Success |
| 358 |
3. Success |
| 359 |
4. Success |
| 360 |
5. Success |
| 361 |
6. Success |
| 362 |
7. Success |
| 363 |
8. Success |
| 364 |
""" |
| 365 |
|
| 366 |
olduid = active_user.get_attr_val_utf8_l('uid') |
| 367 |
|
| 368 |
# Add active user to active group, verify that user is member of group and memberof attribute is filled |
| 369 |
active_group.add_member(active_user.dn) |
| 370 |
assert active_group.is_member(active_user.dn) |
| 371 |
check_memberof(active_user, active_group.dn, should_exist=True) |
| 372 |
|
| 373 |
# Rename active user, verify that user is still member of group and memberof attribute is filled |
| 374 |
olddn = active_user.dn |
| 375 |
active_user.rename(f"uid=x{olduid}") |
| 376 |
assert active_group.is_member(active_user.dn) |
| 377 |
assert not active_group.is_member(olddn) |
| 378 |
check_memberof(active_user, active_group.dn, should_exist=True) |
| 379 |
|
| 380 |
# Rename active user back to original name, verify that user is still member of group and memberof attribute is filled |
| 381 |
olddn = active_user.dn |
| 382 |
active_user.rename(f"uid={olduid}") |
| 383 |
assert active_group.is_member(active_user.dn) |
| 384 |
assert not active_group.is_member(olddn) |
| 385 |
check_memberof(active_user, active_group.dn, should_exist=True) |
| 386 |
|
| 387 |
# Remove active user from active group, verify that user is not member of group and memberof attribute is removed |
| 388 |
active_group.remove_member(active_user.dn) |
| 389 |
assert not active_group.is_member(active_user.dn) |
| 390 |
check_memberof(active_user, active_group.dn, should_exist=False) |
| 391 |
|
| 392 |
|
| 393 |
def test_memberof_modrdn_active_user_to_stage(topology_st, containers, active_group, active_user, config_memberof): |
| 394 |
"""Moving active user to excluded stage subtree cleans membership and memberOf |
| 395 |
|
| 396 |
:id: 8a1a2c3b-5d6e-4f71-9f41-00b8c63d9a07 |
| 397 |
:setup: Standalone instance; MemberOf and Referential Integrity configured; active user and active group exist |
| 398 |
:steps: |
| 399 |
1. Add the active user to the active group and verify memberOf is present |
| 400 |
2. Move the user under the excluded stage subtree |
| 401 |
3. Verify the group membership is removed |
| 402 |
4. Verify memberOf is removed |
| 403 |
5. Move the user back to the active subtree |
| 404 |
6. Verify memberOf is not implicitly restored, and membership is not restored |
| 405 |
:expectedresults: |
| 406 |
1. Success |
| 407 |
2. Success |
| 408 |
3. Success |
| 409 |
4. Success |
| 410 |
5. Success |
| 411 |
6. Success |
| 412 |
""" |
| 413 |
olduid = active_user.get_attr_val_utf8_l('uid') |
| 414 |
|
| 415 |
# Add active user to active group, verify that user is member of group and memberof attribute is filled |
| 416 |
active_group.add_member(active_user.dn) |
| 417 |
assert active_group.is_member(active_user.dn) |
| 418 |
check_memberof(active_user, active_group.dn, should_exist=True) |
| 419 |
|
| 420 |
# Rename active user to stage subtree, v erify that user is not member of group and memberof attribute is removed |
| 421 |
olddn = active_user.dn |
| 422 |
active_user.rename(f"uid={olduid}", newsuperior=STAGE_DN) |
| 423 |
assert not active_group.is_member(active_user.dn) |
| 424 |
assert not active_group.is_member(olddn) |
| 425 |
check_memberof(active_user, active_group.dn, should_exist=False) |
| 426 |
|
| 427 |
# Rename active user back to active subtree, verify that user is not member of group and memberof attribute is not set |
| 428 |
olddn = active_user.dn |
| 429 |
active_user.rename(f"uid={olduid}", newsuperior=ACTIVE_DN) |
| 430 |
assert not active_group.is_member(active_user.dn) |
| 431 |
assert not active_group.is_member(olddn) |
| 432 |
check_memberof(active_user, active_group.dn, should_exist=False) |
| 433 |
|
| 434 |
|
| 435 |
def test_memberof_modrdn_active_user_to_out(topology_st, containers, active_group, active_user, config_memberof): |
| 436 |
"""Moving active user to out of scope subtreecleans membership and memberOf |
| 437 |
|
| 438 |
:id: 2c9b5e4a-4a58-4c19-9b5c-41b9b5a0d0c1 |
| 439 |
:setup: Standalone instance; MemberOf and Referential Integrity configured; active user and active group exist |
| 440 |
:steps: |
| 441 |
1. Add the active user to the active group and verify memberOf is present |
| 442 |
2. Move the user to the out-of-scope subtree |
| 443 |
3. Verify the group membership is removed |
| 444 |
4. Verify memberOf is removed |
| 445 |
5. Move the user back to the active subtree |
| 446 |
6. Verify memberOf is not implicitly restored, and membership is not restored |
| 447 |
:expectedresults: |
| 448 |
1. Success |
| 449 |
2. Success |
| 450 |
3. Success |
| 451 |
4. Success |
| 452 |
5. Success |
| 453 |
6. Success |
| 454 |
""" |
| 455 |
olduid = active_user.get_attr_val_utf8_l('uid') |
| 456 |
|
| 457 |
# Add active user to active group, verify that user is member of group and memberof attribute is filled |
| 458 |
active_group.add_member(active_user.dn) |
| 459 |
assert active_group.is_member(active_user.dn) |
| 460 |
check_memberof(active_user, active_group.dn, should_exist=True) |
| 461 |
|
| 462 |
# Rename active user to out-of-scopesubtree, verify that user is not member of group and memberof attribute is removed |
| 463 |
active_user.rename(f"uid=x{olduid}", newsuperior=SCOPE_OUT_DN) |
| 464 |
assert not active_group.is_member(active_user.dn) |
| 465 |
check_memberof(active_user, active_group.dn, should_exist=False) |
| 466 |
|
| 467 |
# Rename active user back to active subtree, verify that user is not member of group and memberof attribute is not set |
| 468 |
active_user.rename(f"uid={olduid}", newsuperior=ACTIVE_DN) |
| 469 |
assert not active_group.is_member(active_user.dn) |
| 470 |
check_memberof(active_user, active_group.dn, should_exist=False) |
| 471 |
|
| 472 |
|
| 473 |
def test_memberof_modrdn_stage_user_to_active(topology_st, containers, stage_user, active_group, config_memberof): |
| 474 |
"""Move stage user into active scope grants memberOf and preserves membership |
| 475 |
|
| 476 |
:id: d3f5a6c7-9b12-4d34-b5a1-2f3c4d5e6f70 |
| 477 |
:setup: Standalone instance; MemberOf and Referential Integrity configured; stage user and active group exist |
| 478 |
:steps: |
| 479 |
1. Add the stage user to the active group and verify memberOf is not set due to exclusion |
| 480 |
2. Move the user to the active subtree |
| 481 |
3. Verify the group membership is present |
| 482 |
4. Verify memberOf is now present |
| 483 |
5. Move the user back to the stage subtree |
| 484 |
6. Verify the group membership is removed and memberOf is removed |
| 485 |
:expectedresults: |
| 486 |
1. Success |
| 487 |
2. Success |
| 488 |
3. Success |
| 489 |
4. Success |
| 490 |
5. Success |
| 491 |
6. Success |
| 492 |
""" |
| 493 |
olduid = stage_user.get_attr_val_utf8_l('uid') |
| 494 |
|
| 495 |
# Add stage user to active group, verify that user is a member of group but memberof attribute is not set |
| 496 |
active_group.add_member(stage_user.dn) |
| 497 |
assert active_group.is_member(stage_user.dn) |
| 498 |
check_memberof(stage_user, active_group.dn, should_exist=False) |
| 499 |
|
| 500 |
# Rename stage user to active subtree, verify that user is a member of group and memberof attribute is set |
| 501 |
stage_user.rename(f"uid={olduid}", newsuperior=ACTIVE_DN) |
| 502 |
assert active_group.is_member(stage_user.dn) |
| 503 |
check_memberof(stage_user, active_group.dn, should_exist=True) |
| 504 |
|
| 505 |
# Rename stage user back to stage subtree, verify that user is not member of group and memberof attribute is not set |
| 506 |
stage_user.rename(f"uid={olduid}", newsuperior=STAGE_DN) |
| 507 |
assert not active_group.is_member(stage_user.dn) |
| 508 |
check_memberof(stage_user, active_group.dn, should_exist=False) |
| 509 |
|
| 510 |
|
| 511 |
def test_memberof_modrdn_stage_user_to_stage(topology_st, containers, stage_user, active_group, config_memberof): |
| 512 |
"""Renaming stage user within excluded subtree does not set memberOf and cleans membership |
| 513 |
|
| 514 |
:id: 0c1b2a3d-4e5f-6a7b-8c9d-0e1f2a3b4c5d |
| 515 |
:setup: Standalone instance; MemberOf and Referential Integrity configured; stage user and active group exist |
| 516 |
:steps: |
| 517 |
1. Add the stage user to the active group and verify memberOf is not set |
| 518 |
2. Rename the user within the stage subtree |
| 519 |
3. Verify the user is not a member of the active group and memberOf remains unset |
| 520 |
4. Rename the user back to the original RDN |
| 521 |
5. Verify the user remains a member according to scope rules and memberOf remains unset |
| 522 |
:expectedresults: |
| 523 |
1. Success |
| 524 |
2. Success |
| 525 |
3. Success |
| 526 |
4. Success |
| 527 |
5. Success |
| 528 |
""" |
| 529 |
olduid = stage_user.get_attr_val_utf8_l('uid') |
| 530 |
olddn = stage_user.dn |
| 531 |
|
| 532 |
# Add stage user to active group, verify that user is a member of group but memberof attribute is not set |
| 533 |
active_group.add_member(stage_user.dn) |
| 534 |
assert active_group.is_member(stage_user.dn) |
| 535 |
check_memberof(stage_user, active_group.dn, should_exist=False) |
| 536 |
|
| 537 |
# Rename stage user, verify that user is not member of group and memberof attribute is not set |
| 538 |
stage_user.rename(f"uid=x{olduid}") |
| 539 |
assert not active_group.is_member(stage_user.dn) |
| 540 |
# Original user DN is still a member of the group due to the referential integrity plugin configuration for this test |
| 541 |
assert active_group.is_member(olddn) |
| 542 |
check_memberof(stage_user, active_group.dn, should_exist=False) |
| 543 |
|
| 544 |
# Rename stage user back to original name, verify that user is member of group and memberof attribute is not set |
| 545 |
stage_user.rename(f"uid={olduid}") |
| 546 |
assert active_group.is_member(stage_user.dn) |
| 547 |
check_memberof(stage_user, active_group.dn, should_exist=False) |
| 548 |
|
| 549 |
|
| 550 |
def test_memberof_indirect_active_group(topology_st, containers, active_group, indirect_active_group, active_user, config_memberof): |
| 551 |
"""Verify indirect group membership updates memberOf across nested groups |
| 552 |
|
| 553 |
:id: a1b2c3d4-e5f6-47a8-9b0c-d1e2f3a4b5c6 |
| 554 |
:setup: Standalone instance; MemberOf and Referential Integrity configured; active and indirect groups exist |
| 555 |
:steps: |
| 556 |
1. Add the active group as a member of the indirect active group |
| 557 |
2. Verify the active group has memberOf pointing to the indirect group |
| 558 |
3. Add an active user to the active group |
| 559 |
4. Verify the user has memberOf for both the active and indirect groups |
| 560 |
5. Remove the active group from the indirect group |
| 561 |
6. Verify the user's memberOf for the indirect group is removed, and active group memberOf remains |
| 562 |
7. Remove the user from the active group and verify memberOf cleanup |
| 563 |
:expectedresults: |
| 564 |
1. Success |
| 565 |
2. Success |
| 566 |
3. Success |
| 567 |
4. Success |
| 568 |
5. Success |
| 569 |
6. Success |
| 570 |
7. Success |
| 571 |
""" |
| 572 |
# Add active group to indirect active group |
| 573 |
# Verify that active group is member of indirect active group and memberof attribute is set |
| 574 |
indirect_active_group.add_member(active_group.dn) |
| 575 |
assert indirect_active_group.is_member(active_group.dn) |
| 576 |
check_memberof(active_group, indirect_active_group.dn, should_exist=True) |
| 577 |
|
| 578 |
# Add active user to active group, verify that user is member of group and memberof attribute is filled for both groups |
| 579 |
active_group.add_member(active_user.dn) |
| 580 |
assert active_group.is_member(active_user.dn) |
| 581 |
check_memberof(active_user, active_group.dn, should_exist=True) |
| 582 |
check_memberof(active_user, indirect_active_group.dn, should_exist=True) |
| 583 |
|
| 584 |
# Remove active group from indirect active group |
| 585 |
# Verify that active group is not member of indirect active group and memberof attribute is removed between groups |
| 586 |
# User still has active group memberof value |
| 587 |
indirect_active_group.remove_member(active_group.dn) |
| 588 |
assert not indirect_active_group.is_member(active_group.dn) |
| 589 |
check_memberof(active_group, indirect_active_group.dn, should_exist=False) |
| 590 |
assert not indirect_active_group.is_member(active_user.dn) |
| 591 |
check_memberof(active_user, indirect_active_group.dn, should_exist=False) |
| 592 |
assert active_group.is_member(active_user.dn) |
| 593 |
check_memberof(active_user, active_group.dn, should_exist=True) |
| 594 |
|
| 595 |
# Remove active user from active group |
| 596 |
# Verify that user is not member of group and memberof attribute is removed |
| 597 |
active_group.remove_member(active_user.dn) |
| 598 |
assert not active_group.is_member(active_user.dn) |
| 599 |
check_memberof(active_user, active_group.dn, should_exist=False) |
| 600 |
|
| 601 |
|
| 602 |
def test_memberof_indirect_active_group_active_user_to_stage(topology_st, containers, active_group, indirect_active_group, active_user, config_memberof): |
| 603 |
"""Move active user to stage subtree cleans direct and indirect memberOf |
| 604 |
|
| 605 |
:id: b2c3d4e5-f6a7-48b9-801c-d2e3f4a5b6c7 |
| 606 |
:setup: Standalone instance; MemberOf and Referential Integrity configured; active user, active and indirect groups exist |
| 607 |
:steps: |
| 608 |
1. Add the active group to the indirect active group |
| 609 |
2. Add the active user to the active group and verify memberOf for both groups |
| 610 |
3. Move the active user to the stage subtree |
| 611 |
4. Verify direct and indirect memberOf are removed and group membership is cleaned |
| 612 |
5. Move the user back to the active subtree and verify memberOf is not implicitly restored |
| 613 |
:expectedresults: |
| 614 |
1. Success |
| 615 |
2. Success |
| 616 |
3. Success |
| 617 |
4. Success |
| 618 |
5. Success |
| 619 |
""" |
| 620 |
olduid = active_user.get_attr_val_utf8_l('uid') |
| 621 |
|
| 622 |
# Add active group to indirect active group |
| 623 |
# Verify that active group is member of indirect active group and memberof attribute is set |
| 624 |
indirect_active_group.add_member(active_group.dn) |
| 625 |
assert indirect_active_group.is_member(active_group.dn) |
| 626 |
check_memberof(active_group, indirect_active_group.dn, should_exist=True) |
| 627 |
|
| 628 |
# Add active user to active group |
| 629 |
# Verify that user is member of group and memberof attribute is filled for both groups |
| 630 |
active_group.add_member(active_user.dn) |
| 631 |
assert active_group.is_member(active_user.dn) |
| 632 |
check_memberof(active_user, active_group.dn, should_exist=True) |
| 633 |
check_memberof(active_user, indirect_active_group.dn, should_exist=True) |
| 634 |
|
| 635 |
# Rename active user to stage subtree |
| 636 |
# Verify that user is not member of group and memberof attribute is removed |
| 637 |
active_user.rename(f"uid={olduid}", newsuperior=STAGE_DN) |
| 638 |
assert not active_group.is_member(active_user.dn) |
| 639 |
check_memberof(active_user, active_group.dn, should_exist=False) |
| 640 |
check_memberof(active_user, indirect_active_group.dn, should_exist=False) |
| 641 |
|
| 642 |
# Rename active user back to active subtree |
| 643 |
# Verify that user is not member of group and memberof attribute is not set |
| 644 |
active_user.rename(f"uid={olduid}", newsuperior=ACTIVE_DN) |
| 645 |
assert not active_group.is_member(active_user.dn) |
| 646 |
check_memberof(active_user, active_group.dn, should_exist=False) |
| 647 |
check_memberof(active_user, indirect_active_group.dn, should_exist=False) |
| 648 |
|
| 649 |
|
| 650 |
def test_memberof_indirect_active_group_active_user_to_out(topology_st, containers, active_group, indirect_active_group, active_user, config_memberof): |
| 651 |
"""Moving active user out of scope cleans direct and indirect memberOf |
| 652 |
|
| 653 |
:id: c3d4e5f6-a7b8-49c0-912d-e3f4a5b6c7d8 |
| 654 |
:setup: Standalone instance; MemberOf and Referential Integrity configured; active user, active and indirect groups exist |
| 655 |
:steps: |
| 656 |
1. Add the active group to the indirect active group |
| 657 |
2. Add the active user to the active group and verify memberOf for both groups |
| 658 |
3. Move the active user to the out-of-scope subtree |
| 659 |
4. Verify direct and indirect memberOf are removed and group membership is cleaned |
| 660 |
5. Move the user back to the active subtree and verify memberOf is not implicitly restored |
| 661 |
:expectedresults: |
| 662 |
1. Success |
| 663 |
2. Success |
| 664 |
3. Success |
| 665 |
4. Success |
| 666 |
5. Success |
| 667 |
""" |
| 668 |
olduid = active_user.get_attr_val_utf8_l('uid') |
| 669 |
|
| 670 |
# Add active group to indirect active group |
| 671 |
# Verify that active group is member of indirect active group and memberof attribute is set |
| 672 |
indirect_active_group.add_member(active_group.dn) |
| 673 |
assert indirect_active_group.is_member(active_group.dn) |
| 674 |
check_memberof(active_group, indirect_active_group.dn, should_exist=True) |
| 675 |
|
| 676 |
# Add active user to active group |
| 677 |
# Verify that user is member of group and memberof attribute is filled for both groups |
| 678 |
active_group.add_member(active_user.dn) |
| 679 |
assert active_group.is_member(active_user.dn) |
| 680 |
check_memberof(active_user, active_group.dn, should_exist=True) |
| 681 |
check_memberof(active_user, indirect_active_group.dn, should_exist=True) |
| 682 |
|
| 683 |
# Rename active user to out-of-scope subtree |
| 684 |
# Verify that user is not member of group and memberof attribute is removed |
| 685 |
active_user.rename(f"uid={olduid}", newsuperior=SCOPE_OUT_DN) |
| 686 |
assert not active_group.is_member(active_user.dn) |
| 687 |
check_memberof(active_user, active_group.dn, should_exist=False) |
| 688 |
check_memberof(active_user, indirect_active_group.dn, should_exist=False) |
| 689 |
|
| 690 |
# Rename active user back to active subtree |
| 691 |
# Verify that user is not member of group and memberof attribute is not set |
| 692 |
active_user.rename(f"uid={olduid}", newsuperior=ACTIVE_DN) |
| 693 |
assert not active_group.is_member(active_user.dn) |
| 694 |
check_memberof(active_user, active_group.dn, should_exist=False) |
| 695 |
check_memberof(active_user, indirect_active_group.dn, should_exist=False) |
| 696 |
|
| 697 |
|
| 698 |
def test_memberof_indirect_active_group_stage_user_to_active(topology_st, containers, active_group, indirect_active_group, stage_user, config_memberof): |
| 699 |
"""Moving stage user to active subtree grants direct and indirect memberOf |
| 700 |
|
| 701 |
:id: d4e5f6a7-b8c9-4ad1-923e-f4a5b6c7d8e9 |
| 702 |
:setup: Standalone instance; MemberOf and Referential Integrity configured; stage user, active and indirect groups exist |
| 703 |
:steps: |
| 704 |
1. Add the active group to the indirect active group |
| 705 |
2. Add the stage user to the active group and verify memberOf is not set |
| 706 |
3. Move the stage user to the active subtree |
| 707 |
4. Verify the user has memberOf for both the active and indirect groups |
| 708 |
5. Move the user back to the stage subtree, verify memberOf is removed from both groups, user is not a member of active group |
| 709 |
:expectedresults: |
| 710 |
1. Success |
| 711 |
2. Success |
| 712 |
3. Success |
| 713 |
4. Success |
| 714 |
5. Success |
| 715 |
""" |
| 716 |
olduid = stage_user.get_attr_val_utf8_l('uid') |
| 717 |
|
| 718 |
# Add active group to indirect active group |
| 719 |
# Verify that active group is member of indirect active group and memberof attribute is set |
| 720 |
indirect_active_group.add_member(active_group.dn) |
| 721 |
assert indirect_active_group.is_member(active_group.dn) |
| 722 |
check_memberof(active_group, indirect_active_group.dn, should_exist=True) |
| 723 |
|
| 724 |
# Add stage user to active group |
| 725 |
# Verify that user is a member of group but memberof attribute is not set |
| 726 |
active_group.add_member(stage_user.dn) |
| 727 |
assert active_group.is_member(stage_user.dn) |
| 728 |
assert not indirect_active_group.is_member(stage_user.dn) |
| 729 |
check_memberof(stage_user, active_group.dn, should_exist=False) |
| 730 |
check_memberof(stage_user, indirect_active_group.dn, should_exist=False) |
| 731 |
|
| 732 |
# Rename stage user to active subtree |
| 733 |
# Verify that user is a member of group and memberof attribute is set |
| 734 |
stage_user.rename(f"uid={olduid}", newsuperior=ACTIVE_DN) |
| 735 |
assert active_group.is_member(stage_user.dn) |
| 736 |
check_memberof(stage_user, active_group.dn, should_exist=True) |
| 737 |
check_memberof(stage_user, indirect_active_group.dn, should_exist=True) |
| 738 |
|
| 739 |
# Rename stage user back to stage subtree |
| 740 |
# Verify that user is not member of group and memberof attribute is not set |
| 741 |
stage_user.rename(f"uid={olduid}", newsuperior=STAGE_DN) |
| 742 |
assert not active_group.is_member(stage_user.dn) |
| 743 |
assert not indirect_active_group.is_member(stage_user.dn) |
| 744 |
check_memberof(stage_user, active_group.dn, should_exist=False) |
| 745 |
check_memberof(stage_user, indirect_active_group.dn, should_exist=False) |