| 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 pytest |
| 10 |
from lib389.tasks import * |
| 11 |
from lib389.utils import * |
| 12 |
from test389.topologies import topology_st |
| 13 |
from lib389.pwpolicy import PwPolicyManager |
| 14 |
from lib389.idm.user import UserAccount, UserAccounts, TEST_USER_PROPERTIES |
| 15 |
from lib389.idm.organizationalunit import OrganizationalUnits |
| 16 |
from lib389._constants import (DEFAULT_SUFFIX, DN_DM, PASSWORD) |
| 17 |
from lib389.idm.directorymanager import DirectoryManager |
| 18 |
|
| 19 |
pytestmark = pytest.mark.tier1 |
| 20 |
|
| 21 |
OU_PEOPLE = 'ou=people,{}'.format(DEFAULT_SUFFIX) |
| 22 |
TEST_USER_NAME = 'simplepaged_test' |
| 23 |
TEST_USER_DN = 'uid={},{}'.format(TEST_USER_NAME, OU_PEOPLE) |
| 24 |
TEST_USER_PWD = 'simplepaged_test' |
| 25 |
PW_POLICY_CONT_USER = 'cn="cn=nsPwPolicyEntry,uid=simplepaged_test,' \ |
| 26 |
'ou=people,dc=example,dc=com",' \ |
| 27 |
'cn=nsPwPolicyContainer,ou=people,dc=example,dc=com' |
| 28 |
PW_POLICY_CONT_PEOPLE = 'cn="cn=nsPwPolicyEntry,' \ |
| 29 |
'ou=people,dc=example,dc=com",' \ |
| 30 |
'cn=nsPwPolicyContainer,ou=people,dc=example,dc=com' |
| 31 |
|
| 32 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 33 |
log = logging.getLogger(__name__) |
| 34 |
|
| 35 |
|
| 36 |
@pytest.fixture(scope="module") |
| 37 |
def add_test_user(topology_st, request): |
| 38 |
"""User for binding operation""" |
| 39 |
topology_st.standalone.config.set('nsslapd-auditlog-logging-enabled', 'on') |
| 40 |
log.info('Adding test user {}') |
| 41 |
users = UserAccounts(topology_st.standalone, OU_PEOPLE, rdn=None) |
| 42 |
user_props = TEST_USER_PROPERTIES.copy() |
| 43 |
user_props.update({'uid': TEST_USER_NAME, 'userpassword': TEST_USER_PWD}) |
| 44 |
try: |
| 45 |
user = users.create(properties=user_props) |
| 46 |
except: |
| 47 |
pass # debug only |
| 48 |
|
| 49 |
USER_ACI = '(targetattr="*")(version 3.0; acl "pwp test"; allow (all) userdn="ldap:///%s";)' % user.dn |
| 50 |
ous = OrganizationalUnits(topology_st.standalone, DEFAULT_SUFFIX) |
| 51 |
ou_people = ous.get('people') |
| 52 |
ou_people.add('aci', USER_ACI) |
| 53 |
|
| 54 |
def fin(): |
| 55 |
log.info('Deleting user {}'.format(user.dn)) |
| 56 |
topology_st.standalone.simple_bind_s(DN_DM, PASSWORD) |
| 57 |
|
| 58 |
request.addfinalizer(fin) |
| 59 |
return user |
| 60 |
|
| 61 |
|
| 62 |
@pytest.fixture(scope="function") |
| 63 |
def password_policy(topology_st, request, add_test_user): |
| 64 |
"""Set up password policy for subtree and user""" |
| 65 |
|
| 66 |
pwp = PwPolicyManager(topology_st.standalone) |
| 67 |
policy_props = {} |
| 68 |
log.info(f"Create password policy for subtree {OU_PEOPLE}") |
| 69 |
try: |
| 70 |
pwp.create_subtree_policy(OU_PEOPLE, policy_props) |
| 71 |
except ldap.ALREADY_EXISTS: |
| 72 |
log.info(f"Subtree password policy for {OU_PEOPLE} already exist, skipping") |
| 73 |
|
| 74 |
log.info(f"Create password policy for user {TEST_USER_DN}") |
| 75 |
try: |
| 76 |
pwp.create_user_policy(TEST_USER_DN, policy_props) |
| 77 |
except ldap.ALREADY_EXISTS: |
| 78 |
log.info(f"User password policy for {TEST_USER_DN} already exist, skipping") |
| 79 |
|
| 80 |
def fin(): |
| 81 |
log.info(f"Delete password policy for subtree {OU_PEOPLE}") |
| 82 |
try: |
| 83 |
pwp.delete_local_policy(OU_PEOPLE) |
| 84 |
except ValueError: |
| 85 |
log.info(f"Subtree password policy for {OU_PEOPLE} doesn't exist, skipping") |
| 86 |
|
| 87 |
log.info(f"Delete password policy for user {TEST_USER_DN}") |
| 88 |
try: |
| 89 |
pwp.delete_local_policy(TEST_USER_DN) |
| 90 |
except ValueError: |
| 91 |
log.info(f"User password policy for {TEST_USER_DN} doesn't exist, skipping") |
| 92 |
|
| 93 |
request.addfinalizer(fin) |
| 94 |
|
| 95 |
|
| 96 |
@pytest.mark.skipif(ds_is_older('1.4.3.3'), reason="Not implemented") |
| 97 |
def test_pwdReset_by_user_DM(topology_st, add_test_user): |
| 98 |
"""Test new password policy attribute "pwdReset" |
| 99 |
|
| 100 |
:id: 232bc7dc-8cb6-11eb-9791-98fa9ba19b65 |
| 101 |
:customerscenario: True |
| 102 |
:setup: Standalone instance, Add a new user with a password |
| 103 |
:steps: |
| 104 |
1. Enable passwordMustChange |
| 105 |
2. Bind as the user and change the password |
| 106 |
3. Check that the pwdReset attribute is set to TRUE |
| 107 |
4. Bind as the Directory manager and attempt to change the pwdReset to FALSE |
| 108 |
5. Check that pwdReset is NOT SET to FALSE |
| 109 |
:expectedresults: |
| 110 |
1. Success |
| 111 |
2. Success |
| 112 |
3. Successful bind as DS user, pwdReset as DS user fails w UNWILLING_TO_PERFORM |
| 113 |
4. Success |
| 114 |
5. Success |
| 115 |
""" |
| 116 |
|
| 117 |
# Reset user's password |
| 118 |
our_user = UserAccount(topology_st.standalone, TEST_USER_DN) |
| 119 |
log.info('Set password policy passwordMustChange on') |
| 120 |
topology_st.standalone.config.replace('passwordMustChange', 'on') |
| 121 |
our_user.replace('userpassword', PASSWORD) |
| 122 |
time.sleep(5) |
| 123 |
|
| 124 |
# Check that pwdReset is TRUE |
| 125 |
assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE' |
| 126 |
|
| 127 |
log.info('Binding as the Directory manager and attempt to change the pwdReset to FALSE') |
| 128 |
topology_st.standalone.simple_bind_s(DN_DM, PASSWORD) |
| 129 |
with pytest.raises(ldap.UNWILLING_TO_PERFORM): |
| 130 |
topology_st.standalone.config.replace('pwdReset', 'FALSE') |
| 131 |
|
| 132 |
log.info('Check that pwdReset is NOT SET to FALSE') |
| 133 |
assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE' |
| 134 |
|
| 135 |
log.info('Resetting password for {}'.format(TEST_USER_PWD)) |
| 136 |
our_user.reset_password(TEST_USER_PWD) |
| 137 |
|
| 138 |
|
| 139 |
@pytest.mark.skipif(ds_is_older('1.4.3.3'), reason="Not implemented") |
| 140 |
def test_pwd_reset(topology_st, add_test_user): |
| 141 |
"""Test new password policy attribute "pwdReset" |
| 142 |
|
| 143 |
:id: 03db357b-4800-411e-a36e-28a534293004 |
| 144 |
:customerscenario: True |
| 145 |
:setup: Standalone instance |
| 146 |
:steps: |
| 147 |
1. Enable passwordMustChange |
| 148 |
2. Reset user's password |
| 149 |
3. Check that the pwdReset attribute is set to TRUE |
| 150 |
4. Bind as the user and change its password |
| 151 |
5. Check that pwdReset is now set to FALSE |
| 152 |
6. Reset password policy configuration |
| 153 |
:expectedresults: |
| 154 |
1. Success |
| 155 |
2. Success |
| 156 |
3. Success |
| 157 |
4. Success |
| 158 |
5. Success |
| 159 |
6. Success |
| 160 |
""" |
| 161 |
|
| 162 |
# Set password policy config |
| 163 |
topology_st.standalone.config.replace('passwordMustChange', 'on') |
| 164 |
time.sleep(.5) |
| 165 |
|
| 166 |
# Reset user's password |
| 167 |
our_user = UserAccount(topology_st.standalone, TEST_USER_DN) |
| 168 |
our_user.replace('userpassword', PASSWORD) |
| 169 |
time.sleep(.5) |
| 170 |
|
| 171 |
# Check that pwdReset is TRUE |
| 172 |
assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE' |
| 173 |
|
| 174 |
# Bind as user and change its own password |
| 175 |
our_user.rebind(PASSWORD) |
| 176 |
our_user.replace('userpassword', PASSWORD) |
| 177 |
time.sleep(.5) |
| 178 |
|
| 179 |
# Check that pwdReset is FALSE |
| 180 |
topology_st.standalone.simple_bind_s(DN_DM, PASSWORD) |
| 181 |
assert our_user.get_attr_val_utf8('pwdReset') == 'FALSE' |
| 182 |
|
| 183 |
# Reset password policy config |
| 184 |
topology_st.standalone.config.replace('passwordMustChange', 'off') |
| 185 |
|
| 186 |
# Reset user's password |
| 187 |
our_user.replace('userpassword', TEST_USER_PWD) |
| 188 |
|
| 189 |
|
| 190 |
@pytest.mark.parametrize('subtree_pwchange,user_pwchange,exception', |
| 191 |
[('on', 'off', ldap.UNWILLING_TO_PERFORM), |
| 192 |
('off', 'off', ldap.UNWILLING_TO_PERFORM), |
| 193 |
('off', 'on', False), ('on', 'on', False)]) |
| 194 |
def test_change_pwd(topology_st, add_test_user, password_policy, |
| 195 |
subtree_pwchange, user_pwchange, exception): |
| 196 |
"""Verify that 'passwordChange' attr works as expected |
| 197 |
User should have a priority over a subtree. |
| 198 |
|
| 199 |
:id: 2c884432-2ba1-4662-8e5d-2cd49f77e5fa |
| 200 |
:parametrized: yes |
| 201 |
:setup: Standalone instance, a test user, |
| 202 |
password policy entries for a user and a subtree |
| 203 |
:steps: |
| 204 |
1. Set passwordChange on the user and the subtree |
| 205 |
to various combinations |
| 206 |
2. Bind as test user |
| 207 |
3. Try to change password |
| 208 |
4. Clean up - change the password to default while bound as DM |
| 209 |
:expectedresults: |
| 210 |
1. passwordChange should be successfully set |
| 211 |
2. Bind should be successful |
| 212 |
3. Subtree/User passwordChange - result, accordingly: |
| 213 |
off/on, on/on - success; |
| 214 |
on/off, off/off - UNWILLING_TO_PERFORM |
| 215 |
4. Operation should be successful |
| 216 |
""" |
| 217 |
|
| 218 |
users = UserAccounts(topology_st.standalone, OU_PEOPLE, rdn=None) |
| 219 |
user = users.get(TEST_USER_NAME) |
| 220 |
|
| 221 |
log.info('Set passwordChange to "{}" - {}'.format(subtree_pwchange, OU_PEOPLE)) |
| 222 |
pwp = PwPolicyManager(topology_st.standalone) |
| 223 |
subtree_policy = pwp.get_pwpolicy_entry(OU_PEOPLE) |
| 224 |
subtree_policy.set('passwordChange', subtree_pwchange) |
| 225 |
|
| 226 |
time.sleep(1) |
| 227 |
|
| 228 |
log.info('Set passwordChange to "{}" - {}'.format(user_pwchange, TEST_USER_DN)) |
| 229 |
pwp2 = PwPolicyManager(topology_st.standalone) |
| 230 |
user_policy = pwp2.get_pwpolicy_entry(TEST_USER_DN) |
| 231 |
user_policy.set('passwordChange', user_pwchange) |
| 232 |
user_policy.set('passwordExp', 'on') |
| 233 |
|
| 234 |
time.sleep(1) |
| 235 |
|
| 236 |
try: |
| 237 |
log.info('Bind as user and modify userPassword') |
| 238 |
user.rebind(TEST_USER_PWD) |
| 239 |
if exception: |
| 240 |
with pytest.raises(exception): |
| 241 |
user.reset_password('new_pass') |
| 242 |
else: |
| 243 |
user.reset_password('new_pass') |
| 244 |
except ldap.LDAPError as e: |
| 245 |
log.error('Failed to change userpassword for {}: error {}'.format( |
| 246 |
TEST_USER_DN, e.args[0]['info'])) |
| 247 |
raise e |
| 248 |
finally: |
| 249 |
log.info('Bind as DM') |
| 250 |
topology_st.standalone.simple_bind_s(DN_DM, PASSWORD) |
| 251 |
user.reset_password(TEST_USER_PWD) |
| 252 |
|
| 253 |
|
| 254 |
def test_pwd_min_age(topology_st, add_test_user, password_policy): |
| 255 |
"""If we set passwordMinAge to some value, for example to 10, then it |
| 256 |
should not allow the user to change the password within 10 seconds after |
| 257 |
his previous change. |
| 258 |
|
| 259 |
:id: 85b98516-8c82-45bd-b9ec-90bd1245e09c |
| 260 |
:setup: Standalone instance, a test user, |
| 261 |
password policy entries for a user and a subtree |
| 262 |
:steps: |
| 263 |
1. Set passwordMinAge to 10 on the user pwpolicy entry |
| 264 |
2. Set passwordMinAge to 10 on the subtree pwpolicy entry |
| 265 |
3. Set passwordMinAge to 10 on the cn=config entry |
| 266 |
4. Bind as test user |
| 267 |
5. Try to change the password two times in a row |
| 268 |
6. Wait 12 seconds |
| 269 |
7. Try to change the password |
| 270 |
8. Clean up - change the password to default while bound as DM |
| 271 |
:expectedresults: |
| 272 |
1. passwordMinAge should be successfully set on the user pwpolicy entry |
| 273 |
2. passwordMinAge should be successfully set on the subtree pwpolicy entry |
| 274 |
3. passwordMinAge should be successfully set on the cn=config entry |
| 275 |
4. Bind should be successful |
| 276 |
5. The password should be successfully changed |
| 277 |
6. 12 seconds have passed |
| 278 |
7. Constraint Violation error should be raised |
| 279 |
8. Operation should be successful |
| 280 |
""" |
| 281 |
|
| 282 |
num_seconds = '10' |
| 283 |
users = UserAccounts(topology_st.standalone, OU_PEOPLE, rdn=None) |
| 284 |
user = users.get(TEST_USER_NAME) |
| 285 |
|
| 286 |
log.info('Set passwordminage to "{}" - {}'.format(num_seconds, OU_PEOPLE)) |
| 287 |
pwp = PwPolicyManager(topology_st.standalone) |
| 288 |
subtree_policy = pwp.get_pwpolicy_entry(OU_PEOPLE) |
| 289 |
subtree_policy.set('passwordminage', num_seconds) |
| 290 |
|
| 291 |
log.info('Set passwordminage to "{}" - {}'.format(num_seconds, TEST_USER_DN)) |
| 292 |
user_policy = pwp.get_pwpolicy_entry(TEST_USER_DN) |
| 293 |
user_policy.set('passwordminage', num_seconds) |
| 294 |
|
| 295 |
log.info('Set passwordminage to "{}" - {}'.format(num_seconds, DN_CONFIG)) |
| 296 |
topology_st.standalone.config.set('passwordminage', num_seconds) |
| 297 |
|
| 298 |
time.sleep(1) |
| 299 |
|
| 300 |
log.info('Bind as user and modify userPassword') |
| 301 |
user.rebind(TEST_USER_PWD) |
| 302 |
user.reset_password('new_pass') |
| 303 |
|
| 304 |
time.sleep(1) |
| 305 |
|
| 306 |
log.info('Bind as user and modify userPassword straight away after previous change') |
| 307 |
user.rebind('new_pass') |
| 308 |
with pytest.raises(ldap.CONSTRAINT_VIOLATION): |
| 309 |
user.reset_password('new_new_pass') |
| 310 |
|
| 311 |
log.info('Wait {} second'.format(int(num_seconds) + 2)) |
| 312 |
time.sleep(int(num_seconds) + 2) |
| 313 |
|
| 314 |
try: |
| 315 |
log.info('Bind as user and modify userPassword') |
| 316 |
user.rebind('new_pass') |
| 317 |
user.reset_password(TEST_USER_PWD) |
| 318 |
except ldap.LDAPError as e: |
| 319 |
log.error('Failed to change userpassword for {}: error {}'.format( |
| 320 |
TEST_USER_DN, e.args[0]['info'])) |
| 321 |
raise e |
| 322 |
finally: |
| 323 |
log.info('Bind as DM') |
| 324 |
topology_st.standalone.simple_bind_s(DN_DM, PASSWORD) |
| 325 |
user.reset_password(TEST_USER_PWD) |
| 326 |
|
| 327 |
|
| 328 |
def test_pwdpolicysubentry(topology_st, password_policy): |
| 329 |
"""Verify that 'pwdpolicysubentry' attr works as expected |
| 330 |
User should have a priority over a subtree. |
| 331 |
|
| 332 |
:id: 4ab0c62a-623b-40b4-af67-99580c77b36c |
| 333 |
:setup: Standalone instance, a test user, |
| 334 |
password policy entries for a user and a subtree |
| 335 |
:steps: |
| 336 |
1. Create a subtree policy |
| 337 |
2. Create a user policy |
| 338 |
3. Search for 'pwdpolicysubentry' in the user entry |
| 339 |
4. Delete the user policy |
| 340 |
5. Search for 'pwdpolicysubentry' in the user entry |
| 341 |
:expectedresults: |
| 342 |
1. Success |
| 343 |
2. Success |
| 344 |
3. Should point to the user policy entry |
| 345 |
4. Success |
| 346 |
5. Should point to the subtree policy entry |
| 347 |
|
| 348 |
""" |
| 349 |
|
| 350 |
users = UserAccounts(topology_st.standalone, OU_PEOPLE, rdn=None) |
| 351 |
user = users.get(TEST_USER_NAME) |
| 352 |
|
| 353 |
pwp_subentry = user.get_attr_vals_utf8('pwdpolicysubentry')[0] |
| 354 |
assert 'nsPwPolicyEntry_subtree' not in pwp_subentry |
| 355 |
assert 'nsPwPolicyEntry_user' in pwp_subentry |
| 356 |
|
| 357 |
pwp = PwPolicyManager(topology_st.standalone) |
| 358 |
pwp.delete_local_policy(TEST_USER_DN) |
| 359 |
pwp_subentry = user.get_attr_vals_utf8('pwdpolicysubentry')[0] |
| 360 |
assert 'nsPwPolicyEntry_subtree' in pwp_subentry |
| 361 |
assert 'nsPwPolicyEntry_user' not in pwp_subentry |
| 362 |
|
| 363 |
|
| 364 |
@pytest.fixture(scope="function") |
| 365 |
def shadowUser(request, topology_st): |
| 366 |
""" Create a user with shadowAccount objectclass """ |
| 367 |
users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX) |
| 368 |
shadowUser = users.create(properties={ |
| 369 |
'objectclass': ['top', 'person', 'organizationalPerson', |
| 370 |
'inetOrgPerson', 'extensibleObject', 'shadowAccount'], |
| 371 |
'sn': '1', |
| 372 |
'cn': 'shadowUser', |
| 373 |
'uid': 'shadowUser', |
| 374 |
'uidNumber': '1', |
| 375 |
'gidNumber': '11', |
| 376 |
'homeDirectory': '/home/shadowUser', |
| 377 |
'displayName': 'Shadow User', |
| 378 |
'givenname': 'Shadow', |
| 379 |
'mail':f'shadowuser@{DEFAULT_SUFFIX}', |
| 380 |
'userpassword': 'password' |
| 381 |
}) |
| 382 |
|
| 383 |
def fin(): |
| 384 |
if shadowUser.exists(): |
| 385 |
shadowUser.delete() |
| 386 |
|
| 387 |
request.addfinalizer(fin) |
| 388 |
|
| 389 |
return shadowUser |
| 390 |
|
| 391 |
|
| 392 |
def days_to_secs(days): |
| 393 |
""" Convert days to seconds """ |
| 394 |
return days * 86400 |
| 395 |
|
| 396 |
|
| 397 |
def check_shadow_attr_value(inst, user_dn, attr_type, expected): |
| 398 |
""" Check that shadowAccount attribute has expected value """ |
| 399 |
dm = DirectoryManager(inst) |
| 400 |
dm.rebind() |
| 401 |
user = UserAccount(inst, user_dn) |
| 402 |
assert user.present(attr_type), f'Entry {user_dn} does not have {attr_type} attribute' |
| 403 |
actual = int(user.get_attr_val_utf8(attr_type)) |
| 404 |
assert actual == expected, f'{attr_type} of entry {user_dn} is {actual}, expected {expected}' |
| 405 |
log.info(f'{attr_type} of entry {user_dn} has expected value {actual}') |
| 406 |
|
| 407 |
|
| 408 |
def setup_pwp(inst, pwp_mgr, policy, dn=None, policy_props=None): |
| 409 |
""" Setup password policy """ |
| 410 |
|
| 411 |
log.info(f'Setting up {policy} password policy for {dn}') |
| 412 |
dm = DirectoryManager(inst) |
| 413 |
dm.rebind() |
| 414 |
|
| 415 |
log.info(f'Configuring {policy} password policy') |
| 416 |
|
| 417 |
assert policy == 'global' or dn, 'dn is required for non-global policy' |
| 418 |
|
| 419 |
if not policy_props: |
| 420 |
policy_props = { |
| 421 |
'passwordMinAge': str(days_to_secs(1)), |
| 422 |
'passwordExp': 'on', |
| 423 |
'passwordMaxAge': str(days_to_secs(10)), |
| 424 |
'passwordWarning': str(days_to_secs(3)) |
| 425 |
} |
| 426 |
|
| 427 |
if policy == 'global': |
| 428 |
pwp_mgr.set_global_policy(policy_props) |
| 429 |
elif policy == 'subtree': |
| 430 |
pwp_mgr.create_subtree_policy(dn, policy_props) |
| 431 |
elif policy == 'user': |
| 432 |
pwp_mgr.create_user_policy(dn, policy_props) |
| 433 |
else: |
| 434 |
raise ValueError(f'Invalid type of password policy: {policy}') |
| 435 |
|
| 436 |
|
| 437 |
def modify_pwp(inst, pwp_mgr, policy, dn=None, policy_props=None): |
| 438 |
""" Modify password policy """ |
| 439 |
dm = DirectoryManager(inst) |
| 440 |
dm.rebind() |
| 441 |
|
| 442 |
assert policy == 'global' or dn, 'dn is required for non-global policy' |
| 443 |
|
| 444 |
if not policy_props: |
| 445 |
policy_props = { |
| 446 |
'passwordMinAge': str(days_to_secs(3)), |
| 447 |
'passwordMaxAge': str(days_to_secs(30)), |
| 448 |
'passwordWarning': str(days_to_secs(9)) |
| 449 |
} |
| 450 |
|
| 451 |
if policy == 'global': |
| 452 |
pwp_mgr.set_global_policy(properties=policy_props) |
| 453 |
elif policy in ['subtree', 'user']: |
| 454 |
policy_entry = pwp_mgr.get_pwpolicy_entry(dn) |
| 455 |
policy_entry.replace_many(*policy_props.items()) |
| 456 |
else: |
| 457 |
raise ValueError(f'Invalid type of password policy: {policy}') |
| 458 |
log.info(f'Modified {policy} policy with {policy_props}.') |
| 459 |
|
| 460 |
@pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented") |
| 461 |
def test_shadowaccount_no_policy(topology_st, shadowUser): |
| 462 |
"""Check shadowAccount under no password policy |
| 463 |
|
| 464 |
:id: a1b2c3d4-5e6f-7890-abcd-ef1234567890 |
| 465 |
:setup: Standalone instance |
| 466 |
:steps: |
| 467 |
1. Add a user with shadowAccount objectclass |
| 468 |
2. Bind as the user |
| 469 |
3. Check shadowLastChange attribute is set correctly |
| 470 |
:expectedresults: |
| 471 |
1. User is added successfully |
| 472 |
2. Bind is successful |
| 473 |
3. shadowLastChange is set correctly (days since epoch) |
| 474 |
""" |
| 475 |
|
| 476 |
edate = int(time.time() / (60 * 60 * 24)) |
| 477 |
|
| 478 |
log.info(f"Bind as {shadowUser.dn}") |
| 479 |
shadowUser.rebind('password') |
| 480 |
check_shadow_attr_value(topology_st.standalone, shadowUser.dn, |
| 481 |
'shadowLastChange', edate) |
| 482 |
|
| 483 |
|
| 484 |
@pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented") |
| 485 |
def test_shadowaccount_global_policy(topology_st, shadowUser, request): |
| 486 |
"""Check shadowAccount with global password policy |
| 487 |
|
| 488 |
:id: b2c3d4e5-6f7a-8901-bcde-f23456789012 |
| 489 |
:setup: Standalone instance |
| 490 |
:steps: |
| 491 |
1. Set global password policy |
| 492 |
2. Add a second shadowAccount user |
| 493 |
3. Bind as each user and check shadowAccount attributes |
| 494 |
4. Modify global password policy |
| 495 |
5. Change user password (as the user, not DM) |
| 496 |
6. Re-bind with new password |
| 497 |
7. Check shadowAccount attributes are updated |
| 498 |
8. Clean up - delete second user and reset policy |
| 499 |
:expectedresults: |
| 500 |
1. Global password policy is set successfully |
| 501 |
2. Second user is added |
| 502 |
3. shadowAccount attributes match policy values for both users |
| 503 |
4. Password policy is modified successfully |
| 504 |
5. Password is changed successfully |
| 505 |
6. Re-bind with new password is successful |
| 506 |
7. shadowAccount attributes are updated to match new policy values |
| 507 |
8. Cleanup is successful |
| 508 |
""" |
| 509 |
inst = topology_st.standalone |
| 510 |
|
| 511 |
log.info('Create second shadowAccount user') |
| 512 |
users = UserAccounts(inst, DEFAULT_SUFFIX) |
| 513 |
shadowUser2 = users.create(properties={ |
| 514 |
'objectclass': ['top', 'person', 'organizationalPerson', |
| 515 |
'inetOrgPerson', 'extensibleObject', 'shadowAccount'], |
| 516 |
'sn': '2', |
| 517 |
'cn': 'shadowUser2', |
| 518 |
'uid': 'shadowUser2', |
| 519 |
'uidNumber': '2', |
| 520 |
'gidNumber': '22', |
| 521 |
'homeDirectory': '/home/shadowUser2', |
| 522 |
'displayName': 'Shadow User 2', |
| 523 |
'givenname': 'Shadow2', |
| 524 |
'mail': f'shadowuser2@{DEFAULT_SUFFIX}', |
| 525 |
'userpassword': 'password' |
| 526 |
}) |
| 527 |
|
| 528 |
def fin(): |
| 529 |
log.info('Clean up - delete second user and reset global policy') |
| 530 |
dm = DirectoryManager(inst) |
| 531 |
dm.rebind() |
| 532 |
try: |
| 533 |
shadowUser2.delete() |
| 534 |
except Exception: |
| 535 |
pass |
| 536 |
inst.config.replace('passwordMinAge', '0') |
| 537 |
inst.config.replace('passwordMaxAge', '8640000') |
| 538 |
inst.config.replace('passwordWarning', '86400') |
| 539 |
inst.config.replace('passwordExp', 'off') |
| 540 |
request.addfinalizer(fin) |
| 541 |
|
| 542 |
log.info('Configure global password policy') |
| 543 |
pwp_mgr = PwPolicyManager(inst) |
| 544 |
setup_pwp(inst, pwp_mgr, 'global') |
| 545 |
|
| 546 |
edate = int(time.time() / (60 * 60 * 24)) |
| 547 |
|
| 548 |
log.info('Verify attributes of shadowUser (user 1)') |
| 549 |
shadowUser.rebind('password') |
| 550 |
check_shadow_attr_value(inst, shadowUser.dn, |
| 551 |
'shadowLastChange', edate) |
| 552 |
check_shadow_attr_value(inst, shadowUser.dn, |
| 553 |
'shadowMin', 1) |
| 554 |
check_shadow_attr_value(inst, shadowUser.dn, |
| 555 |
'shadowMax', 10) |
| 556 |
check_shadow_attr_value(inst, shadowUser.dn, |
| 557 |
'shadowWarning', 3) |
| 558 |
|
| 559 |
log.info('Verify attributes of shadowUser2 (user 2)') |
| 560 |
shadowUser2.rebind('password') |
| 561 |
check_shadow_attr_value(inst, shadowUser2.dn, |
| 562 |
'shadowLastChange', edate) |
| 563 |
check_shadow_attr_value(inst, shadowUser2.dn, |
| 564 |
'shadowMin', 1) |
| 565 |
check_shadow_attr_value(inst, shadowUser2.dn, |
| 566 |
'shadowMax', 10) |
| 567 |
check_shadow_attr_value(inst, shadowUser2.dn, |
| 568 |
'shadowWarning', 3) |
| 569 |
|
| 570 |
log.info('Modify global password policy') |
| 571 |
modify_pwp(inst, pwp_mgr, 'global') |
| 572 |
|
| 573 |
log.info('Change shadowUser2 password as the user') |
| 574 |
shadowUser2.rebind('password') |
| 575 |
shadowUser2.replace('userpassword', 'password2') |
| 576 |
time.sleep(1) |
| 577 |
|
| 578 |
log.info('Re-bind as shadowUser2 with new password') |
| 579 |
shadowUser2.rebind('password2') |
| 580 |
|
| 581 |
log.info('Verify modified shadowUser2 attributes') |
| 582 |
check_shadow_attr_value(inst, shadowUser2.dn, |
| 583 |
'shadowMin', 3) |
| 584 |
check_shadow_attr_value(inst, shadowUser2.dn, |
| 585 |
'shadowMax', 30) |
| 586 |
check_shadow_attr_value(inst, shadowUser2.dn, |
| 587 |
'shadowWarning', 9) |
| 588 |
|
| 589 |
|
| 590 |
@pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented") |
| 591 |
def test_shadowaccount_subtree_policy(topology_st, request): |
| 592 |
"""Check shadowAccount with subtree level password policy |
| 593 |
|
| 594 |
:id: c3d4e5f6-7a8b-9012-cdef-345678901234 |
| 595 |
:setup: Standalone instance |
| 596 |
:steps: |
| 597 |
1. Create subtree password policy for DEFAULT_SUFFIX with passwordMustChange on |
| 598 |
2. Add a new shadowAccount user under the subtree |
| 599 |
3. Check shadowLastChange is 0 (since passwordMustChange is on) |
| 600 |
4. Verify search as user fails with UNWILLING_TO_PERFORM |
| 601 |
5. Change user password (as user) |
| 602 |
6. Re-bind with new password |
| 603 |
7. Check shadowAccount attributes are updated with correct values |
| 604 |
8. Clean up subtree password policy |
| 605 |
:expectedresults: |
| 606 |
1. Subtree password policy is created successfully |
| 607 |
2. User is added successfully |
| 608 |
3. shadowLastChange is 0 until password is changed |
| 609 |
4. Search fails with UNWILLING_TO_PERFORM as expected |
| 610 |
5. Password is changed successfully |
| 611 |
6. Re-bind with new password is successful |
| 612 |
7. shadowAccount attributes are updated to match policy values |
| 613 |
8. Subtree password policy is deleted successfully |
| 614 |
""" |
| 615 |
inst = topology_st.standalone |
| 616 |
subtree_dn = DEFAULT_SUFFIX |
| 617 |
|
| 618 |
log.info('Configure subtree password policy with passwordMustChange on') |
| 619 |
properties = { |
| 620 |
'passwordMustChange': 'on', |
| 621 |
'passwordExp': 'on', |
| 622 |
'passwordMinAge': str(days_to_secs(2)), |
| 623 |
'passwordMaxAge': str(days_to_secs(20)), |
| 624 |
'passwordWarning': str(days_to_secs(6)), |
| 625 |
'passwordChange': 'on', |
| 626 |
'passwordStorageScheme': 'clear' |
| 627 |
} |
| 628 |
|
| 629 |
pwp_mgr = PwPolicyManager(inst) |
| 630 |
setup_pwp(inst, pwp_mgr, 'subtree', dn=subtree_dn, policy_props=properties) |
| 631 |
|
| 632 |
def fin(): |
| 633 |
log.info('Clean up: delete subtree password policy') |
| 634 |
dm = DirectoryManager(inst) |
| 635 |
dm.rebind() |
| 636 |
try: |
| 637 |
pwp_mgr.delete_local_policy(subtree_dn) |
| 638 |
except Exception: |
| 639 |
pass |
| 640 |
try: |
| 641 |
subtree_user.delete() |
| 642 |
except Exception: |
| 643 |
pass |
| 644 |
request.addfinalizer(fin) |
| 645 |
|
| 646 |
log.info('Add a new shadowAccount user under the subtree') |
| 647 |
users = UserAccounts(inst, DEFAULT_SUFFIX) |
| 648 |
subtree_user = users.create(properties={ |
| 649 |
'objectclass': ['top', 'person', 'organizationalPerson', |
| 650 |
'inetOrgPerson', 'extensibleObject', 'shadowAccount'], |
| 651 |
'sn': '3', |
| 652 |
'cn': 'subtreeUser', |
| 653 |
'uid': 'subtreeUser', |
| 654 |
'uidNumber': '3', |
| 655 |
'gidNumber': '33', |
| 656 |
'homeDirectory': '/home/subtreeUser', |
| 657 |
'displayName': 'Subtree User', |
| 658 |
'givenname': 'Subtree', |
| 659 |
'mail': f'subtreeuser@{DEFAULT_SUFFIX}', |
| 660 |
'userpassword': 'password' |
| 661 |
}) |
| 662 |
|
| 663 |
dm = DirectoryManager(inst) |
| 664 |
dm.rebind() |
| 665 |
|
| 666 |
log.info('Verify shadowLastChange is 0 since passwordMustChange is on') |
| 667 |
check_shadow_attr_value(inst, subtree_user.dn, |
| 668 |
'shadowLastChange', 0) |
| 669 |
check_shadow_attr_value(inst, subtree_user.dn, |
| 670 |
'shadowMin', 2) |
| 671 |
check_shadow_attr_value(inst, subtree_user.dn, |
| 672 |
'shadowMax', 20) |
| 673 |
check_shadow_attr_value(inst, subtree_user.dn, |
| 674 |
'shadowWarning', 6) |
| 675 |
|
| 676 |
log.info(f'Bind as {subtree_user.dn} and verify search fails with UNWILLING_TO_PERFORM') |
| 677 |
subtree_user.rebind('password') |
| 678 |
with pytest.raises(ldap.UNWILLING_TO_PERFORM): |
| 679 |
subtree_user.exists() |
| 680 |
|
| 681 |
log.info('Modify subtree password policy') |
| 682 |
dm.rebind() |
| 683 |
modify_properties = { |
| 684 |
'passwordMinAge': str(days_to_secs(4)), |
| 685 |
'passwordMaxAge': str(days_to_secs(40)), |
| 686 |
'passwordWarning': str(days_to_secs(12)) |
| 687 |
} |
| 688 |
modify_pwp(inst, pwp_mgr, 'subtree', dn=subtree_dn, policy_props=modify_properties) |
| 689 |
|
| 690 |
log.info(f'Change {subtree_user.dn} password as the user') |
| 691 |
subtree_user.rebind('password') |
| 692 |
subtree_user.replace('userpassword', 'password0') |
| 693 |
time.sleep(1) |
| 694 |
|
| 695 |
log.info(f'Re-bind as {subtree_user.dn} with new password') |
| 696 |
subtree_user.rebind('password0') |
| 697 |
|
| 698 |
edate = int(time.time() / (60 * 60 * 24)) |
| 699 |
|
| 700 |
log.info('Verify shadowLastChange is now set to today after password change') |
| 701 |
check_shadow_attr_value(inst, subtree_user.dn, |
| 702 |
'shadowLastChange', edate) |
| 703 |
check_shadow_attr_value(inst, subtree_user.dn, |
| 704 |
'shadowMin', 4) |
| 705 |
check_shadow_attr_value(inst, subtree_user.dn, |
| 706 |
'shadowMax', 40) |
| 707 |
check_shadow_attr_value(inst, subtree_user.dn, |
| 708 |
'shadowWarning', 12) |
| 709 |
|
| 710 |
|
| 711 |
@pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented") |
| 712 |
def test_shadowaccount_user_policy(topology_st, request): |
| 713 |
"""Check shadowAccount with user level password policy |
| 714 |
|
| 715 |
:id: d4e5f6a7-8b9c-0123-def0-456789012345 |
| 716 |
:setup: Standalone instance |
| 717 |
:steps: |
| 718 |
1. Create a new shadowAccount user |
| 719 |
2. Create user password policy |
| 720 |
3. Verify shadowAccount attributes match policy values |
| 721 |
4. Modify user password policy |
| 722 |
5. Change user password |
| 723 |
6. Re-bind with new password |
| 724 |
7. Check shadowAccount attributes are updated |
| 725 |
8. Clean up user password policy |
| 726 |
:expectedresults: |
| 727 |
1. User is created successfully |
| 728 |
2. User password policy is created successfully |
| 729 |
3. shadowAccount attributes match policy values |
| 730 |
4. Password policy is modified successfully |
| 731 |
5. Password is changed successfully |
| 732 |
6. Re-bind with new password is successful |
| 733 |
7. shadowAccount attributes are updated to match new policy values |
| 734 |
8. User password policy is deleted successfully |
| 735 |
""" |
| 736 |
inst = topology_st.standalone |
| 737 |
|
| 738 |
log.info('Create a new shadowAccount user for user policy test') |
| 739 |
users = UserAccounts(inst, DEFAULT_SUFFIX) |
| 740 |
user_policy_user = users.create(properties={ |
| 741 |
'objectclass': ['top', 'person', 'organizationalPerson', |
| 742 |
'inetOrgPerson', 'extensibleObject', 'shadowAccount'], |
| 743 |
'sn': '4', |
| 744 |
'cn': 'userPolicyUser', |
| 745 |
'uid': 'userPolicyUser', |
| 746 |
'uidNumber': '4', |
| 747 |
'gidNumber': '44', |
| 748 |
'homeDirectory': '/home/userPolicyUser', |
| 749 |
'displayName': 'User Policy User', |
| 750 |
'givenname': 'UserPolicy', |
| 751 |
'mail': f'userpolicyuser@{DEFAULT_SUFFIX}', |
| 752 |
'userpassword': 'password' |
| 753 |
}) |
| 754 |
|
| 755 |
pwp_mgr = PwPolicyManager(inst) |
| 756 |
|
| 757 |
def fin(): |
| 758 |
log.info('Clean up: delete user password policy and user') |
| 759 |
dm = DirectoryManager(inst) |
| 760 |
dm.rebind() |
| 761 |
try: |
| 762 |
pwp_mgr.delete_local_policy(user_policy_user.dn) |
| 763 |
except Exception: |
| 764 |
pass |
| 765 |
try: |
| 766 |
user_policy_user.delete() |
| 767 |
except Exception: |
| 768 |
pass |
| 769 |
request.addfinalizer(fin) |
| 770 |
|
| 771 |
log.info('Configure user password policy') |
| 772 |
properties = { |
| 773 |
'passwordExp': 'on', |
| 774 |
'passwordMinAge': str(days_to_secs(2)), |
| 775 |
'passwordMaxAge': str(days_to_secs(20)), |
| 776 |
'passwordWarning': str(days_to_secs(6)), |
| 777 |
'passwordChange': 'on', |
| 778 |
'passwordStorageScheme': 'clear' |
| 779 |
} |
| 780 |
setup_pwp(inst, pwp_mgr, 'user', dn=user_policy_user.dn, policy_props=properties) |
| 781 |
|
| 782 |
edate = int(time.time() / (60 * 60 * 24)) |
| 783 |
|
| 784 |
dm = DirectoryManager(inst) |
| 785 |
dm.rebind() |
| 786 |
|
| 787 |
log.info('Verify shadowAccount attributes match user policy') |
| 788 |
check_shadow_attr_value(inst, user_policy_user.dn, |
| 789 |
'shadowLastChange', edate) |
| 790 |
check_shadow_attr_value(inst, user_policy_user.dn, |
| 791 |
'shadowMin', 2) |
| 792 |
check_shadow_attr_value(inst, user_policy_user.dn, |
| 793 |
'shadowMax', 20) |
| 794 |
check_shadow_attr_value(inst, user_policy_user.dn, |
| 795 |
'shadowWarning', 6) |
| 796 |
|
| 797 |
log.info('Modify user password policy') |
| 798 |
modify_properties = { |
| 799 |
'passwordMinAge': str(days_to_secs(4)), |
| 800 |
'passwordMaxAge': str(days_to_secs(40)), |
| 801 |
'passwordWarning': str(days_to_secs(12)) |
| 802 |
} |
| 803 |
modify_pwp(inst, pwp_mgr, 'user', dn=user_policy_user.dn, policy_props=modify_properties) |
| 804 |
|
| 805 |
log.info(f'Change {user_policy_user.dn} password as the user') |
| 806 |
user_policy_user.rebind('password') |
| 807 |
user_policy_user.replace('userpassword', 'password0') |
| 808 |
time.sleep(1) |
| 809 |
|
| 810 |
log.info(f'Re-bind as {user_policy_user.dn} with new password') |
| 811 |
user_policy_user.rebind('password0') |
| 812 |
|
| 813 |
edate = int(time.time() / (60 * 60 * 24)) |
| 814 |
|
| 815 |
log.info('Verify shadowAccount attributes are updated after password change') |
| 816 |
check_shadow_attr_value(inst, user_policy_user.dn, |
| 817 |
'shadowLastChange', edate) |
| 818 |
check_shadow_attr_value(inst, user_policy_user.dn, |
| 819 |
'shadowMin', 4) |
| 820 |
check_shadow_attr_value(inst, user_policy_user.dn, |
| 821 |
'shadowMax', 40) |
| 822 |
check_shadow_attr_value(inst, user_policy_user.dn, |
| 823 |
'shadowWarning', 12) |
| 824 |
|
| 825 |
|
| 826 |
@pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented") |
| 827 |
def test_fixup_shadow_attributes_task(topology_st, request): |
| 828 |
"""fixup shadow attributes task: missing shadowLastChange, consistent entries, |
| 829 |
stale shadow vs passwordExpirationTime (no force), and force when expiration is absent |
| 830 |
|
| 831 |
:id: e7f8a9b0-1c2d-3e4f-5678-90abcdef0124 |
| 832 |
:setup: Standalone instance |
| 833 |
:steps: |
| 834 |
1. Enable passwordMustChange, passwordExp, and passwordMaxAge in cn=config |
| 835 |
2. Create ShadowAccount entry A before password policy is configured |
| 836 |
3. Create ShadowAccount entries B and C after passwordpolicy is set |
| 837 |
4. As entry B, change password; as Directory Manager, set entry C password |
| 838 |
(so C has passwordExpirationTime in the NO_TIME skip case) |
| 839 |
5. Ensure entry A has no shadowLastChange (remove if the server added one) |
| 840 |
6. Record shadowLastChange for entries B and C |
| 841 |
7. Run fixup shadow attributes task with suffix only (no force) |
| 842 |
8. Wait for task completion |
| 843 |
9. Verify entry A has shadowLastChange; B and C unchanged from step 6 |
| 844 |
10. Set entry C passwordExpirationtime and shadowLastChange to inconsistent (stale) values |
| 845 |
11. Run fixup shadow attributes task without force (suffix only) |
| 846 |
12. Wait for task completion |
| 847 |
13. Verify entry C shadowLastChange is recomputed from expiration and policy (not step 6) |
| 848 |
14. Remove entry B passwordExpirationtime and set B shadowLastChange to a stale value |
| 849 |
15. Run fixup shadow attributes task with force on |
| 850 |
16. Wait for task completion |
| 851 |
17. Verify entry B shadowLastChange updates (force required when passwordExpirationTime is absent) |
| 852 |
:expectedresults: |
| 853 |
1. Success |
| 854 |
2. Success |
| 855 |
3. Success |
| 856 |
4. Success |
| 857 |
5. Success |
| 858 |
6. Success |
| 859 |
7. Success |
| 860 |
8. Success |
| 861 |
9. Entry A gains shadowLastChange; B and C unchanged from step 6 (C skipped for NO_TIME) |
| 862 |
10. Success |
| 863 |
11. Success |
| 864 |
12. Success |
| 865 |
13. Entry C shadowLastChange updates for stale shadow vs expiration without force |
| 866 |
14. Success |
| 867 |
15. Success |
| 868 |
16. Success |
| 869 |
17. Entry B shadowLastChange updates because force bypasses skip when expiration is missing |
| 870 |
""" |
| 871 |
inst = topology_st.standalone |
| 872 |
|
| 873 |
MAX_AGE = "100000" |
| 874 |
EXP_TIME = "20250507185841Z" |
| 875 |
|
| 876 |
log.info('Create ShadowAccount entry A before password policy is configured') |
| 877 |
users = UserAccounts(inst, DEFAULT_SUFFIX) |
| 878 |
user_a = users.create(properties={ |
| 879 |
'objectclass': ['top', 'person', 'organizationalPerson', |
| 880 |
'inetOrgPerson', 'extensibleObject', 'shadowAccount'], |
| 881 |
'sn': 'Fa', |
| 882 |
'cn': 'shadowFa', |
| 883 |
'uid': 'shadowFa', |
| 884 |
'uidNumber': '7101', |
| 885 |
'gidNumber': '7101', |
| 886 |
'homeDirectory': '/home/shadowFa', |
| 887 |
'displayName': 'Shadow fixup A', |
| 888 |
'givenname': 'ShadowFa', |
| 889 |
'mail': '[email protected]', |
| 890 |
'userpassword': 'password', |
| 891 |
}) |
| 892 |
|
| 893 |
log.info('Enable passwordMustChange in cn=config') |
| 894 |
inst.config.replace('passwordMustChange', 'on') |
| 895 |
inst.config.replace('passwordExp', 'on') |
| 896 |
inst.config.replace('passwordMaxAge', MAX_AGE) |
| 897 |
|
| 898 |
log.info('Create ShadowAccount entry B after password policy is configured') |
| 899 |
user_b = users.create(properties={ |
| 900 |
'objectclass': ['top', 'person', 'organizationalPerson', |
| 901 |
'inetOrgPerson', 'extensibleObject', 'shadowAccount'], |
| 902 |
'sn': 'Fb', |
| 903 |
'cn': 'shadowFb', |
| 904 |
'uid': 'shadowFb', |
| 905 |
'uidNumber': '7102', |
| 906 |
'gidNumber': '7102', |
| 907 |
'homeDirectory': '/home/shadowFb', |
| 908 |
'displayName': 'Shadow fixup B', |
| 909 |
'givenname': 'ShadowFb', |
| 910 |
'mail': '[email protected]', |
| 911 |
'userpassword': 'password', |
| 912 |
}) |
| 913 |
|
| 914 |
log.info('Create ShadowAccount entry C') |
| 915 |
user_c = users.create(properties={ |
| 916 |
'objectclass': ['top', 'person', 'organizationalPerson', |
| 917 |
'inetOrgPerson', 'extensibleObject', 'shadowAccount'], |
| 918 |
'sn': 'Fc', |
| 919 |
'cn': 'shadowFc', |
| 920 |
'uid': 'shadowFc', |
| 921 |
'uidNumber': '7102', |
| 922 |
'gidNumber': '7102', |
| 923 |
'homeDirectory': '/home/shadowFc', |
| 924 |
'displayName': 'Shadow fixup B', |
| 925 |
'givenname': 'ShadowFc', |
| 926 |
'mail': '[email protected]', |
| 927 |
'userpassword': 'password', |
| 928 |
}) |
| 929 |
|
| 930 |
def fin(): |
| 931 |
log.info('Cleanup: disable passwordMustChange; delete test users') |
| 932 |
dm = DirectoryManager(inst) |
| 933 |
dm.rebind() |
| 934 |
try: |
| 935 |
inst.config.replace('passwordMustChange', 'off') |
| 936 |
inst.config.replace('passwordExp', 'off') |
| 937 |
except Exception: |
| 938 |
pass |
| 939 |
for u in (user_a, user_b, user_c): |
| 940 |
try: |
| 941 |
if u.exists(): |
| 942 |
u.delete() |
| 943 |
except Exception: |
| 944 |
pass |
| 945 |
|
| 946 |
request.addfinalizer(fin) |
| 947 |
|
| 948 |
# Update user B password so it has a current expiration time and not the |
| 949 |
# "reset" value |
| 950 |
user_b.rebind('password') |
| 951 |
user_b.replace('userpassword', 'password0') # Trigger valid exp time |
| 952 |
|
| 953 |
dm = DirectoryManager(inst) |
| 954 |
dm.rebind(PASSWORD) |
| 955 |
user_c.replace('userpassword', 'password0') # Trigger NO_TIME |
| 956 |
|
| 957 |
# Gather the current values for ShadowLastChange |
| 958 |
if user_a.present('shadowLastChange'): |
| 959 |
log.info('Removing shadowLastChange from entry A so the non-forced fixup updates it') |
| 960 |
user_a.remove_all('shadowLastChange') |
| 961 |
|
| 962 |
assert user_b.present('shadowLastChange'), 'Entry B should have shadowLastChange before fixup' |
| 963 |
b_before = int(user_b.get_attr_val_utf8('shadowLastChange')) |
| 964 |
log.info('Entry B shadowLastChange before tasks: {}'.format(b_before)) |
| 965 |
|
| 966 |
c_before = int(user_c.get_attr_val_utf8('shadowLastChange')) |
| 967 |
log.info('Entry C shadowLastChange before tasks: {}'.format(c_before)) |
| 968 |
|
| 969 |
# |
| 970 |
# Run the task (suffix only, no force) |
| 971 |
# |
| 972 |
log.info('Run fixup shadow attributes task (suffix only, no force)') |
| 973 |
shadow_fixup_task = ShadowFixupTask(inst) |
| 974 |
shadow_fixup_task.create(suffix=DEFAULT_SUFFIX, force=False) |
| 975 |
shadow_fixup_task.wait(timeout=120) |
| 976 |
assert shadow_fixup_task.get_exit_code() == 0 |
| 977 |
|
| 978 |
# User A should now have ShadowLastChange |
| 979 |
assert user_a.present('shadowLastChange'), 'Entry A should gain shadowLastChange' |
| 980 |
a_after_first = int(user_a.get_attr_val_utf8('shadowLastChange')) |
| 981 |
log.info('Entry A shadowLastChange after first task: {}'.format(a_after_first)) |
| 982 |
|
| 983 |
# User B should be the same since it has the correct values for |
| 984 |
# ShadowLastChange and passwordExpirationtime |
| 985 |
b_after_first = int(user_b.get_attr_val_utf8('shadowLastChange')) |
| 986 |
assert b_after_first == b_before, ( |
| 987 |
'Entry B shadowLastChange should be unchanged without force; ' |
| 988 |
'got {} expected {}'.format(b_after_first, b_before)) |
| 989 |
|
| 990 |
# User C should remain unchanged because passwordExpiration is set to NO_TIME |
| 991 |
c_after_first = int(user_c.get_attr_val_utf8('shadowLastChange')) |
| 992 |
assert c_after_first == c_before, ( |
| 993 |
'Entry C shadowLastChange should be unchanged without force; ' |
| 994 |
'got {} expected {}'.format(c_after_first, c_before)) |
| 995 |
|
| 996 |
# |
| 997 |
# Run the fixup after tweaking passwordExpirationtime |
| 998 |
# |
| 999 |
# Update user C passwordExpirationtime to a "stale" value which should |
| 1000 |
# trigger shadowLastChange to be updated |
| 1001 |
user_c.replace('passwordExpirationtime', EXP_TIME) |
| 1002 |
user_c.replace('shadowLastChange', '20000') |
| 1003 |
c_before = '20000' |
| 1004 |
log.info('Run fixup shadow attributes task (suffix only, no force; stale reconciliation)') |
| 1005 |
shadow_fixup_task = ShadowFixupTask(inst) |
| 1006 |
shadow_fixup_task.create(suffix=DEFAULT_SUFFIX, force=False) |
| 1007 |
shadow_fixup_task.wait(timeout=120) |
| 1008 |
assert shadow_fixup_task.get_exit_code() == 0 |
| 1009 |
|
| 1010 |
# User C should have ShadowLastChange updated to the current day |
| 1011 |
c_after_first = int(user_c.get_attr_val_utf8('shadowLastChange')) |
| 1012 |
exp_time = gentime_to_posix_time(EXP_TIME) |
| 1013 |
expected_val = int((exp_time - int(MAX_AGE)) / 86400) |
| 1014 |
assert c_after_first != int(c_before) and c_after_first == expected_val, ( |
| 1015 |
'Entry C shadowLastChange should be changed without force; ' |
| 1016 |
'got {} expected {}'.format(c_after_first, c_before)) |
| 1017 |
|
| 1018 |
# |
| 1019 |
# Run the fixup in force option |
| 1020 |
# |
| 1021 |
log.info('Run fixup shadow attributes task with force on') |
| 1022 |
# Update user B so that it would normally not be "fixed-up" |
| 1023 |
user_b.remove_all('passwordExpirationtime') |
| 1024 |
user_b.replace('shadowLastChange', '20000') |
| 1025 |
|
| 1026 |
shadow_fixup_task = ShadowFixupTask(inst) |
| 1027 |
shadow_fixup_task.create(suffix=DEFAULT_SUFFIX, force=True) |
| 1028 |
shadow_fixup_task.wait(timeout=120) |
| 1029 |
assert shadow_fixup_task.get_exit_code() == 0 |
| 1030 |
|
| 1031 |
assert user_b.present('shadowLastChange') |
| 1032 |
b_after_force = int(user_b.get_attr_val_utf8('shadowLastChange')) |
| 1033 |
assert b_after_force != 20000, ( |
| 1034 |
'Entry B shadowLastChange should change when force is on; ' |
| 1035 |
'still {}'.format(b_after_force)) |
| 1036 |
|
| 1037 |
|
| 1038 |
if __name__ == '__main__': |
| 1039 |
# Run isolated |
| 1040 |
# -s for DEBUG mode |
| 1041 |
CURRENT_FILE = os.path.realpath(__file__) |
| 1042 |
pytest.main("-s %s" % CURRENT_FILE) |