Debian Codegraph @

dirsrvtests/tests/suites/password/pwdPolicy_temporary_password_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2016 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8 #
9 import pytest
10 from lib389.tasks import *
11 from lib389.utils import *
12 import pdb
13 from test389.topologies import topology_st
14 from lib389.pwpolicy import PwPolicyManager
15 from lib389.idm.user import UserAccount, UserAccounts, TEST_USER_PROPERTIES
16 from lib389.idm.organizationalunit import OrganizationalUnits
17 from lib389._constants import (DEFAULT_SUFFIX, DN_DM, PASSWORD)
18
19 pytestmark = pytest.mark.tier1
20
21 OU_PEOPLE = 'ou=people,{}'.format(DEFAULT_SUFFIX)
22 TEST_USER_NAME = 'simplepaged_test'
23 TEST_USER_DN = 'uid={},{}'.format(TEST_USER_NAME, OU_PEOPLE)
24 TEST_USER_PWD = 'simplepaged_test'
25 PW_POLICY_CONT_USER = 'cn="cn=nsPwPolicyEntry,uid=simplepaged_test,' \
26 'ou=people,dc=example,dc=com",' \
27 'cn=nsPwPolicyContainer,ou=people,dc=example,dc=com'
28 PW_POLICY_CONT_PEOPLE = 'cn="cn=nsPwPolicyEntry,' \
29 'ou=people,dc=example,dc=com",' \
30 'cn=nsPwPolicyContainer,ou=people,dc=example,dc=com'
31
32 logging.getLogger(__name__).setLevel(logging.INFO)
33 log = logging.getLogger(__name__)
34
35
36 @pytest.fixture(scope="module")
37 def test_user(topology_st, request):
38 """User for binding operation
39
40 :id: test-user-fixture
41 """
42 topology_st.standalone.config.set('nsslapd-auditlog-logging-enabled', 'on')
43 log.info('Adding test user {}')
44 users = UserAccounts(topology_st.standalone, OU_PEOPLE, rdn=None)
45 user_props = TEST_USER_PROPERTIES.copy()
46 user_props.update({'uid': TEST_USER_NAME, 'userpassword': TEST_USER_PWD})
47 try:
48 user = users.create(properties=user_props)
49 except:
50 pass # debug only
51
52 USER_ACI = '(targetattr="*")(version 3.0; acl "pwp test"; allow (all) userdn="ldap:///%s";)' % user.dn
53 ous = OrganizationalUnits(topology_st.standalone, DEFAULT_SUFFIX)
54 ou_people = ous.get('people')
55 ou_people.add('aci', USER_ACI)
56
57 def fin():
58 log.info('Deleting user {}'.format(user.dn))
59 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
60
61 request.addfinalizer(fin)
62 return user
63
64 def test_global_tpr_maxuse_1(topology_st, test_user, request):
65 """Test global TPR policy : passwordTPRMaxUse
66 Test that after passwordTPRMaxUse failures to bind
67 additional bind with valid password are failing with CONSTRAINT_VIOLATION
68
69 :id: d1b38436-806c-4671-8ccf-c8fdad21f034
70 :customerscenario: False
71 :setup: Standalone instance
72 :steps:
73 1. Enable passwordMustChange
74 2. Set passwordTPRMaxUse=5
75 3. Set passwordMaxFailure to a higher value to not disturb the test
76 4. Bind with a wrong password passwordTPRMaxUse times and check INVALID_CREDENTIALS
77 5. Check that passwordTPRRetryCount got to the limit (5)
78 6. Bind with a wrong password (CONSTRAINT_VIOLATION)
79 and check passwordTPRRetryCount overpass the limit by 1 (6)
80 7. Bind with a valid password 5 times and check CONSTRAINT_VIOLATION
81 and check passwordTPRRetryCount overpass the limit by 1 (6)
82 8. Reset password policy configuration
83 :expectedresults:
84 1. Success
85 2. Success
86 3. Success
87 4. Success
88 5. Success
89 6. Success
90 7. Success
91 8. Success
92 """
93
94 try_tpr_failure = 5
95 # Set password policy config, passwordMaxFailure being higher than
96 # passwordTPRMaxUse so that TPR is enforced first
97 topology_st.standalone.config.replace('passwordMustChange', 'on')
98 topology_st.standalone.config.replace('passwordMaxFailure', str(try_tpr_failure + 20))
99 topology_st.standalone.config.replace('passwordTPRMaxUse', str(try_tpr_failure))
100 time.sleep(.5)
101
102 # Reset user's password
103 our_user = UserAccount(topology_st.standalone, TEST_USER_DN)
104 our_user.replace('userpassword', PASSWORD)
105 time.sleep(.5)
106
107 # look up to passwordTPRMaxUse with failing
108 # bind to check that the limits of TPR are enforced
109 for i in range(try_tpr_failure):
110 # Bind as user with a wrong password
111 with pytest.raises(ldap.INVALID_CREDENTIALS):
112 our_user.rebind('wrong password')
113 time.sleep(.5)
114
115 # Check that pwdReset is TRUE
116 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
117 #assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
118
119 # Check that pwdTPRReset is TRUE
120 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
121 assert our_user.get_attr_val_utf8('pwdTPRUseCount') == str(i+1)
122 log.info("%dth failing bind (INVALID_CREDENTIALS) => pwdTPRUseCount = %d" % (i+1, i+1))
123
124
125 # Now the #failures reached passwordTPRMaxUse
126 # Check that pwdReset is TRUE
127 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
128 #assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
129
130 # Check that pwdTPRReset is TRUE
131 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
132 assert our_user.get_attr_val_utf8('pwdTPRUseCount') == str(try_tpr_failure)
133 log.info("last failing bind (INVALID_CREDENTIALS) => pwdTPRUseCount = %d" % (try_tpr_failure))
134
135 # Bind as user with wrong password --> ldap.CONSTRAINT_VIOLATION
136 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
137 our_user.rebind("wrong password")
138 time.sleep(.5)
139
140 # Check that pwdReset is TRUE
141 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
142 #assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
143
144 # Check that pwdTPRReset is TRUE
145 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
146 assert our_user.get_attr_val_utf8('pwdTPRUseCount') == str(try_tpr_failure + 1)
147 log.info("failing bind (CONSTRAINT_VIOLATION) => pwdTPRUseCount = %d" % (try_tpr_failure + i))
148
149 # Now check that all next attempts with correct password are all in LDAP_CONSTRAINT_VIOLATION
150 # and passwordTPRRetryCount remains unchanged
151 # account is now similar to locked
152 for i in range(10):
153 # Bind as user with valid password
154 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
155 our_user.rebind(PASSWORD)
156 time.sleep(.5)
157
158 # Check that pwdReset is TRUE
159 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
160 #assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
161
162 # Check that pwdTPRReset is TRUE
163 # pwdTPRUseCount keeps increasing
164 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
165 assert our_user.get_attr_val_utf8('pwdTPRUseCount') == str(try_tpr_failure + i + 2)
166 log.info("Rejected bind (CONSTRAINT_VIOLATION) => pwdTPRUseCount = %d" % (try_tpr_failure + i + 2))
167
168
169 def fin():
170 topology_st.standalone.restart()
171 # Reset password policy config
172 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
173 topology_st.standalone.config.replace('passwordMustChange', 'off')
174
175 # Reset user's password
176 our_user.replace('userpassword', TEST_USER_PWD)
177
178
179 request.addfinalizer(fin)
180
181 def test_global_tpr_maxuse_2(topology_st, test_user, request):
182 """Test global TPR policy : passwordTPRMaxUse
183 Test that after less than passwordTPRMaxUse failures to bind
184 additional bind with valid password are successfull
185
186 :id: bd18bf8e-f3c3-4612-9009-500cf558317e
187 :customerscenario: False
188 :setup: Standalone instance
189 :steps:
190 1. Enable passwordMustChange
191 2. Set passwordTPRMaxUse=5
192 3. Set passwordMaxFailure to a higher value to not disturb the test
193 4. Bind with a wrong password less than passwordTPRMaxUse times and check INVALID_CREDENTIALS
194 5. Bind successfully with a valid password 10 times
195 and check passwordTPRRetryCount returns to 0
196 6. Reset password policy configuration
197 :expectedresults:
198 1. Success
199 2. Success
200 3. Success
201 4. Success
202 5. Success
203 6. Success
204 """
205
206 try_tpr_failure = 5
207 # Set password policy config, passwordMaxFailure being higher than
208 # passwordTPRMaxUse so that TPR is enforced first
209 topology_st.standalone.config.replace('passwordMustChange', 'on')
210 topology_st.standalone.config.replace('passwordMaxFailure', str(try_tpr_failure + 20))
211 topology_st.standalone.config.replace('passwordTPRMaxUse', str(try_tpr_failure))
212 time.sleep(.5)
213
214 # Reset user's password
215 our_user = UserAccount(topology_st.standalone, TEST_USER_DN)
216 our_user.replace('userpassword', PASSWORD)
217 time.sleep(.5)
218
219 # Do less than passwordTPRMaxUse failing bind
220 try_tpr_failure = try_tpr_failure - 2
221 for i in range(try_tpr_failure):
222 # Bind as user with a wrong password
223 with pytest.raises(ldap.INVALID_CREDENTIALS):
224 our_user.rebind('wrong password')
225 time.sleep(.5)
226
227 # Check that pwdReset is TRUE
228 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
229 #assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
230
231 # Check that pwdTPRReset is TRUE
232 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
233 assert our_user.get_attr_val_utf8('pwdTPRUseCount') == str(i+1)
234 log.info("%dth failing bind (INVALID_CREDENTIALS) => pwdTPRUseCount = %d" % (i+1, i+1))
235
236
237 # Now the #failures has not reached passwordTPRMaxUse
238 # Check that pwdReset is TRUE
239 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
240 assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
241
242 # Check that pwdTPRReset is TRUE
243 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
244 assert our_user.get_attr_val_utf8('pwdTPRUseCount') == str(try_tpr_failure)
245 log.info("last failing bind (INVALID_CREDENTIALS) => pwdTPRUseCount = %d" % (try_tpr_failure))
246
247 our_user.rebind(PASSWORD)
248 our_user.replace('userpassword', PASSWORD)
249 # give time to update the pwp attributes in the entry
250 time.sleep(.5)
251 # Now check that all next attempts with correct password are successfull
252 # and passwordTPRRetryCount reset to 0
253 for i in range(10):
254 # Bind as user with valid password
255 our_user.rebind(PASSWORD)
256 time.sleep(.5)
257
258 # Check that pwdReset is TRUE
259 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
260 #assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
261
262 # Check that pwdTPRReset is FALSE
263 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'FALSE'
264 #pdb.set_trace()
265 assert not our_user.present('pwdTPRUseCount')
266
267
268 def fin():
269 topology_st.standalone.restart()
270 # Reset password policy config
271 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
272 topology_st.standalone.config.replace('passwordMustChange', 'off')
273
274 # Reset user's password
275 our_user.replace('userpassword', TEST_USER_PWD)
276
277 request.addfinalizer(fin)
278
279 def test_global_tpr_maxuse_3(topology_st, test_user, request):
280 """Test global TPR policy : passwordTPRMaxUse
281 Test that after less than passwordTPRMaxUse failures to bind
282 A bind with valid password is successfull but passwordMustChange
283 does not allow to do a search.
284 Changing the password allows to do a search
285
286 :id: 7fd0301a-781e-4db8-a4bd-7b44e0f04bb6
287 :customerscenario: False
288 :setup: Standalone instance
289 :steps:
290 1. Enable passwordMustChange
291 2. Set passwordTPRMaxUse=5
292 3. Set passwordMaxFailure to a higher value to not disturb the test
293 4. Bind with a wrong password less then passwordTPRMaxUse times and check INVALID_CREDENTIALS
294 5. Bind with the valid password and check SRCH fail (ldap.UNWILLING_TO_PERFORM)
295 because of passwordMustChange
296 6. check passwordTPRRetryCount reset to 0
297 7. Bindd with valid password and reset the password
298 8. Check we can bind again and SRCH succeeds
299 9. Reset password policy configuration
300 :expectedresults:
301 1. Success
302 2. Success
303 3. Success
304 4. Success
305 5. Success
306 6. Success
307 7. Success
308 8. Success
309 9. Success
310 """
311
312 try_tpr_failure = 5
313 # Set password policy config, passwordMaxFailure being higher than
314 # passwordTPRMaxUse so that TPR is enforced first
315 topology_st.standalone.config.replace('passwordMustChange', 'on')
316 topology_st.standalone.config.replace('passwordMaxFailure', str(try_tpr_failure + 20))
317 topology_st.standalone.config.replace('passwordTPRMaxUse', str(try_tpr_failure))
318 time.sleep(.5)
319
320 # Reset user's password
321 our_user = UserAccount(topology_st.standalone, TEST_USER_DN)
322 our_user.replace('userpassword', PASSWORD)
323 # give time to update the pwp attributes in the entry
324 time.sleep(.5)
325
326 # Do less than passwordTPRMaxUse failing bind
327 try_tpr_failure = try_tpr_failure - 2
328 for i in range(try_tpr_failure):
329 # Bind as user with a wrong password
330 with pytest.raises(ldap.INVALID_CREDENTIALS):
331 our_user.rebind('wrong password')
332 time.sleep(.5)
333
334 # Check that pwdReset is TRUE
335 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
336 #assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
337
338 # Check that pwdTPRReset is TRUE
339 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
340 assert our_user.get_attr_val_utf8('pwdTPRUseCount') == str(i+1)
341 log.info("%dth failing bind (INVALID_CREDENTIALS) => pwdTPRUseCount = %d" % (i+1, i+1))
342
343
344 # Now the #failures has not reached passwordTPRMaxUse
345 # Check that pwdReset is TRUE
346 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
347 assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
348
349 # Check that pwdTPRReset is TRUE
350 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
351 assert our_user.get_attr_val_utf8('pwdTPRUseCount') == str(try_tpr_failure)
352 log.info("last failing bind (INVALID_CREDENTIALS) => pwdTPRUseCount = %d" % (try_tpr_failure))
353
354 # Bind as user with valid password
355 our_user.rebind(PASSWORD)
356 time.sleep(.5)
357
358 # We can not do anything else that reset password
359 users = UserAccounts(topology_st.standalone, OU_PEOPLE, rdn=None)
360 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
361 user = users.get(TEST_USER_NAME)
362
363 # Check that pwdReset is TRUE
364 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
365 assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
366
367 # Check that pwdTPRReset is FALSE
368 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
369 assert our_user.get_attr_val_utf8('pwdTPRUseCount') == str(try_tpr_failure + 1)
370
371 # Now reset the password and check we can do fully use the account
372 our_user.rebind(PASSWORD)
373 our_user.reset_password(TEST_USER_PWD)
374 # give time to update the pwp attributes in the entry
375 time.sleep(.5)
376 our_user.rebind(TEST_USER_PWD)
377 time.sleep(.5)
378 user = users.get(TEST_USER_NAME)
379
380
381 def fin():
382 topology_st.standalone.restart()
383 # Reset password policy config
384 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
385 topology_st.standalone.config.replace('passwordMustChange', 'off')
386
387 # Reset user's password
388 our_user.replace('userpassword', TEST_USER_PWD)
389
390 request.addfinalizer(fin)
391
392 def test_global_tpr_maxuse_4(topology_st, test_user, request):
393 """Test global TPR policy : passwordTPRMaxUse
394 Test that a TPR attribute passwordTPRMaxUse
395 can be updated by DM but not the by user itself
396
397 :id: ee698277-9c4e-4f58-8f57-158a6d966fe6
398 :customerscenario: False
399 :setup: Standalone instance
400 :steps:
401 1. Enable passwordMustChange
402 2. Set passwordTPRMaxUse=5
403 3. Set passwordMaxFailure to a higher value to not disturb the test
404 4. Create a user without specific rights to update passwordTPRMaxUse
405 5. Reset user password
406 6. Do 3 failing (bad password) user authentication -> INVALID_CREDENTIALS
407 7. Check that pwdTPRUseCount==3
408 8. Bind as user and reset its password
409 9. Check that user can not update pwdTPRUseCount => INSUFFICIENT_ACCESS
410 10. Check that DM can update pwdTPRUseCount
411 :expectedresults:
412 1. Success
413 2. Success
414 3. Success
415 4. Success
416 5. Success
417 6. INVALID_CREDENTIALS
418 7. Success
419 8. Success
420 9. INSUFFICIENT_ACCESS
421 10. Success
422 """
423
424 try_tpr_failure = 5
425 USER_NO_ACI_NAME = 'user_no_aci'
426 USER_NO_ACI_DN = 'uid={},{}'.format(USER_NO_ACI_NAME, OU_PEOPLE)
427 USER_NO_ACI_PWD = 'user_no_aci'
428 # Set password policy config, passwordMaxFailure being higher than
429 # passwordTPRMaxUse so that TPR is enforced first
430 topology_st.standalone.config.replace('passwordMustChange', 'on')
431 topology_st.standalone.config.replace('passwordMaxFailure', str(try_tpr_failure + 20))
432 topology_st.standalone.config.replace('passwordTPRMaxUse', str(try_tpr_failure))
433 time.sleep(.5)
434
435 # create user account (without aci granting write rights)
436 users = UserAccounts(topology_st.standalone, OU_PEOPLE, rdn=None)
437 user_props = TEST_USER_PROPERTIES.copy()
438 user_props.update({'uid': USER_NO_ACI_NAME, 'userpassword': USER_NO_ACI_PWD})
439 try:
440 user = users.create(properties=user_props)
441 except:
442 pass # debug only
443
444 # Reset user's password
445 user.replace('userpassword', PASSWORD)
446 time.sleep(.5)
447
448 # Do less than passwordTPRMaxUse failing bind
449 try_tpr_failure = try_tpr_failure - 2
450 for i in range(try_tpr_failure):
451 # Bind as user with a wrong password
452 with pytest.raises(ldap.INVALID_CREDENTIALS):
453 user.rebind('wrong password')
454 time.sleep(.5)
455
456 # Check that pwdReset is TRUE
457 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
458 #assert user.get_attr_val_utf8('pwdReset') == 'TRUE'
459
460 # Check that pwdTPRReset is TRUE
461 assert user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
462 assert user.get_attr_val_utf8('pwdTPRUseCount') == str(i+1)
463 log.info("%dth failing bind (INVALID_CREDENTIALS) => pwdTPRUseCount = %d" % (i+1, i+1))
464
465
466 # Now the #failures has not reached passwordTPRMaxUse
467 # Check that pwdReset is TRUE
468 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
469 assert user.get_attr_val_utf8('pwdReset') == 'TRUE'
470
471 # Check that pwdTPRReset is TRUE
472 assert user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
473 assert user.get_attr_val_utf8('pwdTPRUseCount') == str(try_tpr_failure)
474 log.info("last failing bind (INVALID_CREDENTIALS) => pwdTPRUseCount = %d" % (try_tpr_failure))
475
476 # Bind as user with valid password, reset the password
477 # and do simple search
478 user.rebind(PASSWORD)
479 user.reset_password(USER_NO_ACI_PWD)
480 time.sleep(.5)
481 user.rebind(USER_NO_ACI_PWD)
482 assert user.get_attr_val_utf8('uid')
483 time.sleep(.5)
484
485 # Fail to update pwdTPRUseCount being USER_NO_ACI
486 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
487 user.replace('pwdTPRUseCount', '100')
488 assert user.get_attr_val_utf8('pwdTPRUseCount') != '100'
489
490 # Succeeds to update pwdTPRUseCount being DM
491 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
492 user.replace('pwdTPRUseCount', '100')
493 assert user.get_attr_val_utf8('pwdTPRUseCount') == '100'
494
495 def fin():
496 topology_st.standalone.restart()
497 # Reset password policy config
498 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
499 topology_st.standalone.config.replace('passwordMustChange', 'off')
500
501 # Reset user's password
502 user.delete()
503
504 request.addfinalizer(fin)
505
506 def test_local_tpr_maxuse_5(topology_st, test_user, request):
507 """Test TPR local policy overpass global one: passwordTPRMaxUse
508 Test that after passwordTPRMaxUse failures to bind
509 additional bind with valid password are failing with CONSTRAINT_VIOLATION
510
511 :id: c3919707-d804-445a-8754-8385b1072c42
512 :customerscenario: False
513 :setup: Standalone instance
514 :steps:
515 1. Global password policy Enable passwordMustChange
516 2. Global password policy Set passwordTPRMaxUse=5
517 3. Global password policy Set passwordMaxFailure to a higher value to not disturb the test
518 4. Local password policy Enable passwordMustChange
519 5. Local password policy Set passwordTPRMaxUse=10 (higher than global)
520 6. Bind with a wrong password 10 times and check INVALID_CREDENTIALS
521 7. Check that passwordTPRUseCount got to the limit (5)
522 8. Bind with a wrong password (CONSTRAINT_VIOLATION)
523 and check passwordTPRUseCount overpass the limit by 1 (11)
524 9. Bind with a valid password 10 times and check CONSTRAINT_VIOLATION
525 and check passwordTPRUseCount increases
526 10. Reset password policy configuration and remove local password from user
527 :expectedresults:
528 1. Success
529 2. Success
530 3. Success
531 4. Success
532 5. Success
533 6. Success
534 7. Success
535 8. Success
536 9. Success
537 10. Success
538 """
539
540 global_tpr_maxuse = 5
541 # Set global password policy config, passwordMaxFailure being higher than
542 # passwordTPRMaxUse so that TPR is enforced first
543 topology_st.standalone.config.replace('passwordMustChange', 'on')
544 topology_st.standalone.config.replace('passwordMaxFailure', str(global_tpr_maxuse + 20))
545 topology_st.standalone.config.replace('passwordTPRMaxUse', str(global_tpr_maxuse))
546 time.sleep(.5)
547
548 local_tpr_maxuse = global_tpr_maxuse + 5
549 # Reset user's password with a local password policy
550 # that has passwordTPRMaxUse higher than global
551 #our_user = UserAccount(topology_st.standalone, TEST_USER_DN)
552 subprocess.call(['%s/dsconf' % topology_st.standalone.get_sbin_dir(),
553 '-D',
554 '%s' % DN_DM,
555 '-w',
556 '%s' % PASSWORD,
557 'slapd-standalone1',
558 'localpwp',
559 'adduser',
560 test_user.dn])
561 subprocess.call(['%s/dsconf' % topology_st.standalone.get_sbin_dir(),
562 '-D',
563 '%s' % DN_DM,
564 '-w',
565 '%s' % PASSWORD,
566 'slapd-standalone1',
567 'localpwp',
568 'set',
569 '--pwptprmaxuse',
570 str(local_tpr_maxuse),
571 '--pwdmustchange',
572 'on',
573 test_user.dn])
574 test_user.replace('userpassword', PASSWORD)
575 time.sleep(.5)
576
577 # look up to passwordTPRMaxUse with failing
578 # bind to check that the limits of TPR are enforced
579 for i in range(local_tpr_maxuse):
580 # Bind as user with a wrong password
581 with pytest.raises(ldap.INVALID_CREDENTIALS):
582 test_user.rebind('wrong password')
583 time.sleep(.5)
584
585 # Check that pwdReset is TRUE
586 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
587 #assert test_user.get_attr_val_utf8('pwdReset') == 'TRUE'
588
589 # Check that pwdTPRReset is TRUE
590 assert test_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
591 assert test_user.get_attr_val_utf8('pwdTPRUseCount') == str(i+1)
592 log.info("%dth failing bind (INVALID_CREDENTIALS) => pwdTPRUseCount = %d" % (i+1, i+1))
593
594
595 # Now the #failures reached passwordTPRMaxUse
596 # Check that pwdReset is TRUE
597 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
598
599 # Check that pwdTPRReset is TRUE
600 assert test_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
601 assert test_user.get_attr_val_utf8('pwdTPRUseCount') == str(local_tpr_maxuse)
602 log.info("last failing bind (INVALID_CREDENTIALS) => pwdTPRUseCount = %d" % (local_tpr_maxuse))
603
604 # Bind as user with wrong password --> ldap.CONSTRAINT_VIOLATION
605 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
606 test_user.rebind("wrong password")
607 time.sleep(.5)
608
609 # Check that pwdReset is TRUE
610 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
611
612 # Check that pwdTPRReset is TRUE
613 assert test_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
614 assert test_user.get_attr_val_utf8('pwdTPRUseCount') == str(local_tpr_maxuse + 1)
615 log.info("failing bind (CONSTRAINT_VIOLATION) => pwdTPRUseCount = %d" % (local_tpr_maxuse + i))
616
617 # Now check that all next attempts with correct password are all in LDAP_CONSTRAINT_VIOLATION
618 # and passwordTPRRetryCount remains unchanged
619 # account is now similar to locked
620 for i in range(10):
621 # Bind as user with valid password
622 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
623 test_user.rebind(PASSWORD)
624 time.sleep(.5)
625
626 # Check that pwdReset is TRUE
627 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
628
629 # Check that pwdTPRReset is TRUE
630 # pwdTPRUseCount keeps increasing
631 assert test_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
632 assert test_user.get_attr_val_utf8('pwdTPRUseCount') == str(local_tpr_maxuse + i + 2)
633 log.info("Rejected bind (CONSTRAINT_VIOLATION) => pwdTPRUseCount = %d" % (local_tpr_maxuse + i + 2))
634
635
636 def fin():
637 topology_st.standalone.restart()
638 # Reset password policy config
639 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
640 topology_st.standalone.config.replace('passwordMustChange', 'off')
641
642 # Remove local password policy from that entry
643 subprocess.call(['%s/dsconf' % topology_st.standalone.get_sbin_dir(),
644 '-D',
645 '%s' % DN_DM,
646 '-w',
647 '%s' % PASSWORD,
648 'slapd-standalone1',
649 'localpwp',
650 'remove',
651 test_user.dn])
652
653 # Reset user's password
654 test_user.replace('userpassword', TEST_USER_PWD)
655
656
657 request.addfinalizer(fin)
658
659 def test_global_tpr_delayValidFrom_1(topology_st, test_user, request):
660 """Test global TPR policy : passwordTPRDelayValidFrom
661 Test that a TPR password is not valid before reset time +
662 passwordTPRDelayValidFrom
663
664 :id: 8420a348-e765-43ec-82c7-7f75cb4bf913
665 :customerscenario: False
666 :setup: Standalone instance
667 :steps:
668 1. Enable passwordMustChange
669 2. Set passwordTPRDelayValidFrom=10s
670 3. Create a account user
671 4. Reset the password
672 5. Check that Validity is not reached yet
673 pwdTPRValidFrom >= now + passwordTPRDelayValidFrom - 2 (safety)
674 6. Bind with valid password, Fails because of CONSTRAINT_VIOLATION
675 :expectedresults:
676 1. Success
677 2. Success
678 3. Success
679 4. Success
680 5. Success
681 6. Success
682 """
683
684 ValidFrom = 10
685 # Set password policy config, passwordMaxFailure being higher than
686 # passwordTPRMaxUse so that TPR is enforced first
687 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
688 topology_st.standalone.config.replace('passwordMustChange', 'on')
689 topology_st.standalone.config.replace('passwordTPRDelayValidFrom', str(ValidFrom))
690 time.sleep(.5)
691
692 # Reset user's password
693 our_user = UserAccount(topology_st.standalone, TEST_USER_DN)
694 our_user.replace('userpassword', PASSWORD)
695 # give time to update the pwp attributes in the entry
696 time.sleep(.5)
697
698 # Check that pwdReset is TRUE
699 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
700 assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
701
702 # Check that pwdTPRReset is TRUE
703 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
704 now = time.mktime(time.gmtime())
705 log.info("compare pwdTPRValidFrom (%s) vs now (%s)" % (our_user.get_attr_val_utf8('pwdTPRValidFrom'), time.gmtime()))
706 assert (gentime_to_posix_time(our_user.get_attr_val_utf8('pwdTPRValidFrom'))) >= (now + ValidFrom - 2)
707
708 # Bind as user with valid password
709 # But too early compare to ValidFrom
710 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
711 our_user.rebind(PASSWORD)
712
713 def fin():
714 topology_st.standalone.restart()
715 # Reset password policy config
716 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
717 topology_st.standalone.config.replace('passwordMustChange', 'off')
718
719 # Reset user's password
720 our_user.replace('userpassword', TEST_USER_PWD)
721
722 request.addfinalizer(fin)
723
724 def test_global_tpr_delayValidFrom_2(topology_st, test_user, request):
725 """Test global TPR policy : passwordTPRDelayValidFrom
726 Test that a TPR password is valid after reset time +
727 passwordTPRDelayValidFrom
728
729 :id: 8fa9f6f7-9be2-47c0-bf92-d9fe78ddbc34
730 :customerscenario: False
731 :setup: Standalone instance
732 :steps:
733 1. Enable passwordMustChange
734 2. Set passwordTPRDelayValidFrom=6s
735 3. Create a account user
736 4. Reset the password
737 5. Wait for passwordTPRDelayValidFrom=6s
738 6. Bind with valid password, reset password
739 to allow further searches
740 7. Check bound user can search attribute ('uid')
741 :expectedresults:
742 1. Success
743 2. Success
744 3. Success
745 4. Success
746 5. Success
747 6. Success
748 7. Success
749 """
750
751 ValidFrom = 6
752 # Set password policy config, passwordMaxFailure being higher than
753 # passwordTPRMaxUse so that TPR is enforced first
754 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
755 topology_st.standalone.config.replace('passwordMustChange', 'on')
756 topology_st.standalone.config.replace('passwordTPRDelayValidFrom', str(ValidFrom))
757 time.sleep(.5)
758
759 # Reset user's password
760 our_user = UserAccount(topology_st.standalone, TEST_USER_DN)
761 our_user.replace('userpassword', PASSWORD)
762 # give time to update the pwp attributes in the entry
763 time.sleep(.5)
764
765 # Check that pwdReset is TRUE
766 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
767 assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
768
769 # Check that pwdTPRReset is TRUE
770 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
771 now = time.mktime(time.gmtime())
772 log.info("compare pwdTPRValidFrom (%s) vs now (%s)" % (our_user.get_attr_val_utf8('pwdTPRValidFrom'), time.gmtime()))
773 assert (gentime_to_posix_time(our_user.get_attr_val_utf8('pwdTPRValidFrom'))) >= (now + ValidFrom - 2)
774
775 # wait for pwdTPRValidFrom
776 time.sleep(ValidFrom + 1)
777
778 # Bind as user with valid password, reset the password
779 # and do simple search
780 our_user.rebind(PASSWORD)
781 our_user.reset_password(TEST_USER_PWD)
782 our_user.rebind(TEST_USER_PWD)
783 assert our_user.get_attr_val_utf8('uid')
784
785 def fin():
786 topology_st.standalone.restart()
787 # Reset password policy config
788 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
789 topology_st.standalone.config.replace('passwordMustChange', 'off')
790
791 # Reset user's password
792 our_user.replace('userpassword', TEST_USER_PWD)
793
794 request.addfinalizer(fin)
795
796 def test_global_tpr_delayValidFrom_3(topology_st, test_user, request):
797 """Test global TPR policy : passwordTPRDelayValidFrom
798 Test that a TPR attribute passwordTPRDelayValidFrom
799 can be updated by DM but not the by user itself
800
801 :id: c599aea2-bbad-4158-b32e-307e5c6fca2d
802 :customerscenario: False
803 :setup: Standalone instance
804 :steps:
805 1. Enable passwordMustChange
806 2. Set passwordTPRDelayValidFrom=6s
807 3. Create a account user
808 4. Reset the password
809 5. Check pwdReset/pwdTPRReset/pwdTPRValidFrom
810 6. wait for 6s to let the new TPR password being valid
811 7. Bind with valid password, reset password
812 to allow further searches
813 8. Check bound user can search attribute ('uid')
814 9. Bound as user, check user has not the rights to
815 modify pwdTPRValidFrom
816 10. Bound as DM, check user has the right to
817 modify pwdTPRValidFrom
818
819 :expectedresults:
820 1. Success
821 2. Success
822 3. Success
823 4. Success
824 5. Success
825 6. Success
826 7. Success
827 8. Success
828 9. ldap.INSUFFICIENT_ACCESS
829 10. Success
830 """
831
832 ValidFrom = 6
833 USER_NO_ACI_NAME = 'user_no_aci'
834 USER_NO_ACI_DN = 'uid={},{}'.format(USER_NO_ACI_NAME, OU_PEOPLE)
835 USER_NO_ACI_PWD = 'user_no_aci'
836 # Set password policy config
837 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
838 topology_st.standalone.config.replace('passwordMustChange', 'on')
839 topology_st.standalone.config.replace('passwordTPRDelayValidFrom', str(ValidFrom))
840 time.sleep(.5)
841
842 # create user account (without aci granting write rights)
843 users = UserAccounts(topology_st.standalone, OU_PEOPLE, rdn=None)
844 user_props = TEST_USER_PROPERTIES.copy()
845 user_props.update({'uid': USER_NO_ACI_NAME, 'userpassword': USER_NO_ACI_PWD})
846 try:
847 user = users.create(properties=user_props)
848 except:
849 pass # debug only
850
851 # Reset user's password
852 #our_user = UserAccount(topology_st.standalone, USER_NO_ACI_DN)
853 user.replace('userpassword', PASSWORD)
854 # give time to update the pwp attributes in the entry
855 time.sleep(.5)
856
857 # Check that pwdReset is TRUE
858 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
859 assert user.get_attr_val_utf8('pwdReset') == 'TRUE'
860
861 # Check that pwdTPRReset is TRUE
862 assert user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
863 now = time.mktime(time.gmtime())
864 log.info("compare pwdTPRValidFrom (%s) vs now (%s)" % (user.get_attr_val_utf8('pwdTPRValidFrom'), time.gmtime()))
865 assert (gentime_to_posix_time(user.get_attr_val_utf8('pwdTPRValidFrom'))) >= (now + ValidFrom - 2)
866
867 # wait for pwdTPRValidFrom
868 time.sleep(ValidFrom + 1)
869
870 # Bind as user with valid password, reset the password
871 # and do simple search
872 user.rebind(PASSWORD)
873 user.reset_password(USER_NO_ACI_PWD)
874 user.rebind(USER_NO_ACI_PWD)
875 assert user.get_attr_val_utf8('uid')
876
877 # Fail to update pwdTPRValidFrom being USER_NO_ACI
878 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
879 user.replace('pwdTPRValidFrom', '1234567890Z')
880 assert user.get_attr_val_utf8('pwdTPRValidFrom') != '1234567890Z'
881
882 # Succeeds to update pwdTPRValidFrom being DM
883 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
884 user.replace('pwdTPRValidFrom', '1234567890Z')
885 assert user.get_attr_val_utf8('pwdTPRValidFrom') == '1234567890Z'
886
887 def fin():
888 topology_st.standalone.restart()
889 # Reset password policy config
890 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
891 topology_st.standalone.config.replace('passwordMustChange', 'off')
892
893 # delete the no aci entry
894 user.delete()
895
896 request.addfinalizer(fin)
897
898 def test_global_tpr_delayExpireAt_1(topology_st, test_user, request):
899 """Test global TPR policy : passwordTPRDelayExpireAt
900 Test that a TPR password is not valid after reset time +
901 passwordTPRDelayExpireAt
902
903 :id: b98def32-4e30-49fd-893b-8f959ba72b98
904 :customerscenario: False
905 :setup: Standalone instance
906 :steps:
907 1. Enable passwordMustChange
908 2. Set passwordTPRDelayExpireAt=6s
909 3. Create a account user
910 4. Reset the password
911 5. Wait for passwordTPRDelayExpireAt=6s + 2s (safety)
912 6. Bind with valid password should fail with ldap.CONSTRAINT_VIOLATION
913 :expectedresults:
914 1. Success
915 2. Success
916 3. Success
917 4. Success
918 5. Success
919 6. Success
920 """
921
922 ExpireAt = 6
923 # Set password policy config, passwordMaxFailure being higher than
924 # passwordTPRMaxUse so that TPR is enforced first
925 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
926 topology_st.standalone.config.replace('passwordMustChange', 'on')
927 topology_st.standalone.config.replace('passwordTPRMaxUse', str(-1))
928 topology_st.standalone.config.replace('passwordTPRDelayValidFrom', str(-1))
929 topology_st.standalone.config.replace('passwordTPRDelayExpireAt', str(ExpireAt))
930 time.sleep(.5)
931
932 # Reset user's password
933 our_user = UserAccount(topology_st.standalone, TEST_USER_DN)
934 our_user.replace('userpassword', PASSWORD)
935 # give time to update the pwp attributes in the entry
936 time.sleep(.5)
937
938 # Check that pwdReset is TRUE
939 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
940 assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
941
942 # Check that pwdTPRReset is TRUE
943 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
944 now = time.mktime(time.gmtime())
945 log.info("compare pwdTPRExpireAt (%s) vs now (%s)" % (our_user.get_attr_val_utf8('pwdTPRExpireAt'), time.gmtime()))
946 assert (gentime_to_posix_time(our_user.get_attr_val_utf8('pwdTPRExpireAt'))) >= (now + ExpireAt - 2)
947
948 # wait for pwdTPRExpireAt
949 time.sleep(ExpireAt + 2)
950
951 # Bind as user with valid password but too late
952 # for pwdTPRExpireAt
953 # and do simple search
954 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
955 our_user.rebind(PASSWORD)
956
957 def fin():
958 topology_st.standalone.restart()
959 # Reset password policy config
960 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
961 topology_st.standalone.config.replace('passwordMustChange', 'off')
962
963 # Reset user's password
964 our_user.replace('userpassword', TEST_USER_PWD)
965
966 request.addfinalizer(fin)
967
968 def test_global_tpr_delayExpireAt_2(topology_st, test_user, request):
969 """Test global TPR policy : passwordTPRDelayExpireAt
970 Test that a TPR password is valid before reset time +
971 passwordTPRDelayExpireAt
972
973 :id: 9df320de-ebf6-4ed0-a619-51b1a05a560c
974 :customerscenario: False
975 :setup: Standalone instance
976 :steps:
977 1. Enable passwordMustChange
978 2. Set passwordTPRDelayExpireAt=6s
979 3. Create a account user
980 4. Reset the password
981 5. Wait for 1s
982 6. Bind with valid password should succeeds
983 :expectedresults:
984 1. Success
985 2. Success
986 3. Success
987 4. Success
988 5. Success
989 6. Success
990 """
991
992 ExpireAt = 6
993 # Set password policy config, passwordMaxFailure being higher than
994 # passwordTPRMaxUse so that TPR is enforced first
995 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
996 topology_st.standalone.config.replace('passwordMustChange', 'on')
997 topology_st.standalone.config.replace('passwordTPRMaxUse', str(-1))
998 topology_st.standalone.config.replace('passwordTPRDelayValidFrom', str(-1))
999 topology_st.standalone.config.replace('passwordTPRDelayExpireAt', str(ExpireAt))
1000 time.sleep(.5)
1001
1002 # Reset user's password
1003 our_user = UserAccount(topology_st.standalone, TEST_USER_DN)
1004 our_user.replace('userpassword', PASSWORD)
1005 # give time to update the pwp attributes in the entry
1006 time.sleep(.5)
1007
1008 # Check that pwdReset is TRUE
1009 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
1010 assert our_user.get_attr_val_utf8('pwdReset') == 'TRUE'
1011
1012 # Check that pwdTPRReset is TRUE
1013 assert our_user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
1014 now = time.mktime(time.gmtime())
1015 log.info("compare pwdTPRExpireAt (%s) vs now (%s)" % (our_user.get_attr_val_utf8('pwdTPRExpireAt'), time.gmtime()))
1016 assert (gentime_to_posix_time(our_user.get_attr_val_utf8('pwdTPRExpireAt'))) >= (now + ExpireAt - 2)
1017
1018 # wait for 1s
1019 time.sleep(1)
1020
1021 # Bind as user with valid password, reset the password
1022 # and do simple search
1023 our_user.rebind(PASSWORD)
1024 our_user.reset_password(TEST_USER_PWD)
1025 time.sleep(.5)
1026 our_user.rebind(TEST_USER_PWD)
1027 assert our_user.get_attr_val_utf8('uid')
1028
1029 def fin():
1030 topology_st.standalone.restart()
1031 # Reset password policy config
1032 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
1033 topology_st.standalone.config.replace('passwordMustChange', 'off')
1034
1035 # Reset user's password
1036 our_user.replace('userpassword', TEST_USER_PWD)
1037
1038 request.addfinalizer(fin)
1039
1040 def test_global_tpr_delayExpireAt_3(topology_st, test_user, request):
1041 """Test global TPR policy : passwordTPRDelayExpireAt
1042 Test that a TPR attribute passwordTPRDelayExpireAt
1043 can be updated by DM but not the by user itself
1044
1045 :id: 22bb5dd8-d8f6-4484-988e-6de0ef704391
1046 :customerscenario: False
1047 :setup: Standalone instance
1048 :steps:
1049 1. Enable passwordMustChange
1050 2. Set passwordTPRDelayExpireAt=6s
1051 3. Create a account user
1052 4. Reset the password
1053 5. Check pwdReset/pwdTPRReset/pwdTPRValidFrom
1054 6. wait for 1s so that TPR has not expired
1055 7. Bind with valid password, reset password
1056 to allow further searches
1057 8. Check bound user can search attribute ('uid')
1058 9. Bound as user, check user has not the rights to
1059 modify pwdTPRExpireAt
1060 10. Bound as DM, check user has the right to
1061 modify pwdTPRExpireAt
1062
1063 :expectedresults:
1064 1. Success
1065 2. Success
1066 3. Success
1067 4. Success
1068 5. Success
1069 6. Success
1070 7. Success
1071 8. Success
1072 9. ldap.INSUFFICIENT_ACCESS
1073 10. Success
1074 """
1075
1076 ExpireAt = 6
1077 USER_NO_ACI_NAME = 'user_no_aci'
1078 USER_NO_ACI_DN = 'uid={},{}'.format(USER_NO_ACI_NAME, OU_PEOPLE)
1079 USER_NO_ACI_PWD = 'user_no_aci'
1080 # Set password policy config
1081 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
1082 topology_st.standalone.config.replace('passwordMustChange', 'on')
1083 topology_st.standalone.config.replace('passwordTPRDelayValidFrom', str(-1))
1084 topology_st.standalone.config.replace('passwordTPRDelayExpireAt', str(ExpireAt))
1085 topology_st.standalone.config.replace('passwordTPRDelayValidFrom', str(-1))
1086 time.sleep(.5)
1087
1088 # create user account (without aci granting write rights)
1089 users = UserAccounts(topology_st.standalone, OU_PEOPLE, rdn=None)
1090 user_props = TEST_USER_PROPERTIES.copy()
1091 user_props.update({'uid': USER_NO_ACI_NAME, 'userpassword': USER_NO_ACI_PWD})
1092 try:
1093 user = users.create(properties=user_props)
1094 except:
1095 pass # debug only
1096
1097 # Reset user's password
1098 user.replace('userpassword', PASSWORD)
1099 # give time to update the pwp attributes in the entry
1100 time.sleep(.5)
1101
1102 # Check that pwdReset is TRUE
1103 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
1104 assert user.get_attr_val_utf8('pwdReset') == 'TRUE'
1105
1106 # Check that pwdTPRReset is TRUE
1107 assert user.get_attr_val_utf8('pwdTPRReset') == 'TRUE'
1108 now = time.mktime(time.gmtime())
1109 log.info("compare pwdTPRExpireAt (%s) vs now (%s)" % (user.get_attr_val_utf8('pwdTPRExpireAt'), time.gmtime()))
1110 assert (gentime_to_posix_time(user.get_attr_val_utf8('pwdTPRExpireAt'))) >= (now + ExpireAt - 2)
1111
1112 # wait for 1s
1113 time.sleep(1)
1114
1115 # Bind as user with valid password, reset the password
1116 # and do simple search
1117 user.rebind(PASSWORD)
1118 user.reset_password(USER_NO_ACI_PWD)
1119 time.sleep(.5)
1120 user.rebind(USER_NO_ACI_PWD)
1121 assert user.get_attr_val_utf8('uid')
1122 time.sleep(.5)
1123
1124 # Fail to update pwdTPRExpireAt being USER_NO_ACI
1125 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
1126 user.replace('pwdTPRExpireAt', '1234567890Z')
1127 assert user.get_attr_val_utf8('pwdTPRExpireAt') != '1234567890Z'
1128
1129 # Succeeds to update pwdTPRExpireAt being DM
1130 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
1131 user.replace('pwdTPRExpireAt', '1234567890Z')
1132 assert user.get_attr_val_utf8('pwdTPRExpireAt') == '1234567890Z'
1133
1134 def fin():
1135 topology_st.standalone.restart()
1136 # Reset password policy config
1137 topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
1138 topology_st.standalone.config.replace('passwordMustChange', 'off')
1139
1140 # delete the no aci entry
1141 user.delete()
1142
1143 request.addfinalizer(fin)
1144
1145 if __name__ == '__main__':
1146 # Run isolated
1147 # -s for DEBUG mode
1148 CURRENT_FILE = os.path.realpath(__file__)
1149 pytest.main("-s %s" % CURRENT_FILE)