Debian Codegraph @

dirsrvtests/tests/suites/password/password_policy_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2020 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 """
10 This test script will test password policy.
11 """
12
13 import os
14 import pytest
15 import time
16 from lib389.backend import Backend
17 from lib389.config import Config
18 from lib389.cli_conf.pwpolicy import list_policies, create_subtree_policy, create_user_policy, del_local_policy
19 from lib389.cli_base import FakeArgs
20 from test389.topologies import topology_st as topo
21 from test389.topologies import topology_m1
22 from lib389.idm.domain import Domain
23 from lib389.idm.organizationalunit import OrganizationalUnits
24 from lib389.idm.user import UserAccounts, UserAccount
25 from lib389._constants import DEFAULT_SUFFIX
26 from lib389.pwpolicy import PwPolicyManager, PwPolicyEntries
27 from lib389.idm.account import Account
28 from lib389.idm.nscontainer import nsContainers, nsContainer
29 from lib389.cos import CosPointerDefinitions, CosTemplates
30 import ldap
31
32
33 pytestmark = pytest.mark.tier1
34
35
36 def create_user(inst, uid, cn, sn, givenname, userpasseord, gid, ou):
37 """
38 Will create user
39 """
40 user = UserAccounts(inst, DEFAULT_SUFFIX, rdn=ou).create(properties={
41 'uid': uid,
42 'cn': cn,
43 'sn': sn,
44 'givenname': givenname,
45 'mail': f'{uid}@example.com',
46 'userpassword': userpasseord,
47 'homeDirectory': f'/home/{uid}',
48 'uidNumber': gid,
49 'gidNumber': gid
50 })
51 return user
52
53
54 def create_subtree_policy_custom(instance, dn, properties):
55 """Creates all entries which are needed for the subtree
56 password policy
57
58 :param dn: Entry DN for the subtree pwpolicy
59 :type dn: str
60 :param properties: A dict with password policy settings
61 :type properties: dict
62
63 :returns: PwPolicyEntry instance
64 """
65
66 # Verify target dn exists before getting started
67 subtree_entry = Account(instance, dn)
68 if not subtree_entry.exists():
69 raise ValueError('Can not create subtree password policy because the target dn does not exist')
70
71 # Create the pwp container if needed
72 pwp_containers = nsContainers(instance, basedn=dn)
73 pwp_container = pwp_containers.ensure_state(properties={'cn': 'nsPwPolicyContainer'})
74
75 # Create policy entry
76 pwp_entry = None
77 properties['cn'] = '"cn=nsPwPolicyEntry_subtree,%s"' % dn
78 pwp_entries = PwPolicyEntries(instance, pwp_container.dn)
79 pwp_entry = pwp_entries.create(properties=properties)
80 try:
81 # The CoS template entry (nsPwTemplateEntry) that has the pwdpolicysubentry
82 # value pointing to the above (nsPwPolicyEntry) entry
83 cos_template = None
84 cos_templates = CosTemplates(instance, pwp_container.dn)
85 cos_template = cos_templates.create(properties={'cosPriority': '1',
86 'pwdpolicysubentry': pwp_entry.dn,
87 'cn': 'cn=nsPwTemplateEntry,%s' % dn})
88
89 # The CoS specification entry at the subtree level
90 cos_pointer_defs = CosPointerDefinitions(instance, dn)
91 cos_pointer_defs.create(properties={'cosAttribute': 'pwdpolicysubentry default operational-default',
92 'cosTemplateDn': cos_template.dn,
93 'cn': 'nsPwPolicy_CoS'})
94 except ldap.LDAPError as e:
95 # Something went wrong, remove what we have done
96 if pwp_entry is not None:
97 pwp_entry.delete()
98 if cos_template is not None:
99 cos_template.delete()
100 raise e
101
102 # make sure that local policies are enabled
103 config = Config(instance)
104 config.replace('nsslapd-pwpolicy-local', 'on')
105
106 return pwp_entry
107
108
109 @pytest.fixture(scope="function")
110 def policy_qoutes_setup(topology_m1, request):
111 inst = topology_m1.ms["supplier1"]
112
113 # Add self user modification and anonymous aci
114 USER_SELF_MOD_ACI = '(targetattr="userpassword")(version 3.0; acl "pwp test"; allow (all) userdn="ldap:///self";)'
115 ANON_ACI = "(targetattr=\"*\")(version 3.0; acl \"Anonymous Read access\"; allow (read,search,compare) userdn = \"ldap:///anyone\";)"
116 suffix = Domain(inst, DEFAULT_SUFFIX)
117 existing_acis = suffix.get_attr_vals_utf8('aci') or []
118 if USER_SELF_MOD_ACI not in existing_acis:
119 suffix.add('aci', USER_SELF_MOD_ACI)
120 if ANON_ACI not in existing_acis:
121 suffix.add('aci', ANON_ACI)
122
123 ous = []
124 for suffix, ou in [(DEFAULT_SUFFIX, 'dirsec'), (f'ou=people,{DEFAULT_SUFFIX}', 'others')]:
125 created_ou = OrganizationalUnits(inst, suffix).create(properties={
126 'ou': ou
127 })
128 ous.append(created_ou)
129
130 users = []
131 for uid, cn, sn, givenname, userpasseord, gid, ou in [
132 ('dbyers', 'Danny Byers', 'Byers', 'Danny', 'dby3rs1', '10001', 'ou=dirsec'),
133 ('orla', 'Orla Hegarty', 'Hegarty', 'Orla', '000rla1', '10002', 'ou=dirsec'),
134 ('joe', 'Joe Rath', 'Rath', 'Joe', '00j0e1', '10003', 'ou=people'),
135 ('jack', 'Jack Rath', 'Rath', 'Jack', '00j6ck1', '10004', 'ou=people'),
136 ('fred', 'Fred Byers', 'Byers', 'Fred', '00fr3d1', '10005', None),
137 ('deep', 'Deep Blue', 'Blue', 'Deep', '00de3p1', '10006', 'ou=others, ou=people'),
138 ('accntlusr', 'AccountControl User', 'ControlUser', 'Account', 'AcControl123', '10007', 'ou=dirsec'),
139 ('nocntlusr', 'NoAccountControl User', 'ControlUser', 'NoAccount', 'NoControl123', '10008', 'ou=dirsec')
140 ]:
141 users.append(create_user(inst, uid, cn, sn, givenname, userpasseord, gid, ou))
142
143 policy_props = {'passwordexp': 'off',
144 'passwordchange': 'off',
145 'passwordmustchange': 'off',
146 'passwordchecksyntax': 'off',
147 'passwordinhistory': '6',
148 'passwordhistory': 'off',
149 'passwordlockout': 'off',
150 'passwordlockoutduration': '3600',
151 'passwordmaxage': '8640000',
152 'passwordmaxfailure': '3',
153 'passwordminage': '0',
154 'passwordminlength': '6',
155 'passwordresetfailurecount': '600',
156 'passwordunlock': 'on',
157 'passwordStorageScheme': 'CLEAR',
158 'passwordwarning': '86400'
159 }
160 pwp_dns = []
161 pwp = PwPolicyManager(inst)
162 for dn_dn in (f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}',
163 f'uid=joe,ou=People,{DEFAULT_SUFFIX}'):
164 pwp_dns.append(dn_dn)
165 pwp.create_user_policy(dn_dn, policy_props)
166
167 # The function creates PwPolicyEntry with cn: "<DN>" value instead of <DN>
168 create_subtree_policy_custom(inst, f'ou=People,{DEFAULT_SUFFIX}', policy_props)
169
170 def fin():
171 for dn in pwp_dns:
172 pwp.delete_local_policy(dn)
173
174 for user in users:
175 user.delete()
176
177 for ou in ous:
178 ou.delete()
179
180 request.addfinalizer(fin)
181
182 return pwp
183
184 @pytest.fixture(scope="function")
185 def policy_setup(topo, request):
186 """
187 Will do pretest setup.
188 """
189
190 # Add self user modification and anonymous aci
191 USER_SELF_MOD_ACI = '(targetattr="userpassword")(version 3.0; acl "pwp test"; allow (all) userdn="ldap:///self";)'
192 ANON_ACI = "(targetattr=\"*\")(version 3.0; acl \"Anonymous Read access\"; allow (read,search,compare) userdn = \"ldap:///anyone\";)"
193 suffix = Domain(topo.standalone, DEFAULT_SUFFIX)
194 existing_acis = suffix.get_attr_vals_utf8('aci') or []
195 if USER_SELF_MOD_ACI not in existing_acis:
196 suffix.add('aci', USER_SELF_MOD_ACI)
197 if ANON_ACI not in existing_acis:
198 suffix.add('aci', ANON_ACI)
199
200 ous = []
201 for suffix, ou in [(DEFAULT_SUFFIX, 'dirsec'), (f'ou=people,{DEFAULT_SUFFIX}', 'others')]:
202 ous.append(OrganizationalUnits(topo.standalone, suffix).create(properties={
203 'ou': ou
204 }))
205
206 users = []
207 for uid, cn, sn, givenname, userpasseord, gid, ou in [
208 ('dbyers', 'Danny Byers', 'Byers', 'Danny', 'dby3rs1', '10001', 'ou=dirsec'),
209 ('orla', 'Orla Hegarty', 'Hegarty', 'Orla', '000rla1', '10002', 'ou=dirsec'),
210 ('joe', 'Joe Rath', 'Rath', 'Joe', '00j0e1', '10003', 'ou=people'),
211 ('jack', 'Jack Rath', 'Rath', 'Jack', '00j6ck1', '10004', 'ou=people'),
212 ('fred', 'Fred Byers', 'Byers', 'Fred', '00fr3d1', '10005', None),
213 ('deep', 'Deep Blue', 'Blue', 'Deep', '00de3p1', '10006', 'ou=others, ou=people'),
214 ('accntlusr', 'AccountControl User', 'ControlUser', 'Account', 'AcControl123', '10007', 'ou=dirsec'),
215 ('nocntlusr', 'NoAccountControl User', 'ControlUser', 'NoAccount', 'NoControl123', '10008', 'ou=dirsec')
216 ]:
217 users.append(create_user(topo.standalone, uid, cn, sn, givenname, userpasseord, gid, ou))
218
219 policy_props = {'passwordexp': 'off',
220 'passwordchange': 'off',
221 'passwordmustchange': 'off',
222 'passwordchecksyntax': 'off',
223 'passwordinhistory': '6',
224 'passwordhistory': 'off',
225 'passwordlockout': 'off',
226 'passwordlockoutduration': '3600',
227 'passwordmaxage': '8640000',
228 'passwordmaxfailure': '3',
229 'passwordminage': '0',
230 'passwordminlength': '6',
231 'passwordresetfailurecount': '600',
232 'passwordunlock': 'on',
233 'passwordStorageScheme': 'CLEAR',
234 'passwordwarning': '86400'
235 }
236 pwp_dns = []
237 pwp = PwPolicyManager(topo.standalone)
238 for dn_dn in (f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}',
239 f'uid=joe,ou=People,{DEFAULT_SUFFIX}'):
240 pwp_dns.append(dn_dn)
241 pwp.create_user_policy(dn_dn, policy_props)
242
243 pwp.create_subtree_policy(f'ou=People,{DEFAULT_SUFFIX}', policy_props)
244
245 def fin():
246 pwp.delete_local_policy(f'ou=People,{DEFAULT_SUFFIX}')
247
248 for dn in pwp_dns:
249 pwp.delete_local_policy(dn)
250
251 for user in users:
252 user.delete()
253
254 for ou in ous:
255 ou.delete()
256
257 request.addfinalizer(fin)
258
259
260 def change_password(topo, user_password_new_pass_list):
261 """
262 Will change password with self binding.
263 """
264 for user, password, new_pass in user_password_new_pass_list:
265 real_user = UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}')
266 conn = real_user.bind(password)
267 UserAccount(conn, real_user.dn).replace('userpassword', new_pass)
268
269
270 def change_password_ultra_new(topo, user_password_new_pass_list):
271 """
272 Will change password with self binding.
273 """
274 for user, password, new_pass, ultra_new_pass in user_password_new_pass_list:
275 real_user = UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}')
276 conn = real_user.bind(password)
277 UserAccount(conn, real_user.dn).replace('userpassword', new_pass)
278 conn = real_user.bind(new_pass)
279 UserAccount(conn, real_user.dn).replace('userpassword', ultra_new_pass)
280
281
282 def change_password_with_admin(topo, user_password_new_pass_list):
283 """
284 Will change password by root.
285 """
286 for user, password in user_password_new_pass_list:
287 UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}').replace('userpassword', password)
288
289
290 def _do_transaction_for_pwp(topo, attr1, attr2):
291 """
292 Will change pwp parameters
293 """
294 pwp = PwPolicyManager(topo.standalone)
295 orl = pwp.get_pwpolicy_entry(f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
296 joe = pwp.get_pwpolicy_entry(f'uid=joe,ou=people,{DEFAULT_SUFFIX}')
297 people = pwp.get_pwpolicy_entry(f'ou=people,{DEFAULT_SUFFIX}')
298 for instance in [orl, joe, people]:
299 instance.replace(attr1, attr2)
300 for instance in [orl, joe, people]:
301 assert instance.get_attr_val_utf8(attr1) == attr2
302
303
304 @pytest.fixture(scope="function")
305 def fixture_for_password_change(request, topo):
306 pwp = PwPolicyManager(topo.standalone)
307 orl = pwp.get_pwpolicy_entry(f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
308 for attribute in ('passwordMustChange', 'passwordmustchange'):
309 orl.replace(attribute, 'off')
310 assert orl.get_attr_val_utf8(attribute) == 'off'
311
312 def final_task():
313 people = pwp.get_pwpolicy_entry(f'ou=people,{DEFAULT_SUFFIX}')
314 people.replace('passwordchange', 'on')
315 assert people.get_attr_val_utf8('passwordchange') == 'on'
316 # Administrator Reseting to original password
317 change_password_with_admin(topo, [
318 ('uid=joe,ou=people', '00j0e1'),
319 ('uid=fred', '00fr3d1'),
320 ('uid=jack,ou=people', '00j6ck1'),
321 ('uid=deep,ou=others,ou=people', '00de3p1'),
322 ('uid=orla,ou=dirsec', '000rla1'),
323 ('uid=dbyers,ou=dirsec', 'Anuj')
324 ])
325 request.addfinalizer(final_task)
326
327 def _cli_args(dn, **extraargs):
328 args = FakeArgs()
329 args.DN = dn
330 args.suffix = False
331 args.json = False
332 args.verbose = False
333 args.pwdchange = None
334 args.pwdlockout = None
335 for key, value in extraargs.items():
336 setattr(args, key, value)
337 return args
338
339 def _assert_no_duplicate_in_logs(logcap):
340 logged_output = []
341 for rec in logcap.outputs:
342 msg = rec.getMessage()
343 for line in msg.splitlines():
344 if line.strip():
345 logged_output.append(line)
346 assert len(logged_output) == len(set(logged_output))
347
348 def test_password_change_section(topo, policy_setup, fixture_for_password_change):
349 """Password Change Section.
350
351 :id: 5d018c08-9388-11ea-8394-8c16451d917b
352 :setup: Standalone
353 :steps:
354 1. Confirm that user is not been affected by fine grained password
355 (As its is not belong to any password policy)
356 2. Should be able to change password(As its is not belong to any password policy)
357 3. Try to change password for user even though pw policy is set to no.
358 Should get error message: unwilling to Perform !
359 4. Set Password change to May Change Password.
360 5. Administrator Reseting to original password !
361 6. Attempt to Modify password to orla2 with an invalid first pw with error message.
362 7. Changing current password from orla1 to orla2
363 8. Changing current password from orla2 to orla1.
364 9. Set Password change to Must Not Change After Reset
365 10 Change password for joe,jack,deep even though pw policy is set to no with error message.
366 11. Fred can change.(Fred is not belong to any pw policy)
367 12. Changing pw policy to may change pw
368 13. Set Password change to May Change Password
369 14. Administrator Reseting to original password
370 15. Try to change password with invalid credentials. Should see error message.
371 16. Changing current password for joe and fed.
372 17. Changing current password for jack and deep with error message.(passwordchange not on)
373 18. Changing pw policy to may change pw
374 19. Set Password change to May Change Password
375 20. Administrator Reseting to original password
376 21. Try to change password with invalid credentials. Should see error message.
377 22. Changing current password
378 23. Set Password change to Must Not Change After Reset
379 24. Searching for passwordchange: Off
380 25. Administrator Reseting to original password
381 26. Try to change password with invalid credentials. Should see error message
382 27. Changing current password (('passwordchange', 'off') for joe)
383 :expectedresults:
384 1. Success(As its is not belong to any password policy)
385 2. Success
386 3. Fail(pw policy is set to no)
387 4. Success
388 5. Success
389 6. Fail(invalid first pw)
390 7. Success
391 8. Success
392 9. Success
393 10. Fail(pw policy is set to no)
394 11. Success((Fred is not belong to any pw policy))
395 12. Success
396 13. Success
397 14. Success
398 15. Fail(invalid credentials)
399 16. Success((passwordchange on))
400 17. Fail(passwordchange not on)
401 18. Success
402 19. Success
403 20. Success
404 21. Fail(invalid credentials)
405 22. Success
406 23. Success
407 24. Success
408 25. Success
409 26. Fail(invalid credentials)
410 27. Success
411 """
412 # Confirm that uid=dbyers is not been affected by fine grained password
413 dbyers = UserAccount(topo.standalone, f'uid=dbyers,ou=dirsec,{DEFAULT_SUFFIX}')
414 conn = dbyers.bind('dby3rs1')
415 dbyers_conn = UserAccount(conn, f'uid=dbyers,ou=dirsec,{DEFAULT_SUFFIX}')
416 # Should be able to change password(As its is not belong to any password policy)
417 dbyers_conn.replace('userpassword', "Anuj")
418 # Try to change password for uid=orla even though pw policy is set to no.
419 # Should get error message: unwilling to Perform !
420 orla = UserAccount(topo.standalone, f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
421 conn = orla.bind('000rla1')
422 orla_conn = UserAccount(conn, f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
423 # pw policy is set to no
424 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
425 orla_conn.replace('userpassword', "000rla2")
426 pwp = PwPolicyManager(topo.standalone)
427 orl = pwp.get_pwpolicy_entry(f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
428 # Set Password change to May Change Password.
429 orl.replace('passwordchange', 'on')
430 assert orl.get_attr_val_utf8('passwordchange') == 'on'
431 # Administrator Reseting to original password !
432 orla.replace('userpassword', '000rla1')
433 # Attempt to Modify password to orla2 with an invalid first pw with error message.
434 with pytest.raises(ldap.INVALID_CREDENTIALS):
435 conn = orla.bind('Invalid_password')
436 # Changing current password from orla1 to orla2
437 orla_conn.replace('userpassword', '000rla2')
438 # Changing current password from orla2 to orla1.
439 orla_conn = UserAccount(conn, f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
440 orla_conn.replace('userpassword', '000rla1')
441 # Set Password change to Must Not Change After Reset
442 joe = pwp.get_pwpolicy_entry(f'uid=joe,ou=people,{DEFAULT_SUFFIX}')
443 people = pwp.get_pwpolicy_entry(f'ou=people,{DEFAULT_SUFFIX}')
444 joe.replace_many(('passwordmustchange', 'off'), ('passwordchange', 'off'))
445 people.replace_many(('passwordmustchange', 'off'), ('passwordchange', 'off'))
446 for attr in ['passwordMustChange', 'passwordchange']:
447 assert joe.get_attr_val_utf8(attr) == 'off'
448 for attr in ['passwordMustChange', 'passwordchange']:
449 assert people.get_attr_val_utf8(attr) == 'off'
450 # Change password for uid,joe,jack,deep even though pw policy is set to no with error message.
451 for user, password, pass_to_change in [
452 ('joe', '00j0e1', '00j0e2'),
453 ('jack', '00j6ck1', '00j6ck2'),
454 ('deep,ou=others', '00de3p1', '00de3p2')
455 ]:
456 real_user = UserAccount(topo.standalone, f'uid={user},ou=people,{DEFAULT_SUFFIX}')
457 conn = real_user.bind(password)
458 real_conn = UserAccount(conn, real_user.dn)
459 # pw policy is set to no
460 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
461 real_conn.replace('userpassword', pass_to_change)
462 real_user = UserAccount(topo.standalone, f'uid=fred,{DEFAULT_SUFFIX}')
463 conn = real_user.bind('00fr3d1')
464 # Fred can change.(Fred is not belong to any pw policy)
465 real_conn = UserAccount(conn, real_user.dn)
466 real_conn.replace('userpassword', '00fr3d2')
467 # Changing pw policy to may change pw
468 # Set Password change to May Change Password
469 joe = pwp.get_pwpolicy_entry(f'uid=joe,ou=people,{DEFAULT_SUFFIX}')
470 joe.replace('passwordchange', 'on')
471 assert joe.get_attr_val_utf8('passwordchange') == 'on'
472 # Administrator Reseting to original password
473 change_password_with_admin(topo, [
474 ('uid=joe,ou=people', '00j0e1'),
475 ('uid=jack,ou=people', '00j6ck1'),
476 ('uid=fred', '00fr3d1'),
477 ('uid=deep,ou=others,ou=people', '00de3p1')
478 ])
479 # Try to change password with invalid credentials. Should see error message.
480 for user in [
481 'uid=joe,ou=people',
482 'uid=jack,ou=people',
483 'uid=fred',
484 'uid=deep,ou=others,ou=people'
485 ]:
486 with pytest.raises(ldap.INVALID_CREDENTIALS):
487 UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}').bind("bad")
488 # Changing current password for joe and fed.
489 for user, password, new_pass in [
490 ('uid=joe,ou=people', '00j0e1', '00j0e2'),
491 ('uid=fred', '00fr3d1', '00fr3d2')
492 ]:
493 real_user = UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}')
494 conn = real_user.bind(password)
495 UserAccount(conn, real_user.dn).replace('userpassword', new_pass)
496 # Changing current password for jack and deep with error message.(passwordchange not on)
497 for user, password, new_pass in [
498 ('uid=jack,ou=people', '00j6ck1', '00j6ck2'),
499 ('uid=deep,ou=others,ou=people', '00de3p1', '00de3p2')
500 ]:
501 real_user = UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}')
502 conn = real_user.bind(password)
503 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
504 UserAccount(conn, real_user.dn).replace('userpassword', new_pass)
505 # Changing pw policy to may change pw
506 # Set Password change to May Change Password
507 people.replace('passwordchange', 'on')
508 assert people.get_attr_val_utf8('passwordchange') == 'on'
509 # Administrator Reseting to original password
510 change_password_with_admin(topo, [
511 ('uid=joe,ou=people', '00j0e1'),
512 ('uid=jack,ou=people', '00j6ck1'),
513 ('uid=fred', '00fr3d1'),
514 ('uid=deep,ou=others,ou=people', '00de3p1')
515 ])
516 # Try to change password with invalid credentials. Should see error message.
517 for user in [
518 'uid=joe,ou=people',
519 'uid=jack,ou=people',
520 'uid=fred',
521 'uid=deep,ou=others,ou=people'
522 ]:
523 with pytest.raises(ldap.INVALID_CREDENTIALS):
524 UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}').bind("bad")
525 # Changing current password
526 change_password(topo, [
527 ('uid=joe,ou=people', '00j0e1', '00j0e2'),
528 ('uid=fred', '00fr3d1', '00fr3d2'),
529 ('uid=jack,ou=people', '00j6ck1', '00j6ck2'),
530 ('uid=deep,ou=others,ou=people', '00de3p1', '00de3p2')
531 ])
532 # Set Password change to Must Not Change After Reset
533 joe.replace('passwordchange', 'off')
534 assert joe.get_attr_val_utf8('passwordchange') == 'off'
535 # Administrator Reseting to original password
536 change_password_with_admin(topo, [
537 ('uid=joe,ou=people', '00j0e1'),
538 ('uid=fred', '00fr3d1'),
539 ('uid=jack,ou=people', '00j6ck1'),
540 ('uid=deep,ou=others,ou=people', '00de3p1')
541 ])
542 # Try to change password with invalid credentials. Should see error message
543 for user in [
544 'uid=joe,ou=people',
545 'uid=jack,ou=people',
546 'uid=fred',
547 'uid=deep,ou=others,ou=people'
548 ]:
549 with pytest.raises(ldap.INVALID_CREDENTIALS):
550 UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}').bind("bad")
551 # Changing current password
552 change_password(topo, [
553 ('uid=fred', '00fr3d1', '00fr3d2'),
554 ('uid=jack,ou=people', '00j6ck1', '00j6ck2'),
555 ('uid=deep,ou=others,ou=people', '00de3p1', '00de3p2')
556 ])
557 # ('passwordchange', 'off') for joe
558 real_user = UserAccount(topo.standalone, f'uid=joe,ou=people,{DEFAULT_SUFFIX}')
559 conn = real_user.bind('00j0e1')
560 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
561 UserAccount(conn, real_user.dn).replace('userpassword', '00j0e2')
562
563
564 @pytest.fixture(scope="function")
565 def _fixture_for_syntax_section(request, topo):
566 change_password_with_admin(topo, [
567 ('uid=joe,ou=people', '00j0e1'),
568 ('uid=fred', '00fr3d1'),
569 ('uid=jack,ou=people', '00j6ck1'),
570 ('uid=deep,ou=others,ou=people', '00de3p1'),
571 ('uid=orla,ou=dirsec', '000rla1'),
572 ('uid=dbyers,ou=dirsec', 'Anuj')
573 ])
574 pwp = PwPolicyManager(topo.standalone)
575 orl = pwp.get_pwpolicy_entry(f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
576 joe = pwp.get_pwpolicy_entry(f'uid=joe,ou=people,{DEFAULT_SUFFIX}')
577 people = pwp.get_pwpolicy_entry(f'ou=people,{DEFAULT_SUFFIX}')
578 for instance in [orl, joe, people]:
579 instance.replace('passwordchecksyntax', 'on')
580 instance.replace('passwordChange', 'on')
581 assert instance.get_attr_val_utf8('passwordchecksyntax') == 'on'
582
583 def final_step():
584 for instance1 in [orl, joe, people]:
585 instance1.replace('passwordminlength', '6')
586 change_password_with_admin(topo, [
587 ('uid=orla,ou=dirsec', '000rLb1'),
588 ('uid=joe,ou=people', '00J0e1'),
589 ('uid=jack,ou=people', '00J6ck1'),
590 ('uid=deep,ou=others,ou=people', '00De3p1'),
591 ('uid=dbyers,ou=dirsec', 'dby3rs1'),
592 ('uid=fred', '00fr3d1')
593 ])
594
595 request.addfinalizer(final_step)
596
597
598 def test_password_syntax_section(topo, policy_setup, _fixture_for_syntax_section):
599 """Password Syntax Section.
600
601 :id: 7bf1cb46-9388-11ea-9019-8c16451d917b
602 :setup: Standalone
603 :steps:
604 1. Try to change password with invalid credentials. Should get error (invalid cred).
605 2. Try to change to a password that violates length. Should get error (constaint viol.).
606 3. Attempt to Modify password to db which is in error to policy
607 4. Changing password minimum length to 5 to check triviality
608 5. Try to change password to the value of uid, which is trivial. Should get error.
609 6. Try to change password to givenname which is trivial. Should get error
610 7. Try to change password to sn which is trivial. Should get error
611 8. Changing password minimum length back to 6
612 9. Changing current password from ``*1`` to ``*2``
613 10. Changing current password from ``*2`` to ``*1``
614 11. Changing current password to the evil password
615 12. Resetting to original password as cn=directory manager
616 13. Setting policy to NOT Check Password Syntax
617 14. Test that when checking syntax is off, you can use small passwords
618 15. Test that when checking syntax is off, trivial passwords can be used
619 16. Resetting to original password as cn=directory manager
620 17. Changing password minimum length from 6 to 10
621 18. Setting policy to Check Password Syntax again
622 19. Try to change to a password that violates length
623 20. Change to a password that meets length requirement
624 :expectedresults:
625 1. Fail(invalid cred)
626 2. Fail(constaint viol.)
627 3. Fail(Syntax error)
628 4. Success
629 5. Fail(trivial)
630 6. Fail(password to givenname )
631 7. Success
632 8. Success
633 9. Success
634 10. Success
635 11. Fail(evil password)
636 12. Success
637 13. Success
638 14. Success
639 15. Success
640 16. Success
641 17. Success
642 18. Success
643 19. Fail(violates length)
644 20. Success
645 """
646 # Try to change password with invalid credentials. Should get error (invalid cred).
647 for user in [
648 'uid=joe,ou=people',
649 'uid=jack,ou=people',
650 'uid=fred',
651 'uid=deep,ou=others,ou=people',
652 'uid=dbyers,ou=dirsec',
653 'uid=orla,ou=dirsec'
654 ]:
655 with pytest.raises(ldap.INVALID_CREDENTIALS):
656 UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}').bind("bad")
657 # Try to change to a password that violates length. Should get error (constaint viol.).
658 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
659 change_password(topo, [
660 ('uid=orla,ou=dirsec', '000rla1', 'db'),
661 ('uid=joe,ou=people', '00j0e1', 'db'),
662 ('uid=jack,ou=people', '00j6ck1', 'db'),
663 ('uid=deep,ou=others,ou=people', '00de3p1', 'db')
664 ])
665 # Attempt to Modify password to db which is in error to policy(Syntax error)
666 change_password_ultra_new(topo, [
667 ('uid=dbyers,ou=dirsec', 'Anuj', 'db', 'dby3rs1'),
668 ('uid=fred', '00fr3d1', 'db', '00fr3d1')
669 ])
670 # Changing password minimum length to 5 to check triviality
671 pwp = PwPolicyManager(topo.standalone)
672 orl = pwp.get_pwpolicy_entry(f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
673 joe = pwp.get_pwpolicy_entry(f'uid=joe,ou=people,{DEFAULT_SUFFIX}')
674 people = pwp.get_pwpolicy_entry(f'ou=people,{DEFAULT_SUFFIX}')
675 for instance in [orl, joe, people]:
676 instance.replace('passwordminlength', '5')
677 # Try to change password to the value of uid, which is trivial. Should get error.
678 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
679 change_password(topo, [
680 ('uid=orla,ou=dirsec', '000rla1', 'orla'),
681 ('uid=joe,ou=people', '00j0e1', 'joe'),
682 ('uid=jack,ou=people', '00j6ck1', 'jack'),
683 ('uid=deep,ou=others,ou=people', '00de3p1', 'deep')
684 ])
685 # dbyers and fred can change
686 change_password_ultra_new(topo, [
687 ('uid=dbyers,ou=dirsec', 'dby3rs1', 'dbyers', 'dby3rs1'),
688 ('uid=fred', '00fr3d1', 'fred', '00fr3d1')
689 ])
690 # Try to change password to givenname which is trivial. Should get error
691 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
692 change_password(topo, [
693 ('uid=orla,ou=dirsec', '000rla1', 'orla'),
694 ('uid=joe,ou=people', '00j0e1', 'joe'),
695 ('uid=jack,ou=people', '00j6ck1', 'jack'),
696 ('uid=deep,ou=others,ou=people', '00de3p1', 'deep')
697 ])
698 # dbyers and fred can change
699 change_password_ultra_new(topo, [
700 ('uid=dbyers,ou=dirsec', 'dby3rs1', 'danny', 'dby3rs1'),
701 ('uid=fred', '00fr3d1', 'fred', '00fr3d1')
702 ])
703 # Try to change password to sn which is trivial. Should get error
704 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
705 change_password(topo, [
706 ('uid=orla,ou=dirsec', '000rla1', 'Hegarty'),
707 ('uid=joe,ou=people', '00j0e1', 'Rath'),
708 ('uid=jack,ou=people', '00j6ck1', 'Rath'),
709 ('uid=deep,ou=others,ou=people', '00de3p1', 'Blue')
710 ])
711 # dbyers and fred can change
712 change_password_ultra_new(topo, [
713 ('uid=dbyers,ou=dirsec', 'dby3rs1', 'Byers', 'dby3rs1'),
714 ('uid=fred', '00fr3d1', 'Byers', '00fr3d1')
715 ])
716 # Changing password minimum length back to 6
717 for instance1 in [orl, joe, people]:
718 instance1.replace('passwordminlength', '6')
719 # Changing current password from *1 to *2
720 change_password(topo, [
721 ('uid=orla,ou=dirsec', '000rla1', '000rLb2'),
722 ('uid=dbyers,ou=dirsec', 'dby3rs1', 'dby3rs2'),
723 ('uid=fred', '00fr3d1', '00fr3d2'),
724 ('uid=joe,ou=people', '00j0e1', '00J0e2'),
725 ('uid=jack,ou=people', '00j6ck1', '00J6ck2'),
726 ('uid=deep,ou=others,ou=people', '00de3p1', '00De3p2')
727 ])
728 # Changing current password from *2 to *1
729 change_password(topo, [
730 ('uid=orla,ou=dirsec', '000rLb2', '000rLb1'),
731 ('uid=dbyers,ou=dirsec', 'dby3rs2', 'dby3rs1'),
732 ('uid=fred', '00fr3d2', '00fr3d1'),
733 ('uid=joe,ou=people', '00J0e2', '00J0e1'),
734 ('uid=jack,ou=people', '00J6ck2', '00J6ck1'),
735 ('uid=deep,ou=others,ou=people', '00De3p2', '00De3p1')
736 ])
737 # Changing current password to the evil password
738 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
739 change_password(topo, [
740 ('uid=orla,ou=dirsec', '000rLb1', r'{\;\\].'),
741 ('uid=joe,ou=people', '00J0e1', r'{\;\\].'),
742 ('uid=jack,ou=people', '00J6ck1', r'{\;\\].'),
743 ('uid=deep,ou=others,ou=people', '00De3p1', r'{\;\\].')
744 ])
745 # dbyers and fred can change
746 change_password(topo, [
747 ('uid=dbyers,ou=dirsec', 'dby3rs1', r'{\;\\].'),
748 ('uid=fred', '00fr3d1', r'{\;\\].')
749 ])
750 # Resetting to original password as cn=directory manager
751 change_password_with_admin(topo, [
752 ('uid=orla,ou=dirsec', '000rLb1'),
753 ('uid=joe,ou=people', '00J0e1'),
754 ('uid=jack,ou=people', '00J6ck1'),
755 ('uid=deep,ou=others,ou=people', '00De3p1'),
756 ('uid=dbyers,ou=dirsec', 'dby3rs1'),
757 ('uid=fred', '00fr3d1')
758 ])
759 # Setting policy to NOT Check Password Syntax
760 # Searching for passwordminlength
761 for instance in [orl, joe, people]:
762 instance.replace('passwordchecksyntax', 'off')
763 for instance in [orl, joe, people]:
764 assert instance.get_attr_val_utf8('passwordchecksyntax') == 'off'
765 assert instance.get_attr_val_utf8('passwordminlength') == '6'
766 # Test that when checking syntax is off, you can use small passwords
767 change_password(topo, [
768 ('uid=orla,ou=dirsec', '000rLb1', 'db'),
769 ('uid=joe,ou=people', '00J0e1', 'db'),
770 ('uid=jack,ou=people', '00J6ck1', 'db'),
771 ('uid=deep,ou=others,ou=people', '00De3p1', 'db'),
772 ('uid=dbyers,ou=dirsec', 'dby3rs1', 'db'),
773 ('uid=fred', '00fr3d1', 'db')
774 ])
775 # Test that when checking syntax is off, trivial passwords can be used
776 change_password(topo, [
777 ('uid=orla,ou=dirsec', 'db', 'orla'),
778 ('uid=joe,ou=people', 'db', 'joe'),
779 ('uid=jack,ou=people', 'db', 'jack'),
780 ('uid=deep,ou=others,ou=people', 'db', 'deep'),
781 ('uid=dbyers,ou=dirsec', 'db', 'dbyers'),
782 ('uid=fred', 'db', 'fred')
783 ])
784 # Resetting to original password as cn=directory manager
785 change_password_with_admin(topo, [
786 ('uid=orla,ou=dirsec', '000rLb1'),
787 ('uid=joe,ou=people', '00J0e1'),
788 ('uid=jack,ou=people', '00J6ck1'),
789 ('uid=deep,ou=others,ou=people', '00De3p1'),
790 ('uid=dbyers,ou=dirsec', 'dby3rs1'),
791 ('uid=fred', '00fr3d1')
792 ])
793 # Changing password minimum length from 6 to 10
794 # Setting policy to Check Password Syntax again
795 for instance in [orl, joe, people]:
796 instance.replace_many(
797 ('passwordchecksyntax', 'on'),
798 ('passwordminlength', '10'))
799 # Try to change to a password that violates length
800 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
801 change_password(topo, [
802 ('uid=orla,ou=dirsec', '000rLb1', 'db'),
803 ('uid=joe,ou=people', '00J0e1', 'db'),
804 ('uid=jack,ou=people', '00J6ck1', 'db'),
805 ('uid=deep,ou=others,ou=people', '00De3p1', 'db')
806 ])
807 # dbyers and fred can change as it does not belong to any pw policy
808 change_password(topo, [
809 ('uid=dbyers,ou=dirsec', 'dby3rs1', 'db'),
810 ('uid=fred', '00fr3d1', 'db')
811 ])
812 # Change to a password that meets length requirement
813 change_password(topo, [
814 ('uid=orla,ou=dirsec', '000rLb1', 'This_IS_a_very_very_long_password'),
815 ('uid=joe,ou=people', '00J0e1', 'This_IS_a_very_very_long_password'),
816 ('uid=jack,ou=people', '00J6ck1', 'This_IS_a_very_very_long_password'),
817 ('uid=deep,ou=others,ou=people', '00De3p1', 'This_IS_a_very_very_long_password'),
818 ('uid=dbyers,ou=dirsec', 'db', 'This_IS_a_very_very_long_password'),
819 ('uid=fred', 'db', 'This_IS_a_very_very_long_password')
820 ])
821
822
823 @pytest.fixture(scope="function")
824 def _fixture_for_password_history(request, topo):
825 pwp = PwPolicyManager(topo.standalone)
826 orl = pwp.get_pwpolicy_entry(f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
827 joe = pwp.get_pwpolicy_entry(f'uid=joe,ou=people,{DEFAULT_SUFFIX}')
828 people = pwp.get_pwpolicy_entry(f'ou=people,{DEFAULT_SUFFIX}')
829 change_password_with_admin(topo, [
830 ('uid=orla,ou=dirsec', '000rLb1'),
831 ('uid=joe,ou=people', '00J0e1'),
832 ('uid=jack,ou=people', '00J6ck1'),
833 ('uid=deep,ou=others,ou=people', '00De3p1')
834 ])
835 for instance in [orl, joe, people]:
836 instance.replace_many(
837 ('passwordhistory', 'on'),
838 ('passwordinhistory', '3'),
839 ('passwordChange', 'on'))
840 for instance in [orl, joe, people]:
841 assert instance.get_attr_val_utf8('passwordhistory') == 'on'
842 assert instance.get_attr_val_utf8('passwordinhistory') == '3'
843 assert instance.get_attr_val_utf8('passwordChange') == 'on'
844
845 def final_step():
846 for instance1 in [orl, joe, people]:
847 instance1.replace('passwordhistory', 'off')
848 change_password_with_admin(topo, [
849 ('uid=orla,ou=dirsec', '000rLb1'),
850 ('uid=joe,ou=people', '00J0e1'),
851 ('uid=jack,ou=people', '00J6ck1'),
852 ('uid=deep,ou=others,ou=people', '00De3p1')
853 ])
854 request.addfinalizer(final_step)
855
856
857 def test_password_history_section(topo, policy_setup, _fixture_for_password_history):
858 """Password History Section.
859
860 :id: 51f459a0-a0ba-11ea-ade7-8c16451d917b
861 :setup: Standalone
862 :steps:
863 1. Changing current password for orla,joe,jack and deep
864 2. Checking that the passwordhistory attribute has been added !
865 3. Try to change the password back which should fail
866 4. Change the passwords for all four test users to something new
867 5. Try to change passwords back to the first password
868 6. Change to a fourth password not in password history
869 7. Try to change all the passwords back to the first password
870 8. Change the password to one more new password as root dn
871 9. Now try to change the password back to the first password
872 10. Checking that password history does still containt the previous 3 passwords
873 11. Add a password test for long long password (more than 490 bytes).
874 12. Changing password : LONGPASSWORD goes in history
875 13. Setting policy to NOT keep password histories
876 14. Changing current password from ``*2 to ``*2``
877 15. Try to change ``*2`` to ``*1``, should succeed
878 :expectedresults:
879 1. Success
880 2. Success
881 3. Fail(ldap.CONSTRAINT_VIOLATION)
882 4. Success
883 5. Fail(ldap.CONSTRAINT_VIOLATION))
884 6. Success
885 7. Fail(ldap.CONSTRAINT_VIOLATION))
886 8. Success
887 9. Success
888 10. Success
889 11. Success
890 12. Success
891 13. Success
892 14. Success
893 15. Success
894 """
895 # Changing current password for orla,joe,jack and deep
896 change_password_with_admin(topo, [
897 ('uid=orla,ou=dirsec', '000rLb2'),
898 ('uid=joe,ou=people', '00J0e2'),
899 ('uid=jack,ou=people', '00J6ck2'),
900 ('uid=deep,ou=others,ou=people', '00De3p2'),
901 ])
902 time.sleep(1)
903 # Checking that the password history attribute has been added !
904 for user, password in [
905 ('uid=orla,ou=dirsec', '000rLb1'),
906 ('uid=joe,ou=people', '00J0e1'),
907 ('uid=jack,ou=people', '00J6ck1'),
908 ('uid=deep,ou=others,ou=people', '00De3p1'),
909 ]:
910 assert password in UserAccount(topo.standalone,
911 f'{user},{DEFAULT_SUFFIX}').get_attr_val_utf8("passwordhistory")
912 # Try to change the password back which should fail
913 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
914 change_password(topo, [
915 ('uid=orla,ou=dirsec', '000rLb2', '000rLb1'),
916 ('uid=joe,ou=people', '00J0e2', '00J0e1'),
917 ('uid=jack,ou=people', '00J6ck2', '00J6ck1'),
918 ('uid=deep,ou=others,ou=people', '00De3p2', '00De3p1'),
919 ])
920 # Change the passwords for all four test users to something new
921 change_password_with_admin(topo, [
922 ('uid=orla,ou=dirsec', '000rLb3'),
923 ('uid=joe,ou=people', '00J0e3'),
924 ('uid=jack,ou=people', '00J6ck3'),
925 ('uid=deep,ou=others,ou=people', '00De3p3')
926 ])
927 # Try to change passwords back to the first password
928 time.sleep(1)
929 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
930 change_password(topo, [
931 ('uid=orla,ou=dirsec', '000rLb3', '000rLb1'),
932 ('uid=joe,ou=people', '00J0e3', '00J0e1'),
933 ('uid=jack,ou=people', '00J6ck3', '00J6ck1'),
934 ('uid=deep,ou=others,ou=people', '00De3p3', '00De3p1'),
935 ])
936 # Change to a fourth password not in password history
937 change_password_with_admin(topo, [
938 ('uid=orla,ou=dirsec', '000rLb4'),
939 ('uid=joe,ou=people', '00J0e4'),
940 ('uid=jack,ou=people', '00J6ck4'),
941 ('uid=deep,ou=others,ou=people', '00De3p4')
942 ])
943 time.sleep(1)
944 # Try to change all the passwords back to the first password
945 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
946 change_password(topo, [
947 ('uid=orla,ou=dirsec', '000rLb4', '000rLb1'),
948 ('uid=joe,ou=people', '00J0e4', '00J0e1'),
949 ('uid=jack,ou=people', '00J6ck4', '00J6ck1'),
950 ('uid=deep,ou=others,ou=people', '00De3p4', '00De3p1')
951 ])
952 # change the password to one more new password as root dn
953 change_password_with_admin(topo, [
954 ('uid=orla,ou=dirsec', '000rLb5'),
955 ('uid=joe,ou=people', '00J0e5'),
956 ('uid=jack,ou=people', '00J6ck5'),
957 ('uid=deep,ou=others,ou=people', '00De3p5')
958 ])
959 time.sleep(1)
960 # Now try to change the password back to the first password
961 change_password(topo, [
962 ('uid=orla,ou=dirsec', '000rLb5', '000rLb1'),
963 ('uid=joe,ou=people', '00J0e5', '00J0e1'),
964 ('uid=jack,ou=people', '00J6ck5', '00J6ck1'),
965 ('uid=deep,ou=others,ou=people', '00De3p5', '00De3p1')
966 ])
967 time.sleep(1)
968 # checking that password history does still containt the previous 3 passwords
969 for user, password3, password2, password1 in [
970 ('uid=orla,ou=dirsec', '000rLb5', '000rLb4', '000rLb3'),
971 ('uid=joe,ou=people', '00J0e5', '00J0e4', '00J0e3'),
972 ('uid=jack,ou=people', '00J6ck5', '00J6ck4', '00J6ck3'),
973 ('uid=deep,ou=others,ou=people', '00De3p5', '00De3p4', '00De3p3')
974 ]:
975 user1 = UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}')
976 pass_list = ''.join(user1.get_attr_vals_utf8("passwordhistory"))
977 assert password1 in pass_list
978 assert password2 in pass_list
979 assert password3 in pass_list
980 # Add a password test for long long password (more than 490 bytes).
981 long = '01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901' \
982 '23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456' \
983 '789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012' \
984 '345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678' \
985 '901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234' \
986 '5678901234567890123456789LENGTH=510'
987 change_password(topo, [
988 ('uid=orla,ou=dirsec', '000rLb1', long),
989 ('uid=joe,ou=people', '00J0e1', long),
990 ('uid=jack,ou=people', '00J6ck1', long),
991 ('uid=deep,ou=others,ou=people', '00De3p1', long)
992 ])
993 time.sleep(1)
994 # Changing password : LONGPASSWORD goes in history
995 change_password(topo, [
996 ('uid=orla,ou=dirsec', long, '000rLb2'),
997 ('uid=joe,ou=people', long, '00J0e2'),
998 ('uid=jack,ou=people', long, '00J6ck2'),
999 ('uid=deep,ou=others,ou=people', long, '00De3p2')
1000 ])
1001 time.sleep(1)
1002 for user, password in [
1003 ('uid=orla,ou=dirsec', '000rLb2'),
1004 ('uid=joe,ou=people', '00J0e2'),
1005 ('uid=jack,ou=people', '00J6ck2'),
1006 ('uid=deep,ou=others,ou=people', '00De3p2')
1007 ]:
1008 real_user = UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}')
1009 conn = real_user.bind(password)
1010 assert long in ''.join(UserAccount(conn,
1011 f'{user},{DEFAULT_SUFFIX}').get_attr_vals_utf8("passwordhistory"))
1012 # Setting policy to NOT keep password histories
1013 _do_transaction_for_pwp(topo, 'passwordhistory', 'off')
1014 time.sleep(1)
1015 # Changing current password from *2 to *2
1016 change_password(topo, [
1017 ('uid=orla,ou=dirsec', '000rLb2', '000rLb2'),
1018 ('uid=joe,ou=people', '00J0e2', '00J0e2'),
1019 ('uid=jack,ou=people', '00J6ck2', '00J6ck2'),
1020 ('uid=deep,ou=others,ou=people', '00De3p2', '00De3p2')
1021 ])
1022 # Try to change *2 to *1, should succeed
1023 change_password(topo, [
1024 ('uid=orla,ou=dirsec', '000rLb2', '000rLb1'),
1025 ('uid=joe,ou=people', '00J0e2', '00J0e1'),
1026 ('uid=jack,ou=people', '00J6ck2', '00J6ck1'),
1027 ('uid=deep,ou=others,ou=people', '00De3p2', '00De3p1')
1028 ])
1029
1030
1031 @pytest.fixture(scope="function")
1032 def _fixture_for_password_min_age(request, topo):
1033 pwp = PwPolicyManager(topo.standalone)
1034 orl = pwp.get_pwpolicy_entry(f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
1035 joe = pwp.get_pwpolicy_entry(f'uid=joe,ou=people,{DEFAULT_SUFFIX}')
1036 people = pwp.get_pwpolicy_entry(f'ou=people,{DEFAULT_SUFFIX}')
1037 change_password_with_admin(topo, [
1038 ('uid=orla,ou=dirsec', '000rLb1'),
1039 ('uid=joe,ou=people', '00J0e1'),
1040 ('uid=jack,ou=people', '00J6ck1'),
1041 ('uid=deep,ou=others,ou=people', '00De3p1')
1042 ])
1043 for pwp1 in [orl, joe, people]:
1044 assert pwp1.get_attr_val_utf8('passwordminage') == '0'
1045 pwp1.replace_many(
1046 ('passwordminage', '10'),
1047 ('passwordChange', 'on'))
1048
1049 def final_step():
1050 for pwp2 in [orl, joe, people]:
1051 pwp2.replace('passwordminage', '0')
1052 request.addfinalizer(final_step)
1053
1054
1055 def test_password_minimum_age_section(topo, policy_setup, _fixture_for_password_min_age):
1056 """Password History Section.
1057
1058 :id: 470f5b2a-a0ba-11ea-ab2d-8c16451d917b
1059 :setup: Standalone
1060 :steps:
1061 1. Searching for password minimum age, should be 0 per defaults set
1062 2. Change current password from ``*1`` to ``*2``
1063 3. Wait 5 secs and try to change again. Should fail.
1064 4. Wait more time to complete password min age
1065 5. Now user can change password
1066 :expectedresults:
1067 1. Success
1068 2. Success
1069 3. Fail(ldap.CONSTRAINT_VIOLATION)
1070 4. Success
1071 5. Success
1072 """
1073 # Change current password from *1 to *2
1074 change_password(topo, [
1075 ('uid=orla,ou=dirsec', '000rLb1', '000rLb2'),
1076 ('uid=joe,ou=people', '00J0e1', '00J0e2'),
1077 ('uid=jack,ou=people', '00J6ck1', '00J6ck2'),
1078 ('uid=deep,ou=others,ou=people', '00De3p1', '00De3p2')
1079 ])
1080 # Wait 5 secs and try to change again. Should fail.
1081 count = 0
1082 while count < 5:
1083 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
1084 change_password(topo, [
1085 ('uid=orla,ou=dirsec', '000rLb2', '000rLb1'),
1086 ('uid=joe,ou=people', '00J0e2', '00J0e1'),
1087 ('uid=jack,ou=people', '00J6ck2', '00J6ck1'),
1088 ('uid=deep,ou=others,ou=people', '00De3p2', '00De3p1')
1089 ])
1090 time.sleep(1)
1091 count += 1
1092 # Wait more time to complete password min age
1093 time.sleep(6)
1094 # Now user can change password
1095 change_password(topo, [
1096 ('uid=orla,ou=dirsec', '000rLb2', '000rLb1'),
1097 ('uid=joe,ou=people', '00J0e2', '00J0e1'),
1098 ('uid=jack,ou=people', '00J6ck2', '00J6ck1'),
1099 ('uid=deep,ou=others,ou=people', '00De3p2', '00De3p1')
1100 ])
1101
1102
1103 @pytest.fixture(scope="function")
1104 def _fixture_for_password_lock_out(request, topo):
1105 pwp = PwPolicyManager(topo.standalone)
1106 orl = pwp.get_pwpolicy_entry(f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
1107 joe = pwp.get_pwpolicy_entry(f'uid=joe,ou=people,{DEFAULT_SUFFIX}')
1108 people = pwp.get_pwpolicy_entry(f'ou=people,{DEFAULT_SUFFIX}')
1109 change_password_with_admin(topo, [
1110 ('uid=orla,ou=dirsec', '000rLb1'),
1111 ('uid=joe,ou=people', '00J0e1'),
1112 ('uid=jack,ou=people', '00J6ck1'),
1113 ('uid=deep,ou=others,ou=people', '00De3p1')
1114 ])
1115 for pwp1 in [orl, joe, people]:
1116 assert pwp1.get_attr_val_utf8('passwordlockout') == 'off'
1117 pwp1.replace_many(
1118 ('passwordlockout', 'on'),
1119 ('passwordlockoutduration', '3'),
1120 ('passwordresetfailurecount', '3'),
1121 ('passwordChange', 'on'))
1122
1123 def final_step():
1124 for instance in [orl, joe, people]:
1125 instance.replace('passwordlockout', 'off')
1126 instance.replace('passwordunlock', 'off')
1127 assert instance.get_attr_val_utf8('passwordlockout') == 'off'
1128 assert instance.get_attr_val_utf8('passwordunlock') == 'off'
1129 request.addfinalizer(final_step)
1130
1131
1132 def test_account_lockout_and_lockout_duration_section(topo, policy_setup, _fixture_for_password_lock_out):
1133 """Account Lockout and Lockout Duration Section
1134
1135 :id: 1ff0b7a4-b560-11ea-9ece-8c16451d917b
1136 :setup: Standalone
1137 :steps:
1138 1. Try to bind with invalid credentials
1139 2. Try to bind with valid pw, should give lockout error
1140 3. After 3 seconds Try to bind with valid pw, should work
1141 4. Try to bind with invalid credentials
1142 5. Attempt to bind with valid pw after timeout is up
1143 6. Resetting with root can break lockout
1144 :expectedresults:
1145 1. Fail(ldap.INVALID_CREDENTIALS)
1146 2. Fail(ldap.CONSTRAINT_VIOLATION)
1147 3. Success
1148 4. Fail(ldap.INVALID_CREDENTIALS))
1149 5. Success
1150 6. Success
1151 """
1152 # Try to bind with invalid credentials
1153 for count1 in range(3):
1154 with pytest.raises(ldap.INVALID_CREDENTIALS):
1155 change_password(topo, [
1156 ('uid=orla,ou=dirsec', 'Invalid', 'Invalid'),
1157 ('uid=joe,ou=people', 'Invalid', 'Invalid'),
1158 ('uid=jack,ou=people', 'Invalid', 'Invalid'),
1159 ('uid=deep,ou=others,ou=people', 'Invalid', 'Invalid')
1160 ])
1161 # Try to bind with valid pw, should give lockout error
1162 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
1163 change_password(topo, [
1164 ('uid=orla,ou=dirsec', '000rLb1', '000rLb1'),
1165 ('uid=joe,ou=people', '00J0e1', '00J0e1'),
1166 ('uid=jack,ou=people', '00J6ck1', '00J6ck1'),
1167 ('uid=deep,ou=others,ou=people', '00De3p1', '00De3p1')
1168 ])
1169 # Try to bind with valid pw, should work
1170 time.sleep(3)
1171 change_password(topo, [
1172 ('uid=orla,ou=dirsec', '000rLb1', '000rLb2'),
1173 ('uid=joe,ou=people', '00J0e1', '00J0e2'),
1174 ('uid=jack,ou=people', '00J6ck1', '00J6ck2'),
1175 ('uid=deep,ou=others,ou=people', '00De3p1', '00De3p2')
1176 ])
1177 # Try to bind with invalid credentials
1178 for count1 in range(2):
1179 with pytest.raises(ldap.INVALID_CREDENTIALS):
1180 change_password(topo, [
1181 ('uid=orla,ou=dirsec', 'Invalid', 'Invalid'),
1182 ('uid=joe,ou=people', 'Invalid', 'Invalid'),
1183 ('uid=jack,ou=people', 'Invalid', 'Invalid'),
1184 ('uid=deep,ou=others,ou=people', 'Invalid', 'Invalid')
1185 ])
1186 # Attempt to bind with valid pw after timeout is up
1187 time.sleep(3)
1188 change_password(topo, [
1189 ('uid=orla,ou=dirsec', '000rLb2', '000rLb1'),
1190 ('uid=joe,ou=people', '00J0e2', '00J0e1'),
1191 ('uid=jack,ou=people', '00J6ck2', '00J6ck1'),
1192 ('uid=deep,ou=others,ou=people', '00De3p2', '00De3p1')
1193 ])
1194 # Resetting with root can break lockout
1195 for count1 in range(3):
1196 with pytest.raises(ldap.INVALID_CREDENTIALS):
1197 change_password(topo, [
1198 ('uid=orla,ou=dirsec', 'Invalid', 'Invalid'),
1199 ('uid=joe,ou=people', 'Invalid', 'Invalid'),
1200 ('uid=jack,ou=people', 'Invalid', 'Invalid'),
1201 ('uid=deep,ou=others,ou=people', 'Invalid', 'Invalid')
1202 ])
1203 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
1204 change_password(topo, [
1205 ('uid=orla,ou=dirsec', '000rLb1', '000rLb1'),
1206 ('uid=joe,ou=people', '00J0e1', '00J0e1'),
1207 ('uid=jack,ou=people', '00J6ck1', '00J6ck1'),
1208 ('uid=deep,ou=others,ou=people', '00De3p1', '00De3p1')
1209 ])
1210 change_password_with_admin(topo, [
1211 ('uid=orla,ou=dirsec', '000rLb1'),
1212 ('uid=joe,ou=people', '00J0e1'),
1213 ('uid=jack,ou=people', '00J6ck1'),
1214 ('uid=deep,ou=others,ou=people', '00De3p1')
1215 ])
1216 change_password(topo, [
1217 ('uid=orla,ou=dirsec', '000rLb1', '000rLb1'),
1218 ('uid=joe,ou=people', '00J0e1', '00J0e1'),
1219 ('uid=jack,ou=people', '00J6ck1', '00J6ck1'),
1220 ('uid=deep,ou=others,ou=people', '00De3p1', '00De3p1')
1221 ])
1222
1223
1224 @pytest.fixture(scope="function")
1225 def _fixture_for_grace_limit(topo):
1226 pwp = PwPolicyManager(topo.standalone)
1227 orl = pwp.get_pwpolicy_entry(f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
1228 joe = pwp.get_pwpolicy_entry(f'uid=joe,ou=people,{DEFAULT_SUFFIX}')
1229 people = pwp.get_pwpolicy_entry(f'ou=people,{DEFAULT_SUFFIX}')
1230 change_password_with_admin(topo, [
1231 ('uid=orla,ou=dirsec', '000rLb1'),
1232 ('uid=joe,ou=people', '00J0e1'),
1233 ('uid=jack,ou=people', '00J6ck1'),
1234 ('uid=deep,ou=others,ou=people', '00De3p1'),
1235 ('uid=fred', '00fr3d1')
1236 ])
1237 for instance in [orl, joe, people]:
1238 instance.replace_many(('passwordMaxAge', '3'),
1239 ('passwordGraceLimit', '7'),
1240 ('passwordexp', 'on'),
1241 ('passwordwarning', '30'),
1242 ('passwordChange', 'on'))
1243
1244
1245 def _bind_self(topo, user_password_new_pass_list):
1246 """
1247 Will bind password with self.
1248 """
1249 for user, password in user_password_new_pass_list:
1250 real_user = UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}')
1251 conn = real_user.bind(password)
1252
1253
1254 def test_grace_limit_section(topo, policy_setup, _fixture_for_grace_limit):
1255 """Account Lockout and Lockout Duration Section
1256
1257 :id: 288e3756-b560-11ea-9390-8c16451d917b
1258 :setup: Standalone
1259 :steps:
1260 1. Check users have 7 grace login attempts after their password expires
1261 2. Wait for password expiration
1262 3. The the 8th should fail except fred who defaults to global password policy
1263 4. Now try resetting the password before the grace login attempts run out
1264 5. Wait for password expiration
1265 6. Now change the password as the 7th attempt
1266 7. Wait for password expiration
1267 8. First 7 good attempts
1268 9. The the 8th should fail except fred who defaults to global password policy
1269 10. Changing the paswordMaxAge to 0 so expiration is immediate test
1270 11. Modify the users passwords to start the clock of zero
1271 12. PasswordGraceLimit to 0, passwordMaxAge to 3 seconds
1272 13. Modify the users passwords to start the clock
1273 14. Users should be blocked
1274 15. Removing the passwordgracelimit attribute should make it default to 0
1275 :expectedresults:
1276 1. Success
1277 2. Success
1278 3. Fail(ldap.INVALID_CREDENTIALS)
1279 4. Success
1280 5. Success
1281 6. Success
1282 7. Success
1283 8. Success
1284 9. Fail(ldap.INVALID_CREDENTIALS)
1285 10. Success
1286 11. Success
1287 12. Success
1288 13. Success
1289 14. Success
1290 15. Success
1291 """
1292 # Check users have 7 grace login attempts after their password expires
1293 change_password_with_admin(topo, [
1294 ('uid=orla,ou=dirsec', '000rLb2'),
1295 ('uid=joe,ou=people', '00J0e2'),
1296 ('uid=jack,ou=people', '00J6ck2'),
1297 ('uid=deep,ou=others,ou=people', '00De3p2'),
1298 ('uid=fred', '00fr3d2')
1299 ])
1300 # Wait for password expiration
1301 time.sleep(3)
1302 # The the 8th should fail except fred who defaults to global password policy
1303 for _ in range(7):
1304 _bind_self(topo, [
1305 ('uid=orla,ou=dirsec', '000rLb2'),
1306 ('uid=joe,ou=people', '00J0e2'),
1307 ('uid=jack,ou=people', '00J6ck2'),
1308 ('uid=deep,ou=others,ou=people', '00De3p2'),
1309 ('uid=fred', '00fr3d2')
1310 ])
1311 with pytest.raises(ldap.INVALID_CREDENTIALS):
1312 _bind_self(topo, [
1313 ('uid=orla,ou=dirsec', '000rLb2'),
1314 ('uid=joe,ou=people', '00J0e2'),
1315 ('uid=jack,ou=people', '00J6ck2'),
1316 ('uid=deep,ou=others,ou=people', '00De3p2')
1317 ])
1318 _bind_self(topo, [
1319 ('uid=fred', '00fr3d2')
1320 ])
1321 # Now try resetting the password before the grace login attempts run out
1322 change_password_with_admin(topo, [
1323 ('uid=orla,ou=dirsec', '000rLb1'),
1324 ('uid=joe,ou=people', '00J0e1'),
1325 ('uid=jack,ou=people', '00J6ck1'),
1326 ('uid=deep,ou=others,ou=people', '00De3p1'),
1327 ('uid=fred', '00fr3d1')
1328 ])
1329 # Wait for password expiration
1330 time.sleep(3)
1331 # first 6 good attempts
1332 for _ in range(6):
1333 _bind_self(topo, [
1334 ('uid=orla,ou=dirsec', '000rLb1'),
1335 ('uid=joe,ou=people', '00J0e1'),
1336 ('uid=jack,ou=people', '00J6ck1'),
1337 ('uid=deep,ou=others,ou=people', '00De3p1'),
1338 ('uid=fred', '00fr3d1')
1339 ])
1340 # now change the password as the 7th attempt
1341 change_password(topo, [
1342 ('uid=orla,ou=dirsec', '000rLb1', '000rLb2'),
1343 ('uid=joe,ou=people', '00J0e1', '00J0e2'),
1344 ('uid=jack,ou=people', '00J6ck1', '00J6ck2'),
1345 ('uid=deep,ou=others,ou=people', '00De3p1', '00De3p2'),
1346 ('uid=fred', '00fr3d1', '00fr3d2')
1347 ])
1348 # Wait for password expiration
1349 time.sleep(3)
1350 # first 7 good attempts
1351 for _ in range(7):
1352 _bind_self(topo, [
1353 ('uid=orla,ou=dirsec', '000rLb2'),
1354 ('uid=joe,ou=people', '00J0e2'),
1355 ('uid=jack,ou=people', '00J6ck2'),
1356 ('uid=deep,ou=others,ou=people', '00De3p2'),
1357 ('uid=fred', '00fr3d2')
1358 ])
1359 # The the 8th should fail except fred who defaults to global password policy
1360 with pytest.raises(ldap.INVALID_CREDENTIALS):
1361 _bind_self(topo, [
1362 ('uid=orla,ou=dirsec', '000rLb2'),
1363 ('uid=joe,ou=people', '00J0e2'),
1364 ('uid=jack,ou=people', '00J6ck2'),
1365 ('uid=deep,ou=others,ou=people', '00De3p2')
1366 ])
1367 _bind_self(topo, [
1368 ('uid=fred', '00fr3d2')
1369 ])
1370 # Changing the paswordMaxAge to 0 so expiration is immediate test to see
1371 # that the user still has 7 grace login attempts before locked out
1372 for att1 in ['passwordMaxAge', 'passwordwarning']:
1373 _do_transaction_for_pwp(topo, att1, '0')
1374 # Modify the users passwords to start the clock of zero
1375 change_password_with_admin(topo, [
1376 ('uid=orla,ou=dirsec', '000rLb1'),
1377 ('uid=joe,ou=people', '00J0e1'),
1378 ('uid=jack,ou=people', '00J6ck1'),
1379 ('uid=deep,ou=others,ou=people', '00De3p1'),
1380 ('uid=fred', '00fr3d1')
1381 ])
1382 # first 7 good attempts
1383 for _ in range(7):
1384 _bind_self(topo, [
1385 ('uid=orla,ou=dirsec', '000rLb1'),
1386 ('uid=joe,ou=people', '00J0e1'),
1387 ('uid=jack,ou=people', '00J6ck1'),
1388 ('uid=deep,ou=others,ou=people', '00De3p1'),
1389 ('uid=fred', '00fr3d1')
1390 ])
1391 # The the 8th should fail ....
1392 # except fred who defaults to global password policy
1393 with pytest.raises(ldap.INVALID_CREDENTIALS):
1394 _bind_self(topo, [
1395 ('uid=orla,ou=dirsec', '000rLb1'),
1396 ('uid=joe,ou=people', '00J0e1'),
1397 ('uid=jack,ou=people', '00J6ck1'),
1398 ('uid=deep,ou=others,ou=people', '00De3p1')
1399 ])
1400 _bind_self(topo, [
1401 ('uid=fred', '00fr3d1')
1402 ])
1403 # setting the passwordMaxAge to 3 seconds once more
1404 # and the passwordGraceLimit to 0
1405 for att1, att2 in [('passwordMaxAge', '3'), ('passwordGraceLimit', '0')]:
1406 _do_transaction_for_pwp(topo, att1, att2)
1407 # modify the users passwords to start the clock
1408 change_password_with_admin(topo, [
1409 ('uid=orla,ou=dirsec', '000rLb1'),
1410 ('uid=joe,ou=people', '00J0e1'),
1411 ('uid=jack,ou=people', '00J6ck1'),
1412 ('uid=deep,ou=others,ou=people', '00De3p1'),
1413 ('uid=fred', '00fr3d1')
1414 ])
1415 # Users should be blocked
1416 time.sleep(3)
1417 with pytest.raises(ldap.INVALID_CREDENTIALS):
1418 _bind_self(topo, [
1419 ('uid=orla,ou=dirsec', '000rLb1'),
1420 ('uid=joe,ou=people', '00J0e1'),
1421 ('uid=jack,ou=people', '00J6ck1'),
1422 ('uid=deep,ou=others,ou=people', '00De3p1')
1423 ])
1424 _bind_self(topo, [
1425 ('uid=fred', '00fr3d1')
1426 ])
1427 for att1, att2 in [('passwordGraceLimit', '10')]:
1428 _do_transaction_for_pwp(topo, att1, att2)
1429 # removing the passwordgracelimit attribute should make it default to 0
1430 pwp = PwPolicyManager(topo.standalone)
1431 for dn in [f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}',
1432 f'uid=joe,ou=people,{DEFAULT_SUFFIX}',
1433 f'ou=people,{DEFAULT_SUFFIX}']:
1434 pwp.get_pwpolicy_entry(dn).remove_all('passwordGraceLimit')
1435 change_password_with_admin(topo, [
1436 ('uid=orla,ou=dirsec', '000rLb1'),
1437 ('uid=joe,ou=people', '00J0e1'),
1438 ('uid=jack,ou=people', '00J6ck1'),
1439 ('uid=deep,ou=others,ou=people', '00De3p1'),
1440 ('uid=fred', '00fr3d1')
1441 ])
1442 time.sleep(3)
1443 with pytest.raises(ldap.INVALID_CREDENTIALS):
1444 _bind_self(topo, [
1445 ('uid=orla,ou=dirsec', '000rLb1'),
1446 ('uid=joe,ou=people', '00J0e1'),
1447 ('uid=jack,ou=people', '00J6ck1'),
1448 ('uid=deep,ou=others,ou=people', '00De3p1')
1449 ])
1450 _bind_self(topo, [
1451 ('uid=fred', '00fr3d1')
1452 ])
1453
1454
1455 @pytest.fixture(scope="function")
1456 def _fixture_for_additional_cases(topo):
1457 pwp = PwPolicyManager(topo.standalone)
1458 orl = pwp.get_pwpolicy_entry(f'uid=orla,ou=dirsec,{DEFAULT_SUFFIX}')
1459 joe = pwp.get_pwpolicy_entry(f'uid=joe,ou=people,{DEFAULT_SUFFIX}')
1460 people = pwp.get_pwpolicy_entry(f'ou=people,{DEFAULT_SUFFIX}')
1461 change_password_with_admin(topo, [
1462 ('uid=orla,ou=dirsec', '000rLb1'),
1463 ('uid=joe,ou=people', '00J0e1'),
1464 ('uid=jack,ou=people', '00J6ck1'),
1465 ('uid=deep,ou=others,ou=people', '00De3p1'),
1466 ('uid=fred', '00fr3d1'),
1467 ('uid=dbyers,ou=dirsec', 'dby3rs1')
1468 ])
1469 for instance in [orl, joe, people]:
1470 instance.replace_many(('passwordChange', 'on'),
1471 ('passwordwarning', '86400'),
1472 ('passwordGraceLimit', '0'),
1473 ('passwordexp', 'off'),
1474 ('passwordMaxAge', '8640000'),
1475 ('passwordchecksyntax', 'off'))
1476
1477
1478 def test_additional_corner_cases(topo, policy_setup, _fixture_for_additional_cases):
1479 """Additional corner cases
1480
1481 :id: 2f6cec66-b560-11ea-9d7c-8c16451d917b
1482 :setup: Standalone
1483 :steps:
1484 1. Try to change password to one containing spaces
1485 2. Setting password policy to Check password syntax
1486 3. Try to change password to the value of mail, which is trivial. Should get error.
1487 4. No error for fred and dbyers as they are not included in PW policy.
1488 5. Revert changes for fred and dbyers
1489 6. Try to change password to the value of ou, which is trivial. Should get error.
1490 7. No error for fred and dbyers as they are not included in PW policy.
1491 8. Revert changes for fred and dbyers
1492 :expectedresults:
1493 1. Success
1494 2. Success
1495 3. Fail(CONSTRAINT_VIOLATION)
1496 4. Success
1497 5. Success
1498 6. Fail(CONSTRAINT_VIOLATION)
1499 7. Success
1500 8. Success
1501 """
1502 # Try to change password to one containing spaces
1503 change_password(topo, [
1504 ('uid=orla,ou=dirsec', '000rLb1', 'This Password has spaces.'),
1505 ('uid=joe,ou=people', '00J0e1', 'This Password has spaces.'),
1506 ('uid=jack,ou=people', '00J6ck1', 'This Password has spaces.'),
1507 ('uid=fred', '00fr3d1', 'This Password has spaces.'),
1508 ('uid=deep,ou=others,ou=people', '00De3p1', 'This Password has spaces.'),
1509 ('uid=dbyers,ou=dirsec', 'dby3rs1', 'This Password has spaces.')
1510 ])
1511 change_password(topo, [
1512 ('uid=orla,ou=dirsec', 'This Password has spaces.', '000rLb1'),
1513 ('uid=joe,ou=people', 'This Password has spaces.', '00j0e1'),
1514 ('uid=jack,ou=people', 'This Password has spaces.', '00j6ck1'),
1515 ('uid=fred', 'This Password has spaces.', '00fr3d1'),
1516 ('uid=deep,ou=others,ou=people', 'This Password has spaces.', '00de3p1'),
1517 ('uid=dbyers,ou=dirsec', 'This Password has spaces.', 'dby3rs1')
1518 ])
1519 # Setting password policy to Check password syntax
1520 for attr, para in [('passwordchecksyntax', 'on'), ('passwordminlength', '5')]:
1521 _do_transaction_for_pwp(topo, attr, para)
1522 # Try to change password to the value of mail, which is trivial. Should get error.
1523 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
1524 change_password(topo, [
1525 ('uid=orla,ou=dirsec', '000rLb1', '[email protected]'),
1526 ('uid=joe,ou=people', '00j0e1', '[email protected]'),
1527 ('uid=jack,ou=people', '00j6ck1', '[email protected]'),
1528 ('uid=deep,ou=others,ou=people', '00de3p1', '[email protected]')
1529 ])
1530 # No error for fred and dbyers as they are not included in PW policy.
1531 change_password(topo, [
1532 ('uid=fred', '00fr3d1', '[email protected]'),
1533 ('uid=dbyers,ou=dirsec', 'dby3rs1', '[email protected]')
1534 ])
1535 # Revert changes for fred and dbyers
1536 change_password(topo, [
1537 ('uid=fred', '[email protected]', '00fr3d1'),
1538 ('uid=dbyers,ou=dirsec', '[email protected]', 'dby3rs1')
1539 ])
1540 # Creating OUs.
1541 for user, new_ou in [
1542 ('uid=orla,ou=dirsec', 'dirsec'),
1543 ('uid=joe,ou=people', 'people'),
1544 ('uid=jack,ou=people', 'people'),
1545 ('uid=deep,ou=others,ou=people', 'others'),
1546 ('uid=dbyers,ou=dirsec', 'dirsec')
1547 ]:
1548 UserAccount(topo.standalone, f'{user},{DEFAULT_SUFFIX}').add('ou', new_ou)
1549 # Try to change password to the value of ou, which is trivial. Should get error.
1550 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
1551 change_password(topo, [
1552 ('uid=orla,ou=dirsec', '000rLb1', 'dirsec'),
1553 ('uid=joe,ou=people', '00j0e1', 'people'),
1554 ('uid=jack,ou=people', '00j6ck1', 'people'),
1555 ('uid=deep,ou=others,ou=people', '00de3p1', 'others')
1556 ])
1557 # No error for byers as it is not included in PW policy.
1558 change_password(topo, [('uid=dbyers,ou=dirsec', 'dby3rs1', 'dirsec')])
1559 # Revert changes for dbyers
1560 change_password_with_admin(topo, [
1561 ('uid=fred', '00fr3d1'),
1562 ('uid=dbyers,ou=dirsec', 'dby3rs1')
1563 ])
1564
1565
1566 def test_get_pwpolicy_cn_with_quotes(topology_m1, policy_qoutes_setup):
1567 """Test that that we can get pwpolicy when
1568 cn attr includes quotes
1569
1570 :id: 5d360c40-2466-4042-bf99-14d2f68f9d66
1571 :setup: Standalone
1572 :steps:
1573 1. Configure a custom subtree pwpolicy
1574 2. Try to get the unusual subtree pwpolicy
1575 :expectedresults:
1576 1. Success
1577 2. Success
1578 """
1579
1580 # Try to get the unusual subtree pwpolicy
1581 people = policy_qoutes_setup.get_pwpolicy_entry(f'ou=people,{DEFAULT_SUFFIX}')
1582 people.replace('passwordhistory', 'off')
1583 assert people.get_attr_val_utf8('passwordhistory') == 'off'
1584
1585 def test_pwpolicy_list(topo, request):
1586 """Verify duplicate local password policies are not listed when
1587 all local password are listed
1588
1589 :id: 480a3fae-8c0e-4033-806e-03bc572bf3df
1590 :setup: Standalone
1591 :steps:
1592 1. Create a sub suffix
1593 2. Verify sub suffix OU exists
1594 3. Create pwp on sub suffix
1595 4. List all local pwps
1596 5. Verify no duplicates
1597 :expectedresults:
1598 1. Success
1599 2. Success
1600 3. Success
1601 4. Success
1602 5. Success
1603 """
1604 inst = topo.standalone
1605
1606 # Create a sub suffix
1607 SUB_SUFFIX = 'dc=testSuffix,dc=example,dc=com'
1608 props = {
1609 'cn': 'testSuffix',
1610 'nsslapd-suffix': SUB_SUFFIX,
1611 }
1612 be = Backend(topo.standalone)
1613 backend_entry = be.create(properties=props)
1614 backend_entry.create_sample_entries('001004002')
1615
1616 # Verify OU exists
1617 ous = OrganizationalUnits(inst, SUB_SUFFIX)
1618 people = ous.get("People")
1619 assert people.exists()
1620
1621 # Create subtree pwp on sub suffix OU
1622 policy_props = {
1623 'passwordMustChange': 'off',
1624 'passwordExp': 'off',
1625 'passwordMinAge': '0',
1626 'passwordChange': 'off',
1627 'passwordStorageScheme': 'ssha',
1628 'passwordminlength': '6'
1629 }
1630 pwp = PwPolicyManager(topo.standalone)
1631 pwp.create_subtree_policy(people.dn, policy_props)
1632 subtree_policy = pwp.get_pwpolicy_entry(people.dn)
1633 assert subtree_policy.get_attr_val_utf8('passwordminlength') == '6'
1634
1635 # Capture policy listing
1636 args = FakeArgs()
1637 args.suffix = False
1638 args.json = False
1639 args.verbose = False
1640 args.DN = None
1641
1642 topo.logcap.flush()
1643 list_policies(inst, None, topo.logcap.log, args)
1644 logged_output = []
1645 for rec in topo.logcap.outputs:
1646 msg = rec.getMessage()
1647 for line in msg.splitlines():
1648 if line.strip():
1649 logged_output.append(line)
1650
1651 # Verify there are no duplicates reported
1652 assert len(logged_output) == len(set(logged_output))
1653 topo.logcap.flush()
1654
1655 # Cleanup
1656 def fin():
1657 try:
1658 del_local_policy(inst, None, topo.logcap.log, _cli_args([people.dn]))
1659 except Exception:
1660 pass
1661 try:
1662 people.delete()
1663 except Exception:
1664 pass
1665 try:
1666 backend_entry.delete()
1667 except Exception:
1668 pass
1669
1670 request.addfinalizer(fin)
1671
1672 def test_duplicate_pwpolicy(topo, request):
1673 """Verify that duplicate local password policies are not created
1674 or listed for subtree and user password policies, and that updates
1675 correctly modify existing policy entries.
1676
1677 :id: 42847a30-5d86-489c-af70-f6cc361a288b
1678 :setup: Standalone
1679 :steps:
1680 1. Ensure OU exists
1681 2. Create a subtree pwp on ou=people
1682 3. Attempt to create the same subtree pwp again
1683 4. Update the existing subtree pwp with new attributes
1684 5. List all local pwps and verify no duplicates exist
1685 6. Delete subtree pwp
1686 7. Create a test user under ou=people
1687 8. Create a user pwp for the test user
1688 9. Attempt to create the same user pwp again
1689 10. Update the existing user pwp with new attributes
1690 11. List all local pwps and verify no duplicates exist
1691 :expectedresults:
1692 1. Success
1693 2. Success
1694 3. Duplicate subtree pwp returns a no change message
1695 4. Subtree pwp entry is updated
1696 5. No duplicate pwp entries
1697 6. Success
1698 7. Success
1699 8. Success
1700 9. Duplicate user pwp returns a no change message
1701 10. User pwp entry is updated
1702 11. No duplicate pwp entries
1703 """
1704 inst = topo.standalone
1705
1706 # Verify OU exists
1707 ous = OrganizationalUnits(inst, DEFAULT_SUFFIX)
1708 people = ous.get("People")
1709 assert people.exists()
1710
1711 # Add subtree pwp
1712 topo.logcap.flush()
1713 create_subtree_policy(inst, None, topo.logcap.log, _cli_args([people.dn]))
1714 assert topo.logcap.contains("Successfully created new password policy")
1715
1716 # Try to add the same pwp again
1717 topo.logcap.flush()
1718 create_subtree_policy(inst, None, topo.logcap.log, _cli_args([people.dn]))
1719 assert topo.logcap.contains("Password policy is already up to date")
1720
1721 # Update an existing subtree pwp
1722 topo.logcap.flush()
1723 create_subtree_policy(inst, None, topo.logcap.log, _cli_args([people.dn], pwdchange='on', pwdlockout='on'))
1724 assert topo.logcap.contains("Successfully updated password policy")
1725
1726 # Verify there are no duplicates listed
1727 topo.logcap.flush()
1728 list_policies(inst, None, topo.logcap.log, _cli_args(None))
1729 _assert_no_duplicate_in_logs(topo.logcap)
1730
1731 # Delete subtree pwp
1732 topo.logcap.flush()
1733 del_local_policy(inst, None, topo.logcap.log, _cli_args([people.dn]))
1734 assert topo.logcap.contains("Successfully deleted subtree policy")
1735
1736 # Create test user
1737 test_user = create_user(inst, 'testuser', 'test user', 'User', 'Test', 'Secret', '1234', "ou=people")
1738
1739 # Add user pwp
1740 topo.logcap.flush()
1741 create_user_policy(inst, None, topo.logcap.log, _cli_args([test_user.dn]))
1742 assert topo.logcap.contains("Successfully created new password policy")
1743
1744 # Try add the same pwp again
1745 topo.logcap.flush()
1746 create_user_policy(inst, None, topo.logcap.log, _cli_args([test_user.dn]))
1747 assert topo.logcap.contains("Password policy is already up to date")
1748
1749 # Update an existing user pwp
1750 topo.logcap.flush()
1751 create_user_policy(inst, None, topo.logcap.log, _cli_args([test_user.dn], pwdchange='on', pwdlockout='on'))
1752 assert topo.logcap.contains("Successfully updated password policy")
1753
1754 # Verify there are no duplicates listed
1755 topo.logcap.flush()
1756 list_policies(inst, None, topo.logcap.log, _cli_args(None))
1757 _assert_no_duplicate_in_logs(topo.logcap)
1758
1759 # Cleanup
1760 def fin():
1761 try:
1762 del_local_policy(inst, None, topo.logcap.log, _cli_args([test_user.dn]))
1763 test_user.delete()
1764 except Exception:
1765 pass
1766
1767 request.addfinalizer(fin)
1768
1769 def test_subtree_pwpolicy_cos_repair(topo, request):
1770 """Verify that a missing or corrupted CoS entry is repaired when
1771 create_subtree_policy() is run again.
1772
1773 :id: da15d1d9-5e45-4af1-9d5d-9db93ef0f552
1774 :setup: Standalone
1775 :steps:
1776 1. Ensure OU exists
1777 2. Create subtree password policy
1778 3. Manually delete the related CoS template entry
1779 4. Run create_subtree_policy again
1780 5. Verify CoS entry is recreated
1781 6. Verify repair/update status is reported
1782 :expectedresults:
1783 1. Success
1784 2. Success
1785 3. CoS entry deleted
1786 4. Policy command runs successfully
1787 5. CoS entry exists again
1788 6. Repair/update message reported
1789 """
1790 inst = topo.standalone
1791
1792 # Verify OU exists
1793 ous = OrganizationalUnits(inst, DEFAULT_SUFFIX)
1794 people = ous.get("People")
1795 assert people.exists()
1796
1797 # Add subtree pwp
1798 topo.logcap.flush()
1799 create_subtree_policy(inst, None, topo.logcap.log, _cli_args([people.dn]))
1800 assert topo.logcap.contains("Successfully created new password policy")
1801
1802 # Verify the pwp subtree container exists
1803 pwp_container = nsContainer(inst, 'cn=nsPwPolicyContainer,%s' % people.dn)
1804 assert pwp_container.exists()
1805
1806 # Break the pwp cos chain by deleting the cos template
1807 cos_templates = CosTemplates(inst, pwp_container.dn)
1808 cos_template = cos_templates.get('cn=nsPwTemplateEntry,%s' % people.dn)
1809 assert cos_template.exists()
1810 cos_template.delete()
1811 assert not cos_template.exists()
1812
1813 # Create a subtree pwp to repair the broken pwp CoS chain
1814 topo.logcap.flush()
1815 create_subtree_policy(inst, None, topo.logcap.log, _cli_args([people.dn]))
1816 assert topo.logcap.contains("Successfully updated password policy")
1817
1818 cos_template = cos_templates.get('cn=nsPwTemplateEntry,%s' % people.dn)
1819 assert cos_template.exists()
1820
1821 # Cleanup
1822 def fin():
1823 try:
1824 del_local_policy(inst, None, topo.logcap.log, _cli_args([people.dn]))
1825 except Exception:
1826 pass
1827
1828 request.addfinalizer(fin)
1829
1830
1831 if __name__ == "__main__":
1832 CURRENT_FILE = os.path.realpath(__file__)
1833 pytest.main("-s -v %s" % CURRENT_FILE)