| 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 time |
| 10 |
import pytest |
| 11 |
import logging |
| 12 |
import os |
| 13 |
import ldap |
| 14 |
import json |
| 15 |
|
| 16 |
from lib389 import DEFAULT_SUFFIX |
| 17 |
from lib389._constants import DN_DM, PASSWORD |
| 18 |
from lib389.cli_idm.user import list, get, get_dn, create, delete, modify, rename |
| 19 |
from test389.topologies import topology_st |
| 20 |
from lib389.cli_base import FakeArgs |
| 21 |
from lib389.utils import ds_is_older, ensure_str, is_a_dn |
| 22 |
from lib389.idm.user import nsUserAccounts, nsUserAccount |
| 23 |
from . import check_value_in_log_and_reset |
| 24 |
|
| 25 |
pytestmark = pytest.mark.tier0 |
| 26 |
|
| 27 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 28 |
log = logging.getLogger(__name__) |
| 29 |
|
| 30 |
|
| 31 |
def create_user(topo, user_type): |
| 32 |
"""Create one entry under ou=people using nsUserAccounts + update_objectclasses.""" |
| 33 |
args = FakeArgs() |
| 34 |
args.user_type = user_type |
| 35 |
args.json = False |
| 36 |
|
| 37 |
if user_type == 'posix': |
| 38 |
args.uid = 'posix_user' |
| 39 |
args.cn = 'posix_user' |
| 40 |
args.displayName = 'posix_user' |
| 41 |
args.uidNumber = '6100' |
| 42 |
args.gidNumber = '7100' |
| 43 |
args.homeDirectory = '/home/posix_user' |
| 44 |
rdn = 'posix_user' |
| 45 |
elif user_type == 'traditional': |
| 46 |
#args.uid = 'traditional_user' |
| 47 |
args.cn = 'traditional_user' |
| 48 |
args.sn = 'Traditional' |
| 49 |
args.selector = "cn" |
| 50 |
rdn = 'traditional_user' |
| 51 |
elif user_type == 'basic': |
| 52 |
args.uid = 'basic_user' |
| 53 |
args.cn = 'basic_user' |
| 54 |
args.displayName = 'basic_user' |
| 55 |
rdn = 'basic_user' |
| 56 |
elif user_type == 'service': |
| 57 |
args.cn = 'service_user' |
| 58 |
args.description = 'service_user' |
| 59 |
args.selector = "cn" |
| 60 |
rdn = 'service_user' |
| 61 |
else: |
| 62 |
raise ValueError('Invalid user type: %s' % user_type) |
| 63 |
|
| 64 |
create(topo.standalone, DEFAULT_SUFFIX, topo.logcap.log, args) |
| 65 |
return rdn |
| 66 |
|
| 67 |
@pytest.fixture(scope="function") |
| 68 |
def create_test_user(topology_st, request): |
| 69 |
user_name = 'test_user_1000' |
| 70 |
users = nsUserAccounts(topology_st.standalone, DEFAULT_SUFFIX) |
| 71 |
|
| 72 |
log.info('Create test user') |
| 73 |
if users.exists(user_name): |
| 74 |
test_user = users.get(user_name) |
| 75 |
test_user.delete() |
| 76 |
else: |
| 77 |
test_user = users.create_test_user() |
| 78 |
|
| 79 |
def fin(): |
| 80 |
log.info('Delete test user') |
| 81 |
if test_user.exists(): |
| 82 |
test_user.delete() |
| 83 |
|
| 84 |
request.addfinalizer(fin) |
| 85 |
|
| 86 |
|
| 87 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 88 |
def test_dsidm_user_list(topology_st, create_test_user): |
| 89 |
""" Test dsidm user list option |
| 90 |
|
| 91 |
:id: a7400ac2-b629-4507-bc05-c6402a5b437b |
| 92 |
:setup: Standalone instance |
| 93 |
:steps: |
| 94 |
1. Run dsidm user list option without json |
| 95 |
2. Check the output content is correct |
| 96 |
3. Run dsidm user list option with json |
| 97 |
4. Check the json content is correct |
| 98 |
5. Delete the user |
| 99 |
6. Check the user is not in the list with json |
| 100 |
7. Check the user is not in the list without json |
| 101 |
:expectedresults: |
| 102 |
1. Success |
| 103 |
2. Success |
| 104 |
3. Success |
| 105 |
4. Success |
| 106 |
5. Success |
| 107 |
6. Success |
| 108 |
7. Success |
| 109 |
""" |
| 110 |
|
| 111 |
standalone = topology_st.standalone |
| 112 |
args = FakeArgs() |
| 113 |
args.json = False |
| 114 |
args.full_dn = False |
| 115 |
args.user_type = 'posix' |
| 116 |
user_value = 'test_user_1000' |
| 117 |
json_list = ['type', |
| 118 |
'list', |
| 119 |
'items'] |
| 120 |
|
| 121 |
|
| 122 |
log.info('Empty the log file to prevent false data to check about user') |
| 123 |
topology_st.logcap.flush() |
| 124 |
|
| 125 |
log.info('Test dsidm user list without json') |
| 126 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 127 |
check_value_in_log_and_reset(topology_st, check_value=user_value) |
| 128 |
|
| 129 |
log.info('Test dsidm user list with json') |
| 130 |
args.json = True |
| 131 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 132 |
check_value_in_log_and_reset(topology_st, content_list=json_list, check_value=user_value) |
| 133 |
|
| 134 |
log.info('Test full_dn option with list') |
| 135 |
args.full_dn = True |
| 136 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 137 |
result = topology_st.logcap.get_raw_outputs() |
| 138 |
json_result = json.loads(result[0]) |
| 139 |
assert is_a_dn(json_result['items'][0]) |
| 140 |
args.full_dn = False |
| 141 |
topology_st.logcap.flush() |
| 142 |
|
| 143 |
log.info('Delete the user') |
| 144 |
users = nsUserAccounts(topology_st.standalone, DEFAULT_SUFFIX) |
| 145 |
testuser = users.get(user_value) |
| 146 |
testuser.delete() |
| 147 |
|
| 148 |
log.info('Test empty dsidm user list with json') |
| 149 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 150 |
check_value_in_log_and_reset(topology_st, content_list=json_list, check_value_not=user_value) |
| 151 |
|
| 152 |
log.info('Test empty dsidm user list without json') |
| 153 |
args.json = False |
| 154 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 155 |
check_value_in_log_and_reset(topology_st, check_value_not=user_value) |
| 156 |
|
| 157 |
|
| 158 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 159 |
def test_dsidm_user_get_rdn(topology_st, create_test_user): |
| 160 |
""" Test dsidm user get option |
| 161 |
|
| 162 |
:id: 8c7247cd-7588-45d3-817c-ac5a9f135b32 |
| 163 |
:setup: Standalone instance |
| 164 |
:steps: |
| 165 |
1. Run dsidm get option for created user with json |
| 166 |
2. Check the output content is correct |
| 167 |
3. Run dsidm get option for created user without json |
| 168 |
4. Check the json content is correct |
| 169 |
:expectedresults: |
| 170 |
1. Success |
| 171 |
2. Success |
| 172 |
3. Success |
| 173 |
4. Success |
| 174 |
""" |
| 175 |
|
| 176 |
standalone = topology_st.standalone |
| 177 |
users = nsUserAccounts(topology_st.standalone, DEFAULT_SUFFIX) |
| 178 |
testuser = users.get('test_user_1000') |
| 179 |
|
| 180 |
user_content = ['dn: {}'.format(testuser.dn), |
| 181 |
'cn: {}'.format(testuser.rdn), |
| 182 |
'displayName: {}'.format(testuser.rdn), |
| 183 |
'gidNumber: 2000', |
| 184 |
'homeDirectory: /home/{}'.format(testuser.rdn), |
| 185 |
'objectClass: top', |
| 186 |
'objectClass: nsPerson', |
| 187 |
'objectClass: nsAccount', |
| 188 |
'objectClass: nsOrgPerson', |
| 189 |
'objectClass: posixAccount', |
| 190 |
'uid: {}'.format(testuser.rdn), |
| 191 |
'uidNumber: 1000'] |
| 192 |
|
| 193 |
json_content = ['attrs', |
| 194 |
'objectclass', |
| 195 |
'top', |
| 196 |
'nsPerson', |
| 197 |
'nsAccount', |
| 198 |
'nsOrgPerson', |
| 199 |
'posixAccount', |
| 200 |
'uid', |
| 201 |
testuser.rdn, |
| 202 |
'cn', |
| 203 |
'displayname', |
| 204 |
'uidnumber', |
| 205 |
'gidnumber', |
| 206 |
'2000', |
| 207 |
'homedirectory', |
| 208 |
'/home/{}'.format(testuser.rdn), |
| 209 |
'creatorsname', |
| 210 |
'cn=directory manager', |
| 211 |
'modifiersname', |
| 212 |
'createtimestamp', |
| 213 |
'modifytimestamp', |
| 214 |
'nsuniqueid', |
| 215 |
'parentid', |
| 216 |
'entryid', |
| 217 |
'entrydn', |
| 218 |
testuser.dn] |
| 219 |
|
| 220 |
args = FakeArgs() |
| 221 |
args.json = False |
| 222 |
args.user_type = 'posix' |
| 223 |
args.selector = 'test_user_1000' |
| 224 |
|
| 225 |
log.info('Empty the log file to prevent false data to check about user') |
| 226 |
topology_st.logcap.flush() |
| 227 |
|
| 228 |
log.info('Test dsidm user get without json') |
| 229 |
get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 230 |
check_value_in_log_and_reset(topology_st, content_list=user_content) |
| 231 |
|
| 232 |
log.info('Test dsidm user get with json') |
| 233 |
args.json = True |
| 234 |
get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 235 |
check_value_in_log_and_reset(topology_st, content_list=json_content) |
| 236 |
|
| 237 |
|
| 238 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 239 |
def test_dsidm_user_get_dn(topology_st, create_test_user): |
| 240 |
""" Test dsidm user get_dn option |
| 241 |
|
| 242 |
:id: 787bf278-87c3-402e-936e-6161799d098d |
| 243 |
:setup: Standalone instance |
| 244 |
:steps: |
| 245 |
1. Run dsidm user get_dn for created user without json |
| 246 |
2. Check the output content is correct |
| 247 |
3. Run dsidm user get_dn for created user with json |
| 248 |
4. Check the output content os correct |
| 249 |
:expectedresults: |
| 250 |
1. Success |
| 251 |
2. Success |
| 252 |
3. Success |
| 253 |
4. Success |
| 254 |
""" |
| 255 |
|
| 256 |
standalone = topology_st.standalone |
| 257 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 258 |
user_name = 'test_user_1000' |
| 259 |
test_user = users.get(user_name) |
| 260 |
|
| 261 |
args = FakeArgs() |
| 262 |
args.json = False |
| 263 |
args.dn = test_user.dn |
| 264 |
args.user_type = 'posix' |
| 265 |
|
| 266 |
log.info('Empty the log file to prevent false data to check about user') |
| 267 |
topology_st.logcap.flush() |
| 268 |
|
| 269 |
log.info('Test dsidm user get_dn without json') |
| 270 |
get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 271 |
check_value_in_log_and_reset(topology_st, content_list=user_name) |
| 272 |
|
| 273 |
log.info('Test dsidm user get_dn with json') |
| 274 |
args.json = True |
| 275 |
get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 276 |
check_value_in_log_and_reset(topology_st, content_list=user_name) |
| 277 |
|
| 278 |
|
| 279 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 280 |
def test_dsidm_user_create(topology_st): |
| 281 |
""" Test dsidm user create option |
| 282 |
|
| 283 |
:id: 862f5875-11fd-4e8e-92c1-397010386eb8 |
| 284 |
:setup: Standalone instance |
| 285 |
:steps: |
| 286 |
1. Run dsidm user create |
| 287 |
2. Check that a message is provided on creation |
| 288 |
3. Check that created user exists |
| 289 |
:expectedresults: |
| 290 |
1. Success |
| 291 |
2. Success |
| 292 |
3. Success |
| 293 |
""" |
| 294 |
|
| 295 |
standalone = topology_st.standalone |
| 296 |
user_name = 'new_user' |
| 297 |
output = 'Successfully created {}'.format(user_name) |
| 298 |
|
| 299 |
args = FakeArgs() |
| 300 |
args.json = False |
| 301 |
args.uid = user_name |
| 302 |
args.cn = user_name |
| 303 |
args.displayName = user_name |
| 304 |
args.uidNumber = '1030' |
| 305 |
args.gidNumber = '2030' |
| 306 |
args.homeDirectory = '/home/{}'.format(user_name) |
| 307 |
args.user_type = 'posix' |
| 308 |
|
| 309 |
log.info('Test dsidm user create') |
| 310 |
create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 311 |
check_value_in_log_and_reset(topology_st, check_value=output) |
| 312 |
|
| 313 |
log.info('Check that user is present') |
| 314 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 315 |
new_user = users.get(user_name) |
| 316 |
assert new_user.exists() |
| 317 |
|
| 318 |
log.info('Clean up for next test') |
| 319 |
new_user.delete() |
| 320 |
|
| 321 |
|
| 322 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 323 |
def test_dsidm_user_delete(topology_st, create_test_user): |
| 324 |
""" Test dsidm user delete option |
| 325 |
|
| 326 |
:id: 3704dc3a-9787-4f74-aaa8-45f38e4a6a52 |
| 327 |
:setup: Standalone instance |
| 328 |
:steps: |
| 329 |
1. Run dsidm user delete on created user |
| 330 |
2. Check that a message is provided on deletion |
| 331 |
3. Check that user does not exist |
| 332 |
:expectedresults: |
| 333 |
1. Success |
| 334 |
2. Success |
| 335 |
3. Success |
| 336 |
""" |
| 337 |
|
| 338 |
standalone = topology_st.standalone |
| 339 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 340 |
test_user = users.get('test_user_1000') |
| 341 |
output = 'Successfully deleted {}'.format(test_user.dn) |
| 342 |
|
| 343 |
args = FakeArgs() |
| 344 |
args.dn = test_user.dn |
| 345 |
args.user_type = 'posix' |
| 346 |
|
| 347 |
log.info('Test dsidm user delete') |
| 348 |
delete(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False) |
| 349 |
check_value_in_log_and_reset(topology_st, check_value=output) |
| 350 |
|
| 351 |
log.info('Check that user does not exist') |
| 352 |
assert not test_user.exists() |
| 353 |
|
| 354 |
|
| 355 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 356 |
def test_dsidm_user_modify(topology_st, create_test_user): |
| 357 |
""" Test dsidm user modify add, replace, delete option |
| 358 |
|
| 359 |
:id: 7a27be19-1a63-44d0-b11b-f877e06e1a9b |
| 360 |
:setup: Standalone instance |
| 361 |
:steps: |
| 362 |
1. Run dsidm user modify replace cn value |
| 363 |
2. Run dsidm user modify add telephoneNumber attribute to user |
| 364 |
3. Run dsidm user modify delete for telephoneNumber attribute |
| 365 |
:expectedresults: |
| 366 |
1. cn value is replaced with new name |
| 367 |
2. telephoneNumber attribute is present |
| 368 |
3. telephoneNumber attribute is deleted |
| 369 |
""" |
| 370 |
|
| 371 |
standalone = topology_st.standalone |
| 372 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 373 |
test_user = users.get('test_user_1000') |
| 374 |
output = 'Successfully modified {}'.format(test_user.dn) |
| 375 |
|
| 376 |
args = FakeArgs() |
| 377 |
args.selector = 'test_user_1000' |
| 378 |
args.changes = ['replace:cn:test'] |
| 379 |
args.user_type = 'posix' |
| 380 |
|
| 381 |
log.info('Test dsidm user modify replace') |
| 382 |
modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False) |
| 383 |
check_value_in_log_and_reset(topology_st, check_value=output) |
| 384 |
|
| 385 |
log.info('Test dsidm user modify add') |
| 386 |
args.changes = ['add:telephoneNumber:1234567890'] |
| 387 |
modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False) |
| 388 |
check_value_in_log_and_reset(topology_st, check_value=output) |
| 389 |
assert test_user.present('telephoneNumber', '1234567890') |
| 390 |
|
| 391 |
log.info('Test dsidm user modify delete') |
| 392 |
args.changes = ['delete:telephoneNumber:1234567890'] |
| 393 |
modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False) |
| 394 |
check_value_in_log_and_reset(topology_st, check_value=output) |
| 395 |
assert not test_user.present('telephoneNumber', '1234567890') |
| 396 |
|
| 397 |
|
| 398 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 399 |
def test_dsidm_user_rename_keep_old_rdn(topology_st, create_test_user): |
| 400 |
""" Test dsidm user rename option with keep-old-rdn |
| 401 |
|
| 402 |
:id: 3fd0827c-ab5e-4586-9493-55bc5076a887 |
| 403 |
:setup: Standalone instance |
| 404 |
:steps: |
| 405 |
1. Run dsidm user rename option with keep-old-rdn |
| 406 |
2. Check the user does have another uid attribute with the old rdn |
| 407 |
3. Check the old user is deleted |
| 408 |
:expectedresults: |
| 409 |
1. Success |
| 410 |
2. Success |
| 411 |
3. Success |
| 412 |
""" |
| 413 |
|
| 414 |
standalone = topology_st.standalone |
| 415 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 416 |
test_user = users.get('test_user_1000') |
| 417 |
|
| 418 |
args = FakeArgs() |
| 419 |
args.selector = test_user.rdn |
| 420 |
args.new_name = 'my_user' |
| 421 |
args.keep_old_rdn = True |
| 422 |
args.user_type = 'posix' |
| 423 |
|
| 424 |
log.info('Test dsidm user rename') |
| 425 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 426 |
my_user = users.get(args.new_name) |
| 427 |
output = 'Successfully renamed to {}'.format(my_user.dn) |
| 428 |
check_value_in_log_and_reset(topology_st, check_value=output) |
| 429 |
|
| 430 |
log.info('my_user should have uid attribute with the old rdn') |
| 431 |
assert my_user.present('uid', 'test_user_1000') |
| 432 |
assert my_user.get_attr_val_utf8('cn') == 'test_user_1000' |
| 433 |
assert my_user.get_attr_val_utf8('displayName') == 'test_user_1000' |
| 434 |
|
| 435 |
log.info('Old user dn should not exist') |
| 436 |
assert not test_user.exists() |
| 437 |
|
| 438 |
log.info('Clean up') |
| 439 |
my_user.delete() |
| 440 |
|
| 441 |
|
| 442 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 443 |
def test_dsidm_user_rename(topology_st, create_test_user): |
| 444 |
""" Test dsidm user rename option |
| 445 |
|
| 446 |
:id: fa569966-3954-465f-92b0-331a3a088b1b |
| 447 |
:setup: Standalone instance |
| 448 |
:steps: |
| 449 |
1. Run dsidm user rename option on created user |
| 450 |
2. Check the user does not have another uid attribute with the old rdn |
| 451 |
3. Check the old user is deleted |
| 452 |
:expectedresults: |
| 453 |
1. Success |
| 454 |
2. Success |
| 455 |
3. Success |
| 456 |
""" |
| 457 |
|
| 458 |
standalone = topology_st.standalone |
| 459 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 460 |
test_user = users.get('test_user_1000') |
| 461 |
|
| 462 |
args = FakeArgs() |
| 463 |
args.selector = test_user.rdn |
| 464 |
args.new_name = 'my_user' |
| 465 |
args.keep_old_rdn = False |
| 466 |
args.user_type = 'posix' |
| 467 |
|
| 468 |
log.info('Test dsidm user rename') |
| 469 |
args.new_name = 'my_user' |
| 470 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 471 |
my_user = users.get(args.new_name) |
| 472 |
output = 'Successfully renamed to {}'.format(my_user.dn) |
| 473 |
check_value_in_log_and_reset(topology_st, check_value=output) |
| 474 |
|
| 475 |
log.info('New user should not have uid attribute with the old rdn') |
| 476 |
assert not my_user.present('uid', 'test_user_1000') |
| 477 |
assert my_user.get_attr_val_utf8('cn') == 'test_user_1000' |
| 478 |
assert my_user.get_attr_val_utf8('displayName') == 'test_user_1000' |
| 479 |
|
| 480 |
log.info('Old user dn should not exist.') |
| 481 |
assert not test_user.exists() |
| 482 |
|
| 483 |
log.info('Clean up') |
| 484 |
my_user.delete() |
| 485 |
|
| 486 |
|
| 487 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 488 |
def test_dsidm_user_rename_nonexistent(topology_st): |
| 489 |
"""Test dsidm user rename with nonexistent user |
| 490 |
|
| 491 |
:id: 284f9cf7-53d4-4f5e-9d2e-ae38081cb4e0 |
| 492 |
:setup: Standalone instance |
| 493 |
:steps: |
| 494 |
1. Create a user |
| 495 |
2. Rename the user from original name to new name |
| 496 |
3. Try to rename the original name to new name again (should fail) |
| 497 |
4. Verify the renamed user exists |
| 498 |
:expectedresults: |
| 499 |
1. Success |
| 500 |
2. Success |
| 501 |
3. Failure - should report that the original user doesn't exist |
| 502 |
4. Success |
| 503 |
""" |
| 504 |
|
| 505 |
standalone = topology_st.standalone |
| 506 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 507 |
original_name = 'original_user' |
| 508 |
new_name = 'renamed_user' |
| 509 |
renamed_user = None |
| 510 |
|
| 511 |
try: |
| 512 |
log.info('Create a user') |
| 513 |
args = FakeArgs() |
| 514 |
args.uid = original_name |
| 515 |
args.cn = original_name |
| 516 |
args.displayName = original_name |
| 517 |
args.uidNumber = '1050' |
| 518 |
args.gidNumber = '2050' |
| 519 |
args.homeDirectory = f'/home/{original_name}' |
| 520 |
args.user_type = 'posix' |
| 521 |
create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 522 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully created {original_name}') |
| 523 |
|
| 524 |
log.info('Rename the user') |
| 525 |
args = FakeArgs() |
| 526 |
args.selector = original_name |
| 527 |
args.new_name = new_name |
| 528 |
args.keep_old_rdn = False |
| 529 |
args.user_type = 'posix' |
| 530 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 531 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully renamed to') |
| 532 |
|
| 533 |
log.info('Try to rename the nonexistent user') |
| 534 |
try: |
| 535 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 536 |
assert False, "The rename operation should have failed for a nonexistent user" |
| 537 |
except ValueError as e: |
| 538 |
assert "The entry does not exist" in str(e) |
| 539 |
|
| 540 |
log.info('Verify the renamed user exists') |
| 541 |
renamed_user = users.get(new_name) |
| 542 |
assert renamed_user.exists() |
| 543 |
finally: |
| 544 |
log.info('Clean up') |
| 545 |
for username in [original_name, new_name]: |
| 546 |
try: |
| 547 |
user = users.get(username) |
| 548 |
if user.exists(): |
| 549 |
user.delete() |
| 550 |
except: |
| 551 |
pass |
| 552 |
|
| 553 |
|
| 554 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 555 |
def test_dsidm_user_rename_same_cn_displayname(topology_st): |
| 556 |
"""Test dsidm user rename when another user has same cn/displayName |
| 557 |
|
| 558 |
:id: 4b65b68f-aeda-43a0-99b6-f4c65034ba4b |
| 559 |
:setup: Standalone instance |
| 560 |
:steps: |
| 561 |
1. Create first user with uid=user1, cn=testuser, displayName=testuser |
| 562 |
2. Create second user with uid=user2, cn=testuser, displayName=testuser |
| 563 |
3. Rename user1 to new_user1 |
| 564 |
4. Try to rename user1 again - should fail as user1 no longer exists |
| 565 |
5. Verify user2 still exists with original attributes |
| 566 |
:expectedresults: |
| 567 |
1. Success |
| 568 |
2. Success |
| 569 |
3. Success - user1 is renamed despite shared cn/displayName |
| 570 |
4. Failure - should report user1 doesn't exist |
| 571 |
5. Success - user2 is unchanged |
| 572 |
""" |
| 573 |
|
| 574 |
standalone = topology_st.standalone |
| 575 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 576 |
user1_uid = 'user1' |
| 577 |
user2_uid = 'user2' |
| 578 |
common_name = 'testuser' |
| 579 |
new_name = 'new_user1' |
| 580 |
renamed_user = None |
| 581 |
user2 = None |
| 582 |
|
| 583 |
try: |
| 584 |
log.info('Create first user') |
| 585 |
args = FakeArgs() |
| 586 |
args.uid = user1_uid |
| 587 |
args.cn = common_name |
| 588 |
args.displayName = common_name |
| 589 |
args.uidNumber = '1101' |
| 590 |
args.gidNumber = '2101' |
| 591 |
args.homeDirectory = f'/home/{user1_uid}' |
| 592 |
args.user_type = 'posix' |
| 593 |
create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 594 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully created {user1_uid}') |
| 595 |
|
| 596 |
log.info('Create second user with same cn/displayName') |
| 597 |
args = FakeArgs() |
| 598 |
args.uid = user2_uid |
| 599 |
args.cn = common_name |
| 600 |
args.displayName = common_name |
| 601 |
args.uidNumber = '1102' |
| 602 |
args.gidNumber = '2102' |
| 603 |
args.homeDirectory = f'/home/{user2_uid}' |
| 604 |
args.user_type = 'posix' |
| 605 |
create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 606 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully created {user2_uid}') |
| 607 |
|
| 608 |
log.info('Rename first user') |
| 609 |
args = FakeArgs() |
| 610 |
args.selector = user1_uid |
| 611 |
args.new_name = new_name |
| 612 |
args.keep_old_rdn = False |
| 613 |
args.user_type = 'posix' |
| 614 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 615 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully renamed to') |
| 616 |
|
| 617 |
log.info('Try to rename the first user again') |
| 618 |
try: |
| 619 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 620 |
assert False, "The rename operation should have failed since user1 no longer exists" |
| 621 |
except ValueError as e: |
| 622 |
assert "The entry does not exist" in str(e) |
| 623 |
|
| 624 |
log.info('Verify second user still exists with original attributes') |
| 625 |
user2 = users.get(user2_uid) |
| 626 |
assert user2.exists() |
| 627 |
assert user2.get_attr_val_utf8('cn') == common_name |
| 628 |
assert user2.get_attr_val_utf8('displayName') == common_name |
| 629 |
finally: |
| 630 |
log.info('Clean up') |
| 631 |
for username in [user1_uid, user2_uid, new_name]: |
| 632 |
try: |
| 633 |
user = users.get(username) |
| 634 |
if user.exists(): |
| 635 |
user.delete() |
| 636 |
except: |
| 637 |
pass |
| 638 |
|
| 639 |
|
| 640 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 641 |
def test_dsidm_user_rename_to_existing_name(topology_st): |
| 642 |
"""Test dsidm user rename to an existing user name |
| 643 |
|
| 644 |
:id: 410bec4f-ecfb-4662-917c-1e7bf97876f2 |
| 645 |
:setup: Standalone instance |
| 646 |
:steps: |
| 647 |
1. Create first user with uid=user1 |
| 648 |
2. Create second user with uid=user2 |
| 649 |
3. Try to rename user1 to user2 |
| 650 |
:expectedresults: |
| 651 |
1. Success |
| 652 |
2. Success |
| 653 |
3. Failure - should report name already in use |
| 654 |
""" |
| 655 |
|
| 656 |
standalone = topology_st.standalone |
| 657 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 658 |
user1_uid = 'user1_duplicate' |
| 659 |
user2_uid = 'user2_duplicate' |
| 660 |
user1 = None |
| 661 |
user2 = None |
| 662 |
|
| 663 |
try: |
| 664 |
log.info('Create first user') |
| 665 |
args = FakeArgs() |
| 666 |
args.uid = user1_uid |
| 667 |
args.cn = user1_uid |
| 668 |
args.displayName = user1_uid |
| 669 |
args.uidNumber = '1201' |
| 670 |
args.gidNumber = '2201' |
| 671 |
args.homeDirectory = f'/home/{user1_uid}' |
| 672 |
args.user_type = 'posix' |
| 673 |
create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 674 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully created {user1_uid}') |
| 675 |
|
| 676 |
log.info('Create second user') |
| 677 |
args = FakeArgs() |
| 678 |
args.uid = user2_uid |
| 679 |
args.cn = user2_uid |
| 680 |
args.displayName = user2_uid |
| 681 |
args.uidNumber = '1202' |
| 682 |
args.gidNumber = '2202' |
| 683 |
args.homeDirectory = f'/home/{user2_uid}' |
| 684 |
args.user_type = 'posix' |
| 685 |
create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 686 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully created {user2_uid}') |
| 687 |
|
| 688 |
log.info('Try to rename first user to second user name') |
| 689 |
args = FakeArgs() |
| 690 |
args.selector = user1_uid |
| 691 |
args.new_name = user2_uid |
| 692 |
args.keep_old_rdn = False |
| 693 |
args.user_type = 'posix' |
| 694 |
try: |
| 695 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 696 |
assert False, "The rename operation should have failed" |
| 697 |
except ldap.ALREADY_EXISTS as e: |
| 698 |
assert "Already exists" in str(e) |
| 699 |
|
| 700 |
log.info('Verify both original users still exist') |
| 701 |
user1 = users.get(user1_uid) |
| 702 |
user2 = users.get(user2_uid) |
| 703 |
assert user1.exists() |
| 704 |
assert user2.exists() |
| 705 |
finally: |
| 706 |
log.info('Clean up') |
| 707 |
for username in [user1_uid, user2_uid]: |
| 708 |
try: |
| 709 |
user = users.get(username) |
| 710 |
if user.exists(): |
| 711 |
user.delete() |
| 712 |
except: |
| 713 |
pass |
| 714 |
|
| 715 |
|
| 716 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 717 |
def test_dsidm_user_rename_keep_old_rdn_and_search(topology_st): |
| 718 |
"""Test dsidm user rename with keep-old-rdn and search behavior |
| 719 |
|
| 720 |
:id: 7e9dd9dd-48a5-44c1-a5ec-9882d2bbae97 |
| 721 |
:setup: Standalone instance |
| 722 |
:steps: |
| 723 |
1. Create a user |
| 724 |
2. Rename the user with keep-old-rdn=True |
| 725 |
3. Verify the user has both the new and old uid values in its entry |
| 726 |
4. Try to rename by using the old uid as selector |
| 727 |
:expectedresults: |
| 728 |
1. Success |
| 729 |
2. Success - user is renamed with old RDN kept |
| 730 |
3. Success - both uid values are present |
| 731 |
4. Failure - should not be able to find the user by its old uid as the DN |
| 732 |
""" |
| 733 |
|
| 734 |
standalone = topology_st.standalone |
| 735 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 736 |
original_name = 'keep_old_rdn_user' |
| 737 |
new_name = 'new_keep_old_user' |
| 738 |
renamed_user = None |
| 739 |
|
| 740 |
try: |
| 741 |
log.info('Create a user') |
| 742 |
args = FakeArgs() |
| 743 |
args.uid = original_name |
| 744 |
args.cn = original_name |
| 745 |
args.displayName = original_name |
| 746 |
args.uidNumber = '1501' |
| 747 |
args.gidNumber = '2501' |
| 748 |
args.homeDirectory = f'/home/{original_name}' |
| 749 |
args.user_type = 'posix' |
| 750 |
create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 751 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully created {original_name}') |
| 752 |
|
| 753 |
log.info('Rename the user with keep-old-rdn=True') |
| 754 |
args = FakeArgs() |
| 755 |
args.selector = original_name |
| 756 |
args.new_name = new_name |
| 757 |
args.keep_old_rdn = True |
| 758 |
args.user_type = 'posix' |
| 759 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 760 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully renamed to') |
| 761 |
|
| 762 |
log.info('Verify that both old and new uid values exist in the entry') |
| 763 |
renamed_user = users.get(new_name) |
| 764 |
assert renamed_user.exists() |
| 765 |
|
| 766 |
# The entry should have both the new and old uid values |
| 767 |
uid_values = renamed_user.get_attr_vals_utf8('uid') |
| 768 |
assert new_name in uid_values |
| 769 |
assert original_name in uid_values |
| 770 |
|
| 771 |
# Other attributes should remain as they were |
| 772 |
assert renamed_user.get_attr_val_utf8('cn') == original_name |
| 773 |
assert renamed_user.get_attr_val_utf8('displayName') == original_name |
| 774 |
|
| 775 |
log.info('Try to rename using the original name as selector - should fail because entry does not exist at that DN') |
| 776 |
args.selector = original_name |
| 777 |
args.new_name = 'another_new_name' |
| 778 |
args.keep_old_rdn = False |
| 779 |
|
| 780 |
try: |
| 781 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 782 |
assert False, "The rename operation should have failed because the entry with original RDN doesn't exist" |
| 783 |
except ValueError as e: |
| 784 |
assert "The entry does not exist" in str(e) |
| 785 |
finally: |
| 786 |
log.info('Clean up') |
| 787 |
for username in [original_name, new_name, 'another_new_name']: |
| 788 |
try: |
| 789 |
user = users.get(username) |
| 790 |
if user.exists(): |
| 791 |
user.delete() |
| 792 |
except: |
| 793 |
pass |
| 794 |
|
| 795 |
|
| 796 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 797 |
def test_dsidm_user_list_rdn_after_rename(topology_st): |
| 798 |
"""Test dsidm user list displays correct RDN after renaming with keep-old-rdn |
| 799 |
|
| 800 |
:id: 5d8b758d-ddca-427d-9aac-7e4d84d7537e |
| 801 |
:setup: Standalone instance |
| 802 |
:steps: |
| 803 |
1. Create a user |
| 804 |
2. Rename the user with keep-old-rdn=True |
| 805 |
3. Run dsidm user list and check the output contains the new name |
| 806 |
4. Run dsidm user list with json and check it also shows the new name |
| 807 |
5. Directly verify that the RDN extraction works correctly |
| 808 |
:expectedresults: |
| 809 |
1. Success |
| 810 |
2. Success |
| 811 |
3. Success - list should show the new name from the DN's RDN |
| 812 |
4. Success - json output should also show the new name |
| 813 |
5. Success - RDN value should match the new name, not the old one |
| 814 |
""" |
| 815 |
|
| 816 |
standalone = topology_st.standalone |
| 817 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 818 |
original_name = 'original_rdn_user' |
| 819 |
new_name = 'new_rdn_user' |
| 820 |
renamed_user = None |
| 821 |
|
| 822 |
try: |
| 823 |
log.info('Create a user') |
| 824 |
args = FakeArgs() |
| 825 |
args.uid = original_name |
| 826 |
args.cn = original_name |
| 827 |
args.displayName = original_name |
| 828 |
args.uidNumber = '1601' |
| 829 |
args.gidNumber = '2601' |
| 830 |
args.homeDirectory = f'/home/{original_name}' |
| 831 |
args.user_type = 'posix' |
| 832 |
create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 833 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully created {original_name}') |
| 834 |
|
| 835 |
log.info('Rename the user with keep-old-rdn=True') |
| 836 |
args = FakeArgs() |
| 837 |
args.selector = original_name |
| 838 |
args.new_name = new_name |
| 839 |
args.keep_old_rdn = True |
| 840 |
args.user_type = 'posix' |
| 841 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 842 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully renamed to') |
| 843 |
|
| 844 |
log.info('Test dsidm user list without json') |
| 845 |
args = FakeArgs() |
| 846 |
args.json = False |
| 847 |
args.full_dn = False |
| 848 |
args.user_type = 'posix' |
| 849 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 850 |
# Should show the new name, not the original name |
| 851 |
check_value_in_log_and_reset(topology_st, check_value=new_name, check_value_not=original_name) |
| 852 |
|
| 853 |
log.info('Test dsidm user list with json') |
| 854 |
args.json = True |
| 855 |
args.user_type = 'posix' |
| 856 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 857 |
# Should show the new name in JSON output as well |
| 858 |
check_value_in_log_and_reset(topology_st, check_value=new_name, check_value_not=original_name) |
| 859 |
|
| 860 |
log.info('Test full_dn option with list') |
| 861 |
args.full_dn = True |
| 862 |
args.user_type = 'posix' |
| 863 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 864 |
result = topology_st.logcap.get_raw_outputs() |
| 865 |
json_result = json.loads(result[0]) |
| 866 |
assert is_a_dn(json_result['items'][0]) |
| 867 |
args.full_dn = False |
| 868 |
|
| 869 |
log.info('Directly verify RDN extraction works correctly') |
| 870 |
renamed_user = users.get(new_name) |
| 871 |
rdn_value = renamed_user.get_rdn_from_dn(renamed_user.dn) |
| 872 |
assert rdn_value == new_name, f"Expected RDN value '{new_name}' but got '{rdn_value}'" |
| 873 |
|
| 874 |
# Check that both uid values exist in the entry |
| 875 |
uid_values = renamed_user.get_attr_vals_utf8('uid') |
| 876 |
assert new_name in uid_values, f"New uid value '{new_name}' not found in {uid_values}" |
| 877 |
assert original_name in uid_values, f"Original uid value '{original_name}' not found in {uid_values}" |
| 878 |
finally: |
| 879 |
log.info('Clean up') |
| 880 |
for username in [original_name, new_name]: |
| 881 |
try: |
| 882 |
user = users.get(username) |
| 883 |
if user.exists(): |
| 884 |
user.delete() |
| 885 |
except: |
| 886 |
pass |
| 887 |
|
| 888 |
|
| 889 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 890 |
def test_dsidm_user_rename_no_changes(topology_st): |
| 891 |
"""Test dsidm user rename reports no changes when renaming to an RDN value already present |
| 892 |
|
| 893 |
:id: bda8eddf-1cad-45d6-a0d1-7dca6d1c315c |
| 894 |
:setup: Standalone instance |
| 895 |
:steps: |
| 896 |
1. Create a user |
| 897 |
2. Rename the user to a new name with keep-old-rdn=True |
| 898 |
3. Try to rename the user again to the same new name with keep-old-rdn=True |
| 899 |
4. Verify the message indicates no changes made |
| 900 |
5. Try to rename the user again to the same new name with keep-old-rdn=False |
| 901 |
6. Verify the message indicates no changes made again |
| 902 |
7. Try to use the original name as selector (should fail) |
| 903 |
:expectedresults: |
| 904 |
1. Success |
| 905 |
2. Success - user is renamed and keeps old RDN |
| 906 |
3. Success - rename operation doesn't error |
| 907 |
4. Success - message indicates no changes rather than success |
| 908 |
5. Success - rename operation doesn't error |
| 909 |
6. Success - message indicates no changes rather than success |
| 910 |
7. Failure - entry with original name as RDN no longer exists |
| 911 |
""" |
| 912 |
|
| 913 |
standalone = topology_st.standalone |
| 914 |
users = nsUserAccounts(standalone, DEFAULT_SUFFIX) |
| 915 |
original_name = 'no_change_user' |
| 916 |
new_name = 'renamed_user' |
| 917 |
test_user = None |
| 918 |
|
| 919 |
try: |
| 920 |
log.info('Create a user') |
| 921 |
args = FakeArgs() |
| 922 |
args.uid = original_name |
| 923 |
args.cn = original_name |
| 924 |
args.displayName = original_name |
| 925 |
args.uidNumber = '1800' |
| 926 |
args.gidNumber = '2800' |
| 927 |
args.homeDirectory = f'/home/{original_name}' |
| 928 |
args.user_type = 'posix' |
| 929 |
create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 930 |
check_value_in_log_and_reset(topology_st, check_value=f'Successfully created {original_name}') |
| 931 |
|
| 932 |
log.info('Rename the user with keep-old-rdn=True') |
| 933 |
args = FakeArgs() |
| 934 |
args.selector = original_name |
| 935 |
args.new_name = new_name |
| 936 |
args.keep_old_rdn = True |
| 937 |
args.user_type = 'posix' |
| 938 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 939 |
check_value_in_log_and_reset(topology_st, check_value='Successfully renamed') |
| 940 |
|
| 941 |
log.info('Try to rename the user again to the same name with keep-old-rdn=True') |
| 942 |
# We must use the new name as the selector now, since that's the current RDN |
| 943 |
args.selector = new_name |
| 944 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 945 |
check_value_in_log_and_reset(topology_st, check_value='No changes made', check_value_not='Successfully renamed') |
| 946 |
|
| 947 |
log.info('Try to rename the user again with keep-old-rdn=False') |
| 948 |
args.keep_old_rdn = False |
| 949 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 950 |
check_value_in_log_and_reset(topology_st, check_value='No changes made', check_value_not='Successfully renamed') |
| 951 |
|
| 952 |
log.info('Verify the user exists with both original and new RDNs') |
| 953 |
test_user = users.get(new_name) |
| 954 |
assert test_user.exists() |
| 955 |
assert original_name in test_user.get_attr_vals_utf8('uid') |
| 956 |
assert new_name in test_user.get_attr_vals_utf8('uid') |
| 957 |
|
| 958 |
log.info('Try to use the original name as selector (should fail)') |
| 959 |
args.selector = original_name |
| 960 |
args.new_name = 'another_name' |
| 961 |
try: |
| 962 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 963 |
assert False, "The rename operation should have failed because the entry with original RDN doesn't exist" |
| 964 |
except ValueError as e: |
| 965 |
assert "The entry does not exist" in str(e) |
| 966 |
|
| 967 |
finally: |
| 968 |
log.info('Clean up') |
| 969 |
try: |
| 970 |
if test_user and test_user.exists(): |
| 971 |
test_user.delete() |
| 972 |
except: |
| 973 |
pass |
| 974 |
|
| 975 |
|
| 976 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 977 |
def test_create_user_list_get_modify_rename_delete_by_user_type(topology_st): |
| 978 |
"""create_user() for each type; dsidm list --user-type; get/modify/rename/delete. |
| 979 |
|
| 980 |
:id: c4e90d11-6f2a-4d8e-bc01-9a8f7e3d5012 |
| 981 |
:setup: Standalone instance |
| 982 |
""" |
| 983 |
|
| 984 |
standalone = topology_st.standalone |
| 985 |
|
| 986 |
basic_user = create_user(topology_st, 'basic') |
| 987 |
posix_user = create_user(topology_st, 'posix') |
| 988 |
traditional_user = create_user(topology_st, 'traditional') |
| 989 |
service_user = create_user(topology_st, 'service') |
| 990 |
|
| 991 |
args = FakeArgs() |
| 992 |
args.json = True |
| 993 |
args.full_dn = False |
| 994 |
|
| 995 |
args.user_type = 'basic' |
| 996 |
topology_st.logcap.flush() |
| 997 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 998 |
basic_items = set(json.loads(topology_st.logcap.get_raw_outputs()[0])['items']) |
| 999 |
assert basic_items >= {'basic_user', 'posix_user'} |
| 1000 |
assert traditional_user not in basic_items |
| 1001 |
assert service_user not in basic_items |
| 1002 |
|
| 1003 |
args.user_type = 'posix' |
| 1004 |
topology_st.logcap.flush() |
| 1005 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 1006 |
posix_items = set(json.loads(topology_st.logcap.get_raw_outputs()[0])['items']) |
| 1007 |
assert posix_items == {'demo_user', 'posix_user'} |
| 1008 |
|
| 1009 |
args.user_type = 'traditional' |
| 1010 |
topology_st.logcap.flush() |
| 1011 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 1012 |
trad_items = set(json.loads(topology_st.logcap.get_raw_outputs()[0])['items']) |
| 1013 |
assert trad_items == {'traditional_user'} |
| 1014 |
|
| 1015 |
args.user_type = 'service' |
| 1016 |
topology_st.logcap.flush() |
| 1017 |
list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 1018 |
svc_items = set(json.loads(topology_st.logcap.get_raw_outputs()[0])['items']) |
| 1019 |
assert svc_items == {'service_user'} |
| 1020 |
|
| 1021 |
selectors = { |
| 1022 |
'posix': 'posix_user', |
| 1023 |
'basic': 'basic_user', |
| 1024 |
'traditional': 'traditional_user', |
| 1025 |
'service': 'service_user', |
| 1026 |
} |
| 1027 |
|
| 1028 |
try: |
| 1029 |
for ut in ('posix', 'basic', 'traditional', 'service'): |
| 1030 |
sel = selectors[ut] |
| 1031 |
renamed = '%s_rn' % sel |
| 1032 |
|
| 1033 |
args = FakeArgs() |
| 1034 |
args.json = False |
| 1035 |
args.selector = sel |
| 1036 |
args.user_type = ut |
| 1037 |
topology_st.logcap.flush() |
| 1038 |
get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 1039 |
assert topology_st.logcap.contains(sel) |
| 1040 |
|
| 1041 |
args = FakeArgs() |
| 1042 |
args.selector = sel |
| 1043 |
args.user_type = ut |
| 1044 |
args.changes = ['add:description:roundtrip_%s' % ut] |
| 1045 |
topology_st.logcap.flush() |
| 1046 |
modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, |
| 1047 |
warn=False) |
| 1048 |
assert topology_st.logcap.contains('Successfully modified') |
| 1049 |
|
| 1050 |
args = FakeArgs() |
| 1051 |
args.selector = sel |
| 1052 |
args.new_name = renamed |
| 1053 |
args.keep_old_rdn = False |
| 1054 |
args.user_type = ut |
| 1055 |
topology_st.logcap.flush() |
| 1056 |
rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 1057 |
assert topology_st.logcap.contains('Successfully renamed') |
| 1058 |
|
| 1059 |
args = FakeArgs() |
| 1060 |
args.json = False |
| 1061 |
args.selector = renamed |
| 1062 |
args.user_type = ut |
| 1063 |
topology_st.logcap.flush() |
| 1064 |
get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) |
| 1065 |
assert topology_st.logcap.contains(renamed) |
| 1066 |
|
| 1067 |
finally: |
| 1068 |
standalone.simple_bind_s(DN_DM, PASSWORD) |
| 1069 |
for ut in ('posix', 'basic', 'traditional', 'service'): |
| 1070 |
sel = selectors[ut] |
| 1071 |
renamed = '%s_rn' % sel |
| 1072 |
for rdn_val in (renamed, sel): |
| 1073 |
args = FakeArgs() |
| 1074 |
args.user_type = ut |
| 1075 |
try: |
| 1076 |
delete(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, |
| 1077 |
args, warn=False) |
| 1078 |
except Exception: |
| 1079 |
pass |
| 1080 |
|
| 1081 |
|
| 1082 |
if __name__ == '__main__': |
| 1083 |
# Run isolated |
| 1084 |
# -s for DEBUG mode |
| 1085 |
CURRENT_FILE = os.path.realpath(__file__) |
| 1086 |
pytest.main("-s %s" % CURRENT_FILE) |