Debian Codegraph @

dirsrvtests/tests/suites/password/pwp_gracel_test.py

raw
1 """
2 # --- BEGIN COPYRIGHT BLOCK ---
3 # Copyright (C) 2020 Red Hat, Inc.
4 # All rights reserved.
5 #
6 # License: GPL (version 3 or any later version).
7 # See LICENSE for details.
8 # --- END COPYRIGHT BLOCK ---
9 """
10
11 import os
12 import pytest
13 from test389.topologies import topology_st as topo
14 from lib389.idm.user import UserAccounts, UserAccount
15 from lib389._constants import DEFAULT_SUFFIX
16 from lib389.config import Config
17 import ldap
18 import time
19
20 pytestmark = pytest.mark.tier1
21
22
23 def test_password_gracelimit_section(topo):
24 """Password grace limit section.
25
26 :id: d6f4a7fa-473b-11ea-8766-8c16451d917c
27 :setup: Standalone
28 :steps:
29 1. Resets the default password policy
30 2. Turning on password expiration, passwordMaxAge: 30 and passwordGraceLimit: 7
31 3. Check users have 7 grace login attempts after their password expires
32 4. Reset the user passwords to start the clock
33 5. The the 8th should fail
34 6. Now try resetting the password before the grace login attempts run out
35 7. Bind 6 times, and on the 7th change the password
36 8. Setting passwordMaxAge: 1 and passwordGraceLimit: 7
37 9. Modify the users passwords to start the clock of zero
38 10. First 7 good attempts, 8th should fail
39 11. Setting the passwordMaxAge to 3 seconds once more and the passwordGraceLimit to 0
40 12. Modify the users passwords to start the clock
41 13. Users should be blocked automatically after 3 second
42 :expectedresults:
43 1. Success
44 2. Success
45 3. Success
46 4. Success
47 5. Success
48 6. Success
49 7. Success
50 8. Success
51 9. Success
52 10. Success
53 11. Success
54 12. Success
55 13. Success
56 """
57 config = Config(topo.standalone)
58 # Resets the default password policy
59 config.replace_many(
60 ('passwordmincategories', '1'),
61 ('passwordStorageScheme', 'CLEAR'))
62 user = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn=None).create_test_user()
63 # Turning on password expiration, passwordMaxAge: 30 and passwordGraceLimit: 7
64 config.replace_many(
65 ('passwordMaxAge', '3'),
66 ('passwordGraceLimit', '7'),
67 ('passwordexp', 'on'),
68 ('passwordwarning', '30'))
69 # Reset the user passwords to start the clock
70 # Check users have 7 grace login attempts after their password expires
71 user.replace('userpassword', '00fr3d1')
72 for _ in range(3):
73 time.sleep(1)
74 user_account = UserAccount(topo.standalone, user.dn)
75 for _ in range(7):
76 conn = user_account.bind('00fr3d1')
77 # The the 8th should fail
78 with pytest.raises(ldap.INVALID_CREDENTIALS):
79 conn = user_account.bind('00fr3d1')
80 # Now try resetting the password before the grace login attempts run out
81 user.replace('userpassword', '00fr3d2')
82 for _ in range(3):
83 time.sleep(1)
84 user_account = UserAccount(topo.standalone, user.dn)
85 # Bind 6 times, and on the 7th change the password
86 for _ in range(6):
87 conn = user_account.bind('00fr3d2')
88 user.replace('userpassword', '00fr3d1')
89 for _ in range(3):
90 time.sleep(1)
91 for _ in range(7):
92 conn = user_account.bind('00fr3d1')
93 with pytest.raises(ldap.INVALID_CREDENTIALS):
94 conn = user_account.bind('00fr3d1')
95 # Setting passwordMaxAge: 1 and passwordGraceLimit: 7
96 config.replace_many(
97 ('passwordMaxAge', '1'),
98 ('passwordwarning', '1'))
99 # Modify the users passwords to start the clock of zero
100 user.replace('userpassword', '00fr3d2')
101 time.sleep(1)
102 # First 7 good attempts, 8th should fail
103 user_account = UserAccount(topo.standalone, user.dn)
104 for _ in range(7):
105 conn = user_account.bind('00fr3d2')
106 with pytest.raises(ldap.INVALID_CREDENTIALS):
107 conn = user_account.bind('00fr3d2')
108 # Setting the passwordMaxAge to 3 seconds once more and the passwordGraceLimit to 0
109 config.replace_many(
110 ('passwordMaxAge', '3'),
111 ('passwordGraceLimit', '0'))
112 # Modify the users passwords to start the clock
113 # Users should be blocked automatically after 3 second
114 user.replace('userpassword', '00fr3d1')
115 for _ in range(3):
116 time.sleep(1)
117 with pytest.raises(ldap.INVALID_CREDENTIALS):
118 conn = user_account.bind('00fr3d1')
119
120
121 if __name__ == "__main__":
122 CURRENT_FILE = os.path.realpath(__file__)
123 pytest.main("-s -v %s" % CURRENT_FILE)