Debian Codegraph @

dirsrvtests/tests/suites/password/regression_test.py

raw
1 # Copyright (C) 2017 Red Hat, Inc.
2 # All rights reserved.
3 #
4 # License: GPL (version 3 or any later version).
5 # See LICENSE for details.
6 # --- END COPYRIGHT BLOCK ---
7 #
8 import pytest
9 import time
10 import glob
11 import base64
12 from lib389._constants import PASSWORD, DN_DM, DEFAULT_SUFFIX
13 from lib389._constants import SUFFIX, PASSWORD, DN_DM, DN_CONFIG, PLUGIN_RETRO_CHANGELOG, DEFAULT_SUFFIX, DEFAULT_CHANGELOG_DB, DEFAULT_BENAME
14 from lib389 import Entry
15 from test389.topologies import topology_m1 as topo_supplier
16 from lib389.idm.user import UserAccounts, UserAccount
17 from lib389.utils import ldap, os, logging, ensure_bytes, ds_is_newer, ds_supports_new_changelog
18 from test389.topologies import topology_st as topo
19 from lib389.idm.organizationalunit import OrganizationalUnits
20 from lib389.pwpolicy import PwPolicyManager
21 from lib389.backend import Backend, Backends
22 from lib389.configurations.sample import create_base_org
23
24 pytestmark = pytest.mark.tier1
25
26 DEBUGGING = os.getenv("DEBUGGING", default=False)
27 if DEBUGGING:
28 logging.getLogger(__name__).setLevel(logging.DEBUG)
29 else:
30 logging.getLogger(__name__).setLevel(logging.INFO)
31 log = logging.getLogger(__name__)
32
33 user_data = {'cn': 'CNpwtest1', 'sn': 'SNpwtest1', 'uid': 'UIDpwtest1', 'mail': '[email protected]',
34 'givenname': 'GNpwtest1'}
35
36 TEST_PASSWORDS = list(user_data.values())
37 # Add substring/token values of "CNpwtest1"
38 TEST_PASSWORDS += ['CNpwtest1ZZZZ', 'ZZZZZCNpwtest1',
39 'ZCNpwtest1', 'CNpwtest1Z', 'ZCNpwtest1Z',
40 'ZZCNpwtest1', 'CNpwtest1ZZ', 'ZZCNpwtest1ZZ',
41 'ZZZCNpwtest1', 'CNpwtest1ZZZ', 'ZZZCNpwtest1ZZZ',
42 'ZZZZZZCNpwtest1ZZZZZZZZ']
43
44 TEST_PASSWORDS2 = (
45 'CN12pwtest31', 'SN3pwtest231', 'UID1pwtest123', '[email protected]', '2GN1pwtest123', 'People123')
46
47 SUPPORTED_SCHEMES = (
48 "{SHA}", "{SSHA}", "{SHA256}", "{SSHA256}",
49 "{SHA384}", "{SSHA384}", "{SHA512}", "{SSHA512}",
50 "{crypt}", "{NS-MTA-MD5}", "{clear}", "{MD5}",
51 "{SMD5}", "{PBKDF2_SHA256}", "{PBKDF2_SHA512}",
52 "{GOST_YESCRYPT}", "{PBKDF2-SHA256}", "{PBKDF2-SHA512}" )
53
54 def _check_unhashed_userpw(inst, user_dn, is_present=False):
55 """Check if unhashed#user#password attribute is present or not in the changelog"""
56 unhashed_pwd_attribute = 'unhashed#user#password'
57
58 if ds_supports_new_changelog():
59 dbscanOut = inst.dbscan(DEFAULT_BENAME, 'replication_changelog')
60 else:
61 changelog_dbdir = os.path.join(os.path.dirname(inst.dbdir), DEFAULT_CHANGELOG_DB)
62 for changelog_dbfile in glob.glob(f'{changelog_dbdir}*/*.db*'):
63 log.info('Changelog dbfile file exist: {}'.format(changelog_dbfile))
64 dbscanOut = inst.dbscan(DEFAULT_CHANGELOG_DB, changelog_dbfile)
65
66 for entry in dbscanOut.split(b'dbid: '):
67 if ensure_bytes('operation: modify') in entry and ensure_bytes(user_dn) in entry and ensure_bytes('userPassword') in entry:
68 if is_present:
69 assert ensure_bytes(unhashed_pwd_attribute) in entry
70 else:
71 assert ensure_bytes(unhashed_pwd_attribute) not in entry
72
73 @pytest.fixture(scope="function")
74 def passw_policy(topo, request):
75 """Configure password policy with PasswordCheckSyntax attribute set to on"""
76
77 log.info('Configure Pwpolicy with PasswordCheckSyntax and nsslapd-pwpolicy-local set to on')
78 topo.standalone.simple_bind_s(DN_DM, PASSWORD)
79 topo.standalone.config.set('PasswordExp', 'on')
80 topo.standalone.config.set('PasswordCheckSyntax', 'off')
81 topo.standalone.config.set('nsslapd-pwpolicy-local', 'on')
82
83 subtree = 'ou=people,{}'.format(DEFAULT_SUFFIX)
84 log.info('Configure subtree password policy for {}'.format(subtree))
85 pwp = PwPolicyManager(topo.standalone)
86 pwp.create_subtree_policy(subtree, {'passwordchange': 'on',
87 'passwordCheckSyntax': 'on',
88 'passwordLockout': 'on',
89 'passwordResetFailureCount': '3',
90 'passwordLockoutDuration': '3',
91 'passwordMaxFailure': '2'})
92 time.sleep(1)
93
94 def fin():
95 log.info('Reset pwpolicy configuration settings')
96 topo.standalone.simple_bind_s(DN_DM, PASSWORD)
97 pwp.delete_local_policy(subtree)
98 topo.standalone.config.set('PasswordExp', 'off')
99 topo.standalone.config.set('PasswordCheckSyntax', 'off')
100 topo.standalone.config.set('nsslapd-pwpolicy-local', 'off')
101
102 request.addfinalizer(fin)
103
104
105 @pytest.fixture(scope="module")
106 def create_user(topo, request):
107 """Add test users using UserAccounts"""
108
109 log.info('Adding user-uid={},ou=people,{}'.format(user_data['uid'], DEFAULT_SUFFIX))
110 users = UserAccounts(topo.standalone, DEFAULT_SUFFIX)
111 user_properties = {
112 'uidNumber': '1001',
113 'gidNumber': '2001',
114 'cn': 'pwtest1',
115 'userpassword': PASSWORD,
116 'homeDirectory': '/home/pwtest1'}
117 user_properties.update(user_data)
118 tuser = users.create(properties=user_properties)
119
120 def fin():
121 log.info('Deleting user-{}'.format(tuser.dn))
122 tuser.delete()
123
124 request.addfinalizer(fin)
125 return tuser
126
127
128 def test_pwp_local_unlock(topo, passw_policy, create_user):
129 """Test subtree policies use the same global default for passwordUnlock
130
131 :id: 741a8417-5f65-4012-b9ed-87987ce3ca1b
132 :setup: Standalone instance
133 :steps:
134 1. Test user can bind
135 2. Bind with bad passwords to lockout account, and verify account is locked
136 3. Wait for lockout interval, and bind with valid password
137 :expectedresults:
138 1. Bind successful
139 2. Entry is locked
140 3. Entry can bind with correct password
141 """
142 # Add aci so users can change their own password
143 USER_ACI = '(targetattr="userpassword")(version 3.0; acl "pwp test"; allow (all) userdn="ldap:///self";)'
144 ous = OrganizationalUnits(topo.standalone, DEFAULT_SUFFIX)
145 ou = ous.get('people')
146 ou.add('aci', USER_ACI)
147
148 log.info("Verify user can bind...")
149 create_user.bind(PASSWORD)
150
151 log.info('Test passwordUnlock default - user should be able to reset password after lockout')
152 for i in range(0, 2):
153 try:
154 create_user.bind("bad-password")
155 except ldap.INVALID_CREDENTIALS:
156 # expected
157 pass
158 except ldap.LDAPError as e:
159 log.fatal("Got unexpected failure: " + str(e))
160 raise e
161
162 log.info('Verify account is locked')
163 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
164 create_user.bind(PASSWORD)
165
166 log.info('Wait for lockout duration...')
167 time.sleep(4)
168
169 log.info('Check if user can now bind with correct password')
170 create_user.bind(PASSWORD)
171
172
173 @pytest.mark.parametrize("user_pasw", TEST_PASSWORDS)
174 def test_trivial_passw_check(topo, passw_policy, create_user, user_pasw):
175 """PasswordCheckSyntax attribute fails to validate cn, sn, uid, givenname, ou and mail attributes
176
177 :id: bf9fe1ef-56cb-46a3-a6f8-5530398a06dc
178 :parametrized: yes
179 :setup: Standalone instance.
180 :steps:
181 1. Configure local password policy with PasswordCheckSyntax set to on.
182 2. Add users with cn, sn, uid, givenname, mail and userPassword attributes.
183 3. Configure subtree password policy for ou=people subtree.
184 4. Reset userPassword with trivial values like cn, sn, uid, givenname, ou and mail attributes.
185 :expectedresults:
186 1. Enabling PasswordCheckSyntax should PASS.
187 2. Add users should PASS.
188 3. Configure subtree password policy should PASS.
189 4. Resetting userPassword to cn, sn, uid and mail should be rejected.
190 """
191
192 create_user.rebind(PASSWORD)
193 log.info('Replace userPassword attribute with {}'.format(user_pasw))
194 with pytest.raises(ldap.CONSTRAINT_VIOLATION) as excinfo:
195 create_user.reset_password(user_pasw)
196 log.fatal('Failed: Userpassword with {} is accepted'.format(user_pasw))
197 assert 'password based off of user entry' in str(excinfo.value)
198
199 # reset password
200 topo.standalone.simple_bind_s(DN_DM, PASSWORD)
201 create_user.set('userPassword', PASSWORD)
202
203
204 @pytest.mark.parametrize("user_pasw", TEST_PASSWORDS)
205 def test_global_vs_local(topo, passw_policy, create_user, user_pasw):
206 """Passwords rejected if its similar to uid, cn, sn, givenname, ou and mail attributes
207
208 :id: dfd6cf5d-8bcd-4895-a691-a43ad9ec1be8
209 :parametrized: yes
210 :setup: Standalone instance
211 :steps:
212 1. Configure global password policy with PasswordCheckSyntax set to off
213 2. Add users with cn, sn, uid, mail, givenname and userPassword attributes
214 3. Replace userPassword similar to cn, sn, uid, givenname, ou and mail attributes
215 :expectedresults:
216 1. Disabling the local policy should PASS.
217 2. Add users should PASS.
218 3. Resetting userPasswords similar to cn, sn, uid, givenname, ou and mail attributes should PASS.
219 """
220
221 log.info('Configure Pwpolicy with PasswordCheckSyntax and nsslapd-pwpolicy-local set to off')
222 topo.standalone.simple_bind_s(DN_DM, PASSWORD)
223 topo.standalone.config.set('nsslapd-pwpolicy-local', 'off')
224
225 create_user.rebind(PASSWORD)
226 log.info('Replace userPassword attribute with {}'.format(user_pasw))
227 create_user.reset_password(user_pasw)
228
229 # reset password
230 create_user.set('userPassword', PASSWORD)
231
232 def test_unhashed_pw_switch(topo_supplier):
233 """Check that nsslapd-unhashed-pw-switch works corrently
234
235 :id: e5aba180-d174-424d-92b0-14fe7bb0b92a
236 :setup: Supplier Instance
237 :steps:
238 1. A Supplier is created, enable retrocl (not used here)
239 2. Create a set of users
240 3. update userpassword of user1 and check that unhashed#user#password is not logged (default)
241 4. udpate userpassword of user2 and check that unhashed#user#password is not logged ('nolog')
242 5. udpate userpassword of user3 and check that unhashed#user#password is logged ('on')
243 :expectedresults:
244 1. Success
245 2. Success
246 3. Success (unhashed#user#password is not logged in the replication changelog)
247 4. Success (unhashed#user#password is not logged in the replication changelog)
248 5. Success (unhashed#user#password is logged in the replication changelog)
249 """
250 MAX_USERS = 10
251 PEOPLE_DN = ("ou=people," + DEFAULT_SUFFIX)
252
253 inst = topo_supplier.ms["supplier1"]
254 inst.modify_s("cn=Retro Changelog Plugin,cn=plugins,cn=config",
255 [(ldap.MOD_REPLACE, 'nsslapd-changelogmaxage', b'2m'),
256 (ldap.MOD_REPLACE, 'nsslapd-changelog-trim-interval', b"5s"),
257 (ldap.MOD_REPLACE, 'nsslapd-logAccess', b'on')])
258 inst.config.loglevel(vals=[256 + 4], service='access')
259 inst.restart()
260 # If you need any test suite initialization,
261 # please, write additional fixture for that (including finalizer).
262 # Topology for suites are predefined in lib389/topologies.py.
263
264 # enable dynamic plugins, memberof and retro cl plugin
265 #
266 log.info('Enable plugins...')
267 try:
268 inst.modify_s(DN_CONFIG,
269 [(ldap.MOD_REPLACE,
270 'nsslapd-dynamic-plugins',
271 b'on')])
272 except ldap.LDAPError as e:
273 ldap.error('Failed to enable dynamic plugins! ' + e.message['desc'])
274 assert False
275
276 #topology_st.standalone.plugins.enable(name=PLUGIN_MEMBER_OF)
277 inst.plugins.enable(name=PLUGIN_RETRO_CHANGELOG)
278 #topology_st.standalone.modify_s("cn=changelog,cn=ldbm database,cn=plugins,cn=config", [(ldap.MOD_REPLACE, 'nsslapd-cachememsize', str(100000))])
279 inst.restart()
280
281 log.info('create users and group...')
282 for idx in range(1, MAX_USERS):
283 try:
284 USER_DN = ("uid=member%d,%s" % (idx, PEOPLE_DN))
285 inst.add_s(Entry((USER_DN,
286 {'objectclass': 'top extensibleObject'.split(),
287 'uid': 'member%d' % (idx)})))
288 except ldap.LDAPError as e:
289 log.fatal('Failed to add user (%s): error %s' % (USER_DN, e.message['desc']))
290 assert False
291
292 # Check default is that unhashed#user#password is not logged on 1.4.1.6+
293 user = "uid=member1,%s" % (PEOPLE_DN)
294 inst.modify_s(user, [(ldap.MOD_REPLACE,
295 'userpassword',
296 PASSWORD.encode())])
297 inst.stop()
298 if ds_is_newer('1.4.1.6'):
299 _check_unhashed_userpw(inst, user, is_present=False)
300 else:
301 _check_unhashed_userpw(inst, user, is_present=True)
302 inst.start()
303
304 # Check with nolog that unhashed#user#password is not logged
305 inst.modify_s(DN_CONFIG,
306 [(ldap.MOD_REPLACE,
307 'nsslapd-unhashed-pw-switch',
308 b'nolog')])
309 inst.restart()
310 user = "uid=member2,%s" % (PEOPLE_DN)
311 inst.modify_s(user, [(ldap.MOD_REPLACE,
312 'userpassword',
313 PASSWORD.encode())])
314 inst.stop()
315 _check_unhashed_userpw(inst, user, is_present=False)
316 inst.start()
317
318 # Check with value 'on' that unhashed#user#password is logged
319 inst.modify_s(DN_CONFIG,
320 [(ldap.MOD_REPLACE,
321 'nsslapd-unhashed-pw-switch',
322 b'on')])
323 inst.restart()
324 user = "uid=member3,%s" % (PEOPLE_DN)
325 inst.modify_s(user, [(ldap.MOD_REPLACE,
326 'userpassword',
327 PASSWORD.encode())])
328 inst.stop()
329 _check_unhashed_userpw(inst, user, is_present=True)
330
331 if DEBUGGING:
332 # Add debugging steps(if any)...
333 pass
334
335 @pytest.mark.parametrize("scheme", SUPPORTED_SCHEMES )
336 def test_long_hashed_password(topo, create_user, scheme):
337 """Check that hashed password with very long value does not cause trouble
338
339 :id: 252a1f76-114b-11ef-8a7a-482ae39447e5
340 :setup: standalone Instance
341 :parametrized: yes
342 :steps:
343 1. Add a test user user
344 2. Set a long password with requested scheme
345 3. Bind on that user using a wrong password
346 4. Check that instance is still alive
347 5. Remove the added user
348 :expectedresults:
349 1. Success
350 2. Success
351 3. Should get ldap.INVALID_CREDENTIALS exception
352 4. Success
353 5. Success
354 """
355 inst = topo.standalone
356 inst.simple_bind_s(DN_DM, PASSWORD)
357 users = UserAccounts(inst, DEFAULT_SUFFIX)
358 # Make sure that server is started as this test may crash it
359 inst.start()
360 # Adding Test user (It may already exists if previous test failed)
361 user2 = UserAccount(inst, dn='uid=test_user_1002,ou=People,dc=example,dc=com')
362 if not user2.exists():
363 user2 = users.create_test_user(uid=1002, gid=2002)
364 # Setting hashed password
365 passwd = 'A'*4000
366 hashed_passwd = scheme.encode('utf-8') + base64.b64encode(passwd.encode('utf-8'))
367 user2.replace('userpassword', hashed_passwd)
368 # Bind on that user using a wrong password
369 with pytest.raises(ldap.INVALID_CREDENTIALS):
370 conn = user2.bind(PASSWORD)
371 # Check that instance is still alive
372 assert inst.status()
373 # Remove the added user
374 user2.delete()
375
376
377 SECOND_SUFFIX_COS = b'o=netscaperoot'
378 BE_NAME_COS = 'netscaperoot'
379
380
381 def test_cos_vattr_cache_invalidation(topo, create_user):
382 """COS def changes must be reflected in users (vattr cache invalidation).
383
384 With multiple suffixes, if the last suffix checked has no COS entries, the vattr cache
385 may not be invalidated, so users could keep stale pwdpolicysubentry after delete/re-add
386 of policy. This test verifies the virtual attribute updates correctly.
387
388 :id: 8f4e2a1c-9b3d-4e6a-8c7f-1d2e3a4b5c6d
389 :setup: Standalone instance, create_user fixture (user under ou=People)
390 :steps:
391 1. Create a second suffix with no COS entries
392 2. Enable local pwpolicy and add subtree policy for ou=people via PwPolicyManager
393 3. Assert create_user has pwdpolicysubentry
394 4. Delete the subtree policy
395 5. Assert create_user no longer has pwdpolicysubentry
396 6. Re-add the subtree policy
397 7. Assert create_user has pwdpolicysubentry again
398 8. Cleanup: delete the subtree policy and second backend
399 :expectedresults:
400 1. Success
401 2. Success
402 3. Success
403 4. Success
404 5. Success
405 6. Success
406 7. Success
407 8. Success
408 """
409 inst = topo.standalone
410 people_dn = f'ou=people,{DEFAULT_SUFFIX}'
411
412
413 inst.simple_bind_s(DN_DM, PASSWORD)
414
415 # Create second suffix using lib389 Backend (backend + mapping tree) and suffix root entry.
416 # The Suffix class is for querying (list, toBackend, getParent); creation uses Backend + sample.
417 try:
418 be = Backend(inst)
419 be.create(properties={'cn': BE_NAME_COS, 'nsslapd-suffix': SECOND_SUFFIX_COS})
420 except ldap.ALREADY_EXISTS:
421 pass
422 try:
423 create_base_org(inst, SECOND_SUFFIX_COS)
424 except ldap.ALREADY_EXISTS:
425 pass
426 assert SECOND_SUFFIX_COS in inst.suffix.list(), 'Second suffix should be in suffix list'
427
428 # Set up subtree password policy
429 inst.config.set('nsslapd-pwpolicy-local', 'on')
430
431 pwp = PwPolicyManager(inst)
432 policy_props = {
433 'passwordMustChange': 'off',
434 'passwordExp': 'off',
435 'passwordHistory': 'off',
436 'passwordMinAge': '0',
437 'passwordChange': 'off',
438 'passwordStorageScheme': 'ssha',
439 }
440 pwp.create_subtree_policy(people_dn, policy_props)
441
442 # User must have pwdpolicysubentry
443 assert len(create_user.get_attr_vals_utf8('pwdpolicysubentry')) > 0, (
444 'User should have pwdpolicysubentry after adding policy'
445 )
446
447 # Delete subtree policy
448 pwp.delete_local_policy(people_dn)
449 time.sleep(0.5)
450
451 # User must no longer have pwdpolicysubentry
452 assert len(create_user.get_attr_vals_utf8('pwdpolicysubentry')) == 0, (
453 'User should not have pwdpolicysubentry after deleting policy'
454 )
455
456 # Re-add subtree policy
457 pwp.create_subtree_policy(people_dn, policy_props)
458 time.sleep(0.5)
459
460 # User must have pwdpolicysubentry again
461 assert len(create_user.get_attr_vals_utf8('pwdpolicysubentry')) > 0, (
462 'User should have pwdpolicysubentry after re-adding policy'
463 )
464
465 # Cleanup: remove subtree policy and second backend
466 pwp.delete_local_policy(people_dn)
467 inst.config.set('nsslapd-pwpolicy-local', 'off')
468 Backends(inst).get(SECOND_SUFFIX_COS.decode('utf-8')).delete()
469
470
471 def test_nested_cos_ordering(topo):
472 """Multiple nested COS pointer defs must apply correct policy per user.
473
474 The COS plugin sorts attribute indexes by subtree; each user must receive the
475 pwdpolicysubentry from their own (closest) branch. This test verifies ordering.
476
477 :id: c7d8e9f0-1a2b-4c5d-9e8f-7a6b5c4d3e2f
478 :setup: Standalone instance
479 :steps:
480 1. Create six nested OUs
481 2. Create one user in each branch
482 3. Enable local pwpolicy and add a subtree policy per branch
483 4. For each user, assert pwdpolicysubentry equals the policy DN for that user's branch
484 5. Cleanup: remove created users and policies
485 :expectedresults:
486 1. Success
487 2. Success
488 3. Success
489 4. Success
490 5. Success
491 """
492 inst = topo.standalone
493 inst.simple_bind_s(DN_DM, PASSWORD)
494
495 branch1 = 'ou=level1,' + DEFAULT_SUFFIX
496 branch2 = 'ou=level2,' + branch1
497 branch3 = 'ou=level3,' + branch2
498 branch4 = 'ou=people,' + DEFAULT_SUFFIX
499 branch5 = 'ou=lower,' + branch4
500 branch6 = 'ou=lower,' + branch5
501
502 # Define nested branches: (branch_dn, ou_rdn_value) for creation order
503 branches = [branch1, branch2, branch3, branch4, branch5, branch6]
504 user_rdns = ['user1', 'user2', 'user3', 'user4', 'user5', 'user6']
505 policy_props = {
506 'passwordMustChange': 'off',
507 'passwordExp': 'off',
508 'passwordHistory': 'off',
509 'passwordMinAge': '0',
510 'passwordChange': 'off',
511 'passwordStorageScheme': 'ssha',
512 }
513
514 # Create branch OUs using lib389 (parent before children)
515 ous_top = OrganizationalUnits(inst, DEFAULT_SUFFIX)
516 ous_top.ensure_state(rdn='ou=level1', properties={'ou': 'level1'})
517 OrganizationalUnits(inst, branch1).ensure_state(rdn='ou=level2', properties={'ou': 'level2'})
518 OrganizationalUnits(inst, branch2).ensure_state(rdn='ou=level3', properties={'ou': 'level3'})
519 ous_top.ensure_state(rdn='ou=people', properties={'ou': 'people'})
520 OrganizationalUnits(inst, branch4).ensure_state(rdn='ou=lower', properties={'ou': 'lower'})
521 OrganizationalUnits(inst, branch5).ensure_state(rdn='ou=lower', properties={'ou': 'lower'})
522
523 # Create users in each branch using lib389 UserAccounts
524 user_dns = []
525 for i, branch_dn in enumerate(branches):
526 users = UserAccounts(inst, branch_dn, rdn=None)
527 user_props = {
528 'uid': user_rdns[i],
529 'cn': user_rdns[i],
530 'sn': user_rdns[i],
531 'uidNumber': str(1000 + i),
532 'gidNumber': '2000',
533 'homeDirectory': f'/home/{user_rdns[i]}',
534 }
535 users.ensure_state(rdn=f'uid={user_rdns[i]}', properties=user_props)
536 user_dns.append(f'uid={user_rdns[i]},{branch_dn}')
537
538 inst.config.set('nsslapd-pwpolicy-local', 'on')
539 time.sleep(0.5)
540
541 # Add subtree policies
542 pwp = PwPolicyManager(inst)
543 expected_policy_dns = []
544 for branch_dn in branches:
545 pwp_entry = pwp.create_subtree_policy(branch_dn, policy_props)
546 expected_policy_dns.append(pwp_entry.get_attr_val_utf8('dsEntryDN'))
547
548 time.sleep(1)
549
550 # Each user must have the policy DN for their branch (via COS pwdpolicysubentry).
551 # Read via UserAccount and assert the attribute value.
552 for i, user_dn in enumerate(user_dns):
553 user = UserAccount(inst, user_dn)
554 actual_policy = user.get_attr_val_utf8('pwdpolicysubentry')
555 assert actual_policy == expected_policy_dns[i], (
556 f'User {user_dn} should have pwdpolicysubentry {expected_policy_dns[i]}, got {actual_policy}'
557 )
558
559 # Cleanup: remove created users and policies
560 for user_dn in user_dns:
561 user = UserAccount(inst, user_dn)
562 user.delete()
563 for branch in branches:
564 pwp.delete_local_policy(branch)
565 inst.config.set('nsslapd-pwpolicy-local', 'off')
566
567
568 if __name__ == '__main__':
569 # Run isolated
570 # -s for DEBUG mode
571 CURRENT_FILE = os.path.realpath(__file__)
572 pytest.main(["-s", CURRENT_FILE])