Debian Codegraph @

dirsrvtests/tests/suites/plugins/accpol_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2017 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 import subprocess
11 from lib389.tasks import *
12 from lib389.utils import *
13 from test389.topologies import topology_st, topology_m1c1
14 from lib389.idm.user import (UserAccount, UserAccounts)
15 from lib389.plugins import (AccountPolicyPlugin, AccountPolicyConfig, AccountPolicyConfigs)
16 from lib389.cos import (CosTemplate, CosPointerDefinition)
17 from lib389._constants import (PLUGIN_ACCT_POLICY, DN_PLUGIN, DN_DM, PASSWORD, DEFAULT_SUFFIX,
18 DN_CONFIG, SERVERID_STANDALONE)
19
20 pytestmark = pytest.mark.tier1
21
22 LOCL_CONF = 'cn=AccountPolicy1,ou=people,dc=example,dc=com'
23 TEMPL_COS = 'cn=TempltCoS,ou=people,dc=example,dc=com'
24 DEFIN_COS = 'cn=DefnCoS,ou=people,dc=example,dc=com'
25 ACCPOL_DN = "cn={},{}".format(PLUGIN_ACCT_POLICY, DN_PLUGIN)
26 ACCP_CONF = "{},{}".format(DN_CONFIG, ACCPOL_DN)
27 USER_PASW = 'Secret1234'
28 INVL_PASW = 'Invalid234'
29
30
31 @pytest.fixture(scope="module")
32 def accpol_global(topology_st, request):
33 """Configure Global account policy plugin and restart the server"""
34
35 log.info('Configuring Global account policy plugin, pwpolicy attributes and restarting the server')
36 plugin = AccountPolicyPlugin(topology_st.standalone)
37 try:
38 if DEBUGGING:
39 topology_st.standalone.config.set('nsslapd-auditlog-logging-enabled', 'on')
40 plugin.enable()
41 plugin.set('nsslapd-pluginarg0', ACCP_CONF)
42 accp = AccountPolicyConfig(topology_st.standalone, dn=ACCP_CONF)
43 accp.set('alwaysrecordlogin', 'yes')
44 accp.set('stateattrname', 'lastLoginTime')
45 accp.set('altstateattrname', 'createTimestamp')
46 accp.set('specattrname', 'acctPolicySubentry')
47 accp.set('limitattrname', 'accountInactivityLimit')
48 accp.set('accountInactivityLimit', '12')
49 topology_st.standalone.config.set('passwordexp', 'on')
50 topology_st.standalone.config.set('passwordmaxage', '400')
51 topology_st.standalone.config.set('passwordwarning', '1')
52 topology_st.standalone.config.set('passwordlockout', 'on')
53 topology_st.standalone.config.set('passwordlockoutduration', '5')
54 topology_st.standalone.config.set('passwordmaxfailure', '3')
55 topology_st.standalone.config.set('passwordunlock', 'on')
56 except ldap.LDAPError as e:
57 log.error('Failed to enable Global Account Policy Plugin and Password policy attributes')
58 raise e
59 topology_st.standalone.restart(timeout=10)
60
61 def fin():
62 log.info('Disabling Global accpolicy plugin and removing pwpolicy attrs')
63 try:
64 plugin = AccountPolicyPlugin(topology_st.standalone)
65 plugin.disable()
66 topology_st.standalone.config.set('passwordexp', 'off')
67 topology_st.standalone.config.set('passwordlockout', 'off')
68 except ldap.LDAPError as e:
69 log.error('Failed to disable Global accpolicy plugin, {}'.format(e.message['desc']))
70 assert False
71 topology_st.standalone.restart(timeout=10)
72
73 request.addfinalizer(fin)
74
75
76 @pytest.fixture(scope="module")
77 def accpol_local(topology_st, accpol_global, request):
78 """Configure Local account policy plugin for ou=people subtree and restart the server"""
79
80 log.info('Adding Local account policy plugin configuration entries')
81 try:
82 topology_st.standalone.config.set('passwordmaxage', '400')
83 accp = AccountPolicyConfig(topology_st.standalone, dn=ACCP_CONF)
84 accp.remove_all('accountInactivityLimit')
85 locl_conf = AccountPolicyConfig(topology_st.standalone, dn=LOCL_CONF)
86 locl_conf.create(properties={'cn': 'AccountPolicy1', 'accountInactivityLimit': '10'})
87 cos_template = CosTemplate(topology_st.standalone, dn=TEMPL_COS)
88 cos_template.create(properties={'cn': 'TempltCoS', 'acctPolicySubentry': LOCL_CONF})
89 cos_def = CosPointerDefinition(topology_st.standalone, dn=DEFIN_COS)
90 cos_def.create(properties={
91 'cn': 'DefnCoS',
92 'cosTemplateDn': TEMPL_COS,
93 'cosAttribute': 'acctPolicySubentry default operational-default'})
94 except ldap.LDAPError as e:
95 log.error('Failed to configure Local account policy plugin')
96 log.error('Failed to add entry {}, {}, {}:'.format(LOCL_CONF, TEMPL_COS, DEFIN_COS))
97 raise e
98 topology_st.standalone.restart(timeout=10)
99
100 def fin():
101 log.info('Disabling Local accpolicy plugin and removing pwpolicy attrs')
102 try:
103 topology_st.standalone.plugins.disable(name=PLUGIN_ACCT_POLICY)
104 for entry_dn in [LOCL_CONF, TEMPL_COS, DEFIN_COS]:
105 entry = UserAccount(topology_st.standalone, dn=entry_dn)
106 entry.delete()
107 except ldap.LDAPError as e:
108 log.error('Failed to disable Local accpolicy plugin, {}'.format(e.message['desc']))
109 assert False
110 topology_st.standalone.restart(timeout=10)
111
112 request.addfinalizer(fin)
113
114
115 @pytest.fixture(scope="module")
116 def setup_account_policy_plugin(topology_st):
117 inst = topology_st[0]
118
119 # Enable plugin and restart
120 plugin = AccountPolicyPlugin(inst)
121 plugin.disable()
122 plugin.enable()
123 inst.restart()
124
125 # Add config entry, set alwaysrecordlogin to yes (lastLoginHistorySize defaults to 5)
126 ap_configs = AccountPolicyConfigs(inst)
127 try:
128 ap_config = ap_configs.create(properties={'cn': 'config', 'alwaysrecordlogin': 'yes', })
129 except ldap.ALREADY_EXISTS:
130 ap_config = ap_configs.get('config')
131 ap_config.replace('alwaysrecordlogin', 'yes')
132
133 return ap_config
134
135
136 @pytest.fixture(scope="module")
137 def setup_test_user(topology_st, setup_account_policy_plugin):
138 inst = topology_st[0]
139 USER_PW = 'password'
140
141 # Add a test user entry
142 users = UserAccounts(inst, DEFAULT_SUFFIX)
143 user = users.create_test_user(uid=1000, gid=2000)
144 user.replace('userPassword', USER_PW)
145
146 return user
147
148
149 def pwacc_lock(topology_st, suffix, subtree, userid, nousrs):
150 """Lockout user account by attempting invalid password binds"""
151
152 log.info('Lockout user account by attempting invalid password binds')
153 while (nousrs > 0):
154 usrrdn = '{}{}'.format(userid, nousrs)
155 userdn = 'uid={},{},{}'.format(usrrdn, subtree, suffix)
156 user = UserAccount(topology_st.standalone, dn=userdn)
157 for i in range(3):
158 with pytest.raises(ldap.INVALID_CREDENTIALS):
159 user.bind(INVL_PASW)
160 log.error('No invalid credentials error for User {}'.format(userdn))
161 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
162 user.bind(USER_PASW)
163 log.error('User {} is not locked, expected error 19'.format(userdn))
164 nousrs = nousrs - 1
165 time.sleep(1)
166
167
168 def userpw_reset(topology_st, suffix, subtree, userid, nousrs, bindusr, bindpw, newpasw):
169 """Reset user password"""
170
171 while (nousrs > 0):
172 usrrdn = '{}{}'.format(userid, nousrs)
173 userdn = 'uid={},{},{}'.format(usrrdn, subtree, suffix)
174 user = UserAccount(topology_st.standalone, dn=userdn)
175 log.info('Reset user password for user-{}'.format(userdn))
176 if (bindusr == "DirMgr"):
177 try:
178 user.replace('userPassword', newpasw)
179 except ldap.LDAPError as e:
180 log.error('Unable to reset userPassword for user-{}'.format(userdn))
181 raise e
182 elif (bindusr == "RegUsr"):
183 user_conn = user.bind(bindpw)
184 try:
185 user_conn.replace('userPassword', newpasw)
186 except ldap.LDAPError as e:
187 log.error('Unable to reset userPassword for user-{}'.format(userdn))
188 raise e
189 nousrs = nousrs - 1
190 time.sleep(1)
191
192
193 def nsact_inact(topology_st, suffix, subtree, userid, nousrs, command, expected):
194 """Account activate/in-activate/status using dsidm"""
195
196 log.info('Account activate/in-activate/status using dsidm')
197 while (nousrs > 0):
198 usrrdn = '{}{}'.format(userid, nousrs)
199 userdn = 'uid={},{},{}'.format(usrrdn, subtree, suffix)
200 log.info('Running {} for user {}'.format(command, userdn))
201
202 dsidm_cmd = ['%s/dsidm' % topology_st.standalone.get_sbin_dir(),
203 'slapd-standalone1',
204 '-b', DEFAULT_SUFFIX,
205 'account', command,
206 userdn]
207
208 log.info('Running {} for user {}'.format(dsidm_cmd, userdn))
209 try:
210 output = subprocess.check_output(dsidm_cmd)
211 except subprocess.CalledProcessError as err:
212 output = err.output
213
214 log.info('output: {}'.format(output))
215 assert ensure_bytes(expected) in output
216 nousrs = nousrs - 1
217 time.sleep(1)
218
219
220 def modify_attr(topology_st, base_dn, attr_name, attr_val):
221 """Modify attribute value for a given DN"""
222
223 log.info('Modify attribute value for a given DN')
224 try:
225 entry = UserAccount(topology_st.standalone, dn=base_dn)
226 entry.replace(attr_name, attr_val)
227 except ldap.LDAPError as e:
228 log.error('Failed to replace lastLoginTime attribute for user-{} {}'.format(userdn, e.message['desc']))
229 assert False
230 time.sleep(1)
231
232
233 def check_attr(topology_st, suffix, subtree, userid, nousrs, attr_name):
234 """Check ModifyTimeStamp attribute present for user"""
235
236 log.info('Check ModifyTimeStamp attribute present for user')
237 while (nousrs > 0):
238 usrrdn = '{}{}'.format(userid, nousrs)
239 userdn = 'uid={},{},{}'.format(usrrdn, subtree, suffix)
240 user = UserAccount(topology_st.standalone, dn=userdn)
241 try:
242 user.get_attr_val(attr_name)
243 except ldap.LDAPError as e:
244 log.error('ModifyTimeStamp attribute is not present for user-{} {}'.format(userdn, e.message['desc']))
245 assert False
246 nousrs = nousrs - 1
247
248
249 def add_time_attr(topology_st, suffix, subtree, userid, nousrs, attr_name):
250 """Enable account by replacing lastLoginTime/createTimeStamp/ModifyTimeStamp attribute"""
251
252 new_attr_val = time.strftime("%Y%m%d%H%M%S", time.gmtime()) + 'Z'
253 log.info('Enable account by replacing lastLoginTime/createTimeStamp/ModifyTimeStamp attribute')
254 while (nousrs > 0):
255 usrrdn = '{}{}'.format(userid, nousrs)
256 userdn = 'uid={},{},{}'.format(usrrdn, subtree, suffix)
257 user = UserAccount(topology_st.standalone, dn=userdn)
258 try:
259 user.replace(attr_name, new_attr_val)
260 except ldap.LDAPError as e:
261 log.error('Failed to add/replace {} attribute to-{}, for user-{}'.format(attr_name, new_attr_val, userdn))
262 raise e
263 nousrs = nousrs - 1
264 time.sleep(1)
265 time.sleep(1)
266
267
268 def modusr_attr(topology_st, suffix, subtree, userid, nousrs, attr_name, attr_value):
269 """Enable account by replacing cn attribute value, value of modifyTimeStamp changed"""
270
271 log.info('Enable account by replacing cn attribute value, value of modifyTimeStamp changed')
272 while (nousrs > 0):
273 usrrdn = '{}{}'.format(userid, nousrs)
274 userdn = 'uid={},{},{}'.format(usrrdn, subtree, suffix)
275 user = UserAccount(topology_st.standalone, dn=userdn)
276 try:
277 user.replace(attr_name, attr_value)
278 except ldap.LDAPError as e:
279 log.error('Failed to add/replace {} attribute to-{}, for user-{}'.format(attr_name, attr_value, userdn))
280 raise e
281 nousrs = nousrs - 1
282 time.sleep(1)
283
284
285 def del_time_attr(topology_st, suffix, subtree, userid, nousrs, attr_name):
286 """Delete lastLoginTime/createTimeStamp/ModifyTimeStamp attribute from user account"""
287
288 log.info('Delete lastLoginTime/createTimeStamp/ModifyTimeStamp attribute from user account')
289 while (nousrs > 0):
290 usrrdn = '{}{}'.format(userid, nousrs)
291 userdn = 'uid={},{},{}'.format(usrrdn, subtree, suffix)
292 user = UserAccount(topology_st.standalone, dn=userdn)
293 try:
294 user.remove_all(attr_name)
295 except ldap.LDAPError as e:
296 log.error('Failed to delete {} attribute for user-{}'.format(attr_name, userdn))
297 raise e
298 nousrs = nousrs - 1
299 time.sleep(1)
300
301
302 def add_users(topology_st, suffix, subtree, userid, nousrs, ulimit):
303 """Add users to default test instance with given suffix, subtree, userid and nousrs"""
304
305 log.info('add_users: Pass all of these as parameters suffix, subtree, userid and nousrs')
306 users = UserAccounts(topology_st.standalone, suffix, rdn=subtree)
307 while (nousrs > ulimit):
308 usrrdn = '{}{}'.format(userid, nousrs)
309 user_properties = {
310 'uid': usrrdn,
311 'cn': usrrdn,
312 'sn': usrrdn,
313 'uidNumber': '1001',
314 'gidNumber': '2001',
315 'userpassword': USER_PASW,
316 'homeDirectory': '/home/{}'.format(usrrdn)}
317 users.create(properties=user_properties)
318 nousrs = nousrs - 1
319
320
321 def del_users(topology_st, suffix, subtree, userid, nousrs):
322 """Delete users from default test instance with given suffix, subtree, userid and nousrs"""
323
324 log.info('del_users: Pass all of these as parameters suffix, subtree, userid and nousrs')
325 users = UserAccounts(topology_st.standalone, suffix, rdn=subtree)
326 while (nousrs > 0):
327 usrrdn = '{}{}'.format(userid, nousrs)
328 userdn = users.get(usrrdn)
329 userdn.delete()
330 nousrs = nousrs - 1
331
332
333 def account_status(topology_st, suffix, subtree, userid, nousrs, ulimit, tochck):
334 """Check account status for the given suffix, subtree, userid and nousrs"""
335
336 while (nousrs > ulimit):
337 usrrdn = '{}{}'.format(userid, nousrs)
338 userdn = 'uid={},{},{}'.format(usrrdn, subtree, suffix)
339 user = UserAccount(topology_st.standalone, dn=userdn)
340 if (tochck == "Enabled"):
341 try:
342 user.bind(USER_PASW)
343 except ldap.LDAPError as e:
344 log.error('User {} failed to login, expected 0'.format(userdn))
345 raise e
346 elif (tochck == "Expired"):
347 with pytest.raises(ldap.INVALID_CREDENTIALS):
348 user.bind(USER_PASW)
349 log.error('User {} password not expired , expected error 49'.format(userdn))
350 elif (tochck == "Disabled"):
351 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
352 user.bind(USER_PASW)
353 log.error('User {} is not inactivated, expected error 19'.format(userdn))
354 nousrs = nousrs - 1
355 time.sleep(1)
356
357
358 def user_binds(user, user_pw, num_binds):
359 """ Bind as user a number of times """
360 for i in range(num_binds):
361 userconn = user.bind(user_pw)
362 time.sleep(1)
363 userconn.unbind()
364
365
366 def verify_last_login_entries(inst, dn, expected):
367 """ Search for lastLoginHistory attribute and verify the number and order of entries """
368 entries = inst.search_s(dn, ldap.SCOPE_SUBTREE, "(objectclass=*)", ['lastLoginHistory'])
369 decoded_values = [entry.decode() for entry in entries[0].getValues('lastLoginHistory')]
370 ascending_order = all(decoded_values[i] <= decoded_values[i + 1] for i in range(len(decoded_values) - 1))
371 assert len(decoded_values) == expected
372 assert ascending_order
373
374
375 def test_glact_inact(topology_st, accpol_global):
376 """Verify if user account is inactivated when accountInactivityLimit is exceeded.
377
378 :id: 342af084-0ad0-442f-b6f6-5a8b8e5e4c28
379 :setup: Standalone instance, Global account policy plugin configuration,
380 set accountInactivityLimit to few secs.
381 :steps:
382 1. Add few users to ou=people subtree in the default suffix
383 2. Check if users are active just before it reaches accountInactivityLimit.
384 3. User accounts should not be inactivated, expected 0
385 4. Check if users are inactivated when accountInactivityLimit is exceeded.
386 5. User accounts should be inactivated, expected error 19.
387 :expectedresults:
388 1. Success
389 2. Success
390 3. Success
391 4. Success
392 5. Should return error code 19
393 """
394
395 suffix = DEFAULT_SUFFIX
396 subtree = "ou=people"
397 userid = "glinactusr"
398 nousrs = 3
399 log.info('AccountInactivityLimit set to 12. Account will be inactivated if not accessed in 12 secs')
400 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
401
402 log.info('Sleep for 10 secs to check if account is not inactivated, expected value 0')
403 time.sleep(10)
404 log.info('Account should not be inactivated since AccountInactivityLimit not exceeded')
405 account_status(topology_st, suffix, subtree, userid, 3, 2, "Enabled")
406
407 log.info('Sleep for 3 more secs to check if account is inactivated')
408 time.sleep(3)
409 account_status(topology_st, suffix, subtree, userid, 2, 0, "Disabled")
410
411 log.info('Sleep +10 secs to check if account {}3 is inactivated'.format(userid))
412 time.sleep(10)
413 account_status(topology_st, suffix, subtree, userid, 3, 2, "Disabled")
414 del_users(topology_st, suffix, subtree, userid, nousrs)
415
416
417 def test_glremv_lastlogin(topology_st, accpol_global):
418 """Verify if user account is inactivated by createTimeStamp, if lastLoginTime attribute is missing.
419
420 :id: 8ded5d8e-ed93-4c22-9c8e-78c479189f84
421 :setup: Standalone instance, Global account policy plugin configuration,
422 set accountInactivityLimit to few secs.
423 :steps:
424 1. Add few users to ou=people subtree in the default suffix
425 2. Wait for few secs and bind as user to create lastLoginTime attribute.
426 3. Remove the lastLoginTime attribute from the user.
427 4. Wait till accountInactivityLimit exceeded based on createTimeStamp value
428 5. Check if users are inactivated, expected error 19.
429 6. Replace lastLoginTime attribute and check if account is activated
430 7. User should be activated based on lastLoginTime attribute, expected 0
431 :expectedresults:
432 1. Success
433 2. Success
434 3. Success
435 4. Success
436 5. Success
437 6. Success
438 7. Should return error code 19
439 """
440
441 suffix = DEFAULT_SUFFIX
442 subtree = "ou=people"
443 userid = "nologtimeusr"
444 nousrs = 1
445 log.info('AccountInactivityLimit set to 12. Account will be inactivated if not accessed in 12 secs')
446 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
447 log.info('Sleep for 6 secs to check if account is not inactivated, expected value 0')
448 time.sleep(6)
449 log.info('Account should not be inactivated since AccountInactivityLimit not exceeded')
450 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
451 del_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
452 log.info('Sleep for 7 more secs to check if account is inactivated')
453 time.sleep(7)
454 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
455 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
456 log.info('Check if account is activated, expected 0')
457 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
458 del_users(topology_st, suffix, subtree, userid, nousrs)
459
460
461 def test_login_history_valid_values(topology_st, setup_test_user, setup_account_policy_plugin):
462 """Verify a user account with attr alwaysrecordlogin=yes returns no more
463 than the last login history size and that the timestamps are in chronological order.
464
465 :id: 34725a73-c2ba-4b18-9329-532c1514327f
466 :setup: Standalone instance, Global account policy plugin configuration,
467 set alwaysrecordlogin to yes.
468 :steps:
469 1. Bind as test user more times than lastLoginHistorySize.
470 2. Search on the test user DN for lastLoginTimeHistory attribute.
471 3. Verify returned entry contains only LOGIN_HIST_SIZE_FIVE timestamps in chronological order.
472 4. Modify plugin config entry, setting lastLoginHistorySize to LOGIN_HIST_SIZE_TWO
473 5. Bind as test user more times than lastLoginHistorySize.
474 6. Search on the test user DN for lastLoginTimeHistory attribute.
475 7. Verify returned entry contains only LOGIN_HIST_SIZE_TWO timestamps in chronological order.
476 8. Modify plugin config entry, setting lastLoginHistorySize to LOGIN_HIST_SIZE_FIVE
477 9. Search on the test user DN for lastLoginTimeHistory attribute.
478 10. Verify returned entry contains only LOGIN_HIST_SIZE_FIVE timestamps in chronological order.
479 :expectedresults:
480 1. Success
481 2. Success
482 3. Success
483 4. Success
484 5. Success
485 6. Success
486 7. Success
487 8. Success
488 9. Success
489 10. Success
490 """
491
492 USER_DN = 'uid=test_user_1000,ou=people,dc=example,dc=com'
493 USER_PW = 'password'
494 LOGIN_HIST_NUM_BINDS_SEVEN = 7
495 LOGIN_HIST_SIZE_FIVE = 5
496 LOGIN_HIST_SIZE_TWO = 2
497
498 inst = topology_st[0]
499 user = setup_test_user
500 ap_config = setup_account_policy_plugin
501
502 # Bind as test user more times than lastLoginHistorySize
503 user_binds(user, USER_PW, LOGIN_HIST_NUM_BINDS_SEVEN)
504
505 # Verify lastLoginTimeHistory attribute returns the correct number of entries in chronological order
506 verify_last_login_entries(inst, USER_DN, LOGIN_HIST_SIZE_FIVE)
507
508 ap_config.replace('lastLoginHistorySize', str(LOGIN_HIST_SIZE_TWO))
509
510 # Bind as test user more times than lastLoginHistorySize
511 user_binds(user, USER_PW, LOGIN_HIST_NUM_BINDS_SEVEN)
512
513 # Verify lastLoginTimeHistory attribute returns the correct number of entries in chronological order
514 verify_last_login_entries(inst, USER_DN, LOGIN_HIST_SIZE_TWO)
515
516 # Increase the lastLoginHistorySize to LOGIN_HIST_SIZE_FIVE
517 ap_config.replace('lastLoginHistorySize', str(LOGIN_HIST_SIZE_FIVE))
518
519 # Bind as test user more times than lastLoginHistorySize
520 user_binds(user, USER_PW, LOGIN_HIST_NUM_BINDS_SEVEN)
521
522 # Verify lastLoginTimeHistory attribute returns the correct number of entries in chronological order
523 verify_last_login_entries(inst, USER_DN, LOGIN_HIST_SIZE_FIVE)
524
525
526 def test_lastlogin_history_size_zero(topology_st, setup_test_user, setup_account_policy_plugin):
527 """Verify that when lastLoginHistorySize is set to zero, no login history is recorded.
528
529 :id: c1169b98-ebd9-4fe9-8402-c95f6f80a184
530 :setup: Standalone instance, Global account policy plugin configuration,
531 set alwaysrecordlogin to yes, and a test user.
532 :steps:
533 1. Set the lastLoginHistorySize to 0.
534 2. Bind as the test user more times than the lastLoginHistorySize.
535 3. Search for the lastLoginTimeHistory attribute on the test user DN.
536 :expectedresults:
537 1. The lastLoginHistorySize is successfully set to 0.
538 2. Success.
539 3. The returned entry has no timestamps, as the size was set to zero.
540 """
541
542 USER_DN = 'uid=test_user_1000,ou=people,dc=example,dc=com'
543 USER_PW = 'password'
544 LOGIN_HIST_NUM_BINDS_THREE = 3
545 LOGIN_HIST_SIZE_ZERO = 0
546
547 inst = topology_st[0]
548 user = setup_test_user
549 ap_config = setup_account_policy_plugin
550
551 # Set lastLoginHistorySize to 0
552 ap_config.replace('lastLoginHistorySize', str(LOGIN_HIST_SIZE_ZERO))
553
554 # Bind as test user more times than lastLoginHistorySize
555 user_binds(user, USER_PW, LOGIN_HIST_NUM_BINDS_THREE)
556
557 # Verify no entries in lastLoginTimeHistory attribute
558 verify_last_login_entries(inst, USER_DN, LOGIN_HIST_SIZE_ZERO)
559
560
561 def test_lastlogin_history_size_negative(topology_st, setup_account_policy_plugin):
562 """Verify that setting the lastLoginHistorySize to a negative number raises an error.
563
564 :id: 3e3252e0-ad66-4d49-b9a1-3e097f88f2c4
565 :setup: Standalone instance, Global account policy plugin configuration,
566 set alwaysrecordlogin to yes.
567 :steps:
568 1. Try to set the lastLoginHistorySize to a negative number.
569 :expectedresults:
570 1. A warning messge has been written to the error logs.
571 """
572
573 LOGIN_HIST_SIZE_NEGATIVE = -1
574 AC_POL_CFG_DN = "cn=config,cn=Account Policy Plugin,cn=plugins,cn=config"
575
576 inst = topology_st[0]
577 ap_config = setup_account_policy_plugin
578
579 # Try to set lastLoginHistorySize to negative
580 ap_config.replace('lastLoginHistorySize', str(LOGIN_HIST_SIZE_NEGATIVE))
581
582 assert inst.searchErrorsLog("Invalid value for login-history-size: -1")
583
584
585 def test_lastlogin_history_size_non_integer(topology_st, setup_account_policy_plugin):
586 """Verify that setting the lastLoginHistorySize to a non-integer value raises an error.
587
588 :id: 460e17a0-4d76-4c1e-94e8-a09e185b4dca
589 :setup: Standalone instance, Global account policy plugin configuration,
590 set alwaysrecordlogin to yes.
591 :steps:
592 1. Try to set the lastLoginHistorySize to a non-integer value.
593 :expectedresults:
594 1. An ldap.INVALID_SYNTAX error is raised.
595 """
596
597 LOGIN_HIST_SIZE_NON_INTEGER = 'five'
598 ap_config = setup_account_policy_plugin
599
600 # Try to set lastLoginHistorySize to a non-integer
601 with pytest.raises(ldap.INVALID_SYNTAX):
602 ap_config.replace('lastLoginHistorySize', str(LOGIN_HIST_SIZE_NON_INTEGER))
603
604
605 def test_glact_login(topology_st, accpol_global):
606 """Verify if user account can be activated by replacing the lastLoginTime attribute.
607
608 :id: f89897cc-c13e-4824-af08-3dd1039bab3c
609 :setup: Standalone instance, Global account policy plugin configuration,
610 set accountInactivityLimit to few secs.
611 :steps:
612 1. Add few users to ou=groups subtree in the default suffix
613 2. Wait till accountInactivityLimit exceeded
614 3. Run ldapsearch as normal user, expected error 19.
615 4. Replace the lastLoginTime attribute and check if account is activated
616 5. Run ldapsearch as normal user, expected 0.
617 :expectedresults:
618 1. Success
619 2. Success
620 3. Success
621 4. Success
622 5. Success
623 """
624
625 suffix = DEFAULT_SUFFIX
626 subtree = "ou=groups"
627 userid = "glactusr"
628 nousrs = 3
629 log.info('AccountInactivityLimit set to 12. Account will be inactivated if not accessed in 12 secs')
630 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
631 log.info('Sleep for 13 secs to check if account is inactivated, expected error 19')
632 time.sleep(13)
633 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
634 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
635 log.info('Check if account is activated, expected 0')
636 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
637 del_users(topology_st, suffix, subtree, userid, nousrs)
638
639
640 def test_glinact_limit(topology_st, accpol_global):
641 """Verify if account policy plugin functions well when changing accountInactivityLimit value.
642
643 :id: 7fbc373f-a3d7-4774-8d34-89b057c5e74b
644 :setup: Standalone instance, Global account policy plugin configuration,
645 set accountInactivityLimit to few secs.
646 :steps:
647 1. Add few users to ou=groups subtree in the default suffix
648 2. Check if users are active just before reaching accountInactivityLimit
649 3. Modify AccountInactivityLimit to a bigger value
650 4. Wait for additional few secs, but check users before it reaches accountInactivityLimit
651 5. Wait till accountInactivityLimit exceeded and check users, expected error 19
652 6. Modify accountInactivityLimit to use the min value.
653 7. Add few users to ou=groups subtree in the default suffix
654 8. Wait till it reaches accountInactivityLimit and check users, expected error 19
655 9. Modify accountInactivityLimit to 10 times(30 secs) bigger than the initial value.
656 10. Add few users to ou=groups subtree in the default suffix
657 11. Wait for 90 secs and check if account is not inactivated, expected 0
658 12. Wait for +27 secs and check if account is not inactivated, expected 0
659 13. Wait for +30 secs and check if account is inactivated, error 19
660 14. Replace the lastLoginTime attribute and check if account is activated
661 15. Modify accountInactivityLimit to 12 secs, which is the default
662 16. Run ldapsearch as normal user, expected 0.
663 :expectedresults:
664 1. Success
665 2. Success
666 3. Success
667 4. Success
668 5. Success
669 6. Success
670 7. Success
671 8. Success
672 9. Success
673 10. Success
674 11. Success
675 12. Success
676 13. Success
677 14. Success
678 15. Success
679 16. Success
680 """
681
682 suffix = DEFAULT_SUFFIX
683 subtree = "ou=groups"
684 userid = "inactestusr"
685 nousrs = 3
686
687 log.info('AccountInactivityLimit set to 12. Account will be inactivated if not accessed in 12 secs')
688 add_users(topology_st, suffix, subtree, userid, nousrs, 2)
689 log.info('Sleep for 9 secs to check if account is not inactivated, expected 0')
690 time.sleep(9)
691 account_status(topology_st, suffix, subtree, userid, nousrs, 2, "Enabled")
692
693 modify_attr(topology_st, ACCP_CONF, 'accountInactivityLimit', '20')
694 time.sleep(17)
695 account_status(topology_st, suffix, subtree, userid, nousrs, 2, "Enabled")
696 time.sleep(20)
697 account_status(topology_st, suffix, subtree, userid, nousrs, 2, "Disabled")
698
699 modify_attr(topology_st, ACCP_CONF, 'accountInactivityLimit', '1')
700 add_users(topology_st, suffix, subtree, userid, 2, 1)
701 time.sleep(2)
702 account_status(topology_st, suffix, subtree, userid, 2, 1, "Disabled")
703
704 modify_attr(topology_st, ACCP_CONF, 'accountInactivityLimit', '30')
705 add_users(topology_st, suffix, subtree, userid, 1, 0)
706 time.sleep(27)
707 account_status(topology_st, suffix, subtree, userid, 1, 0, "Enabled")
708 time.sleep(30)
709 account_status(topology_st, suffix, subtree, userid, 1, 0, "Disabled")
710
711 log.info('Check if account is activated, expected 0')
712 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
713 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
714
715 modify_attr(topology_st, ACCP_CONF, 'accountInactivityLimit', '12')
716 del_users(topology_st, suffix, subtree, userid, nousrs)
717
718 #unstable or unstatus tests, skipped for now
719 @pytest.mark.flaky(max_runs=2, min_passes=1)
720 def test_glnologin_attr(topology_st, accpol_global):
721 """Verify if user account is inactivated based on createTimeStamp attribute, no lastLoginTime attribute present
722
723 :id: 3032f670-705d-4f69-96f5-d75445cffcfb
724 :setup: Standalone instance, Local account policy plugin configuration,
725 set accountInactivityLimit to few secs.
726 :steps:
727 1. Configure Global account policy plugin with createTimestamp as stateattrname
728 2. lastLoginTime attribute will not be effective.
729 3. Add few users to ou=groups subtree in the default suffix
730 4. Wait for 10 secs and check if account is not inactivated, expected 0
731 5. Modify AccountInactivityLimit to 20 secs
732 6. Wait for +9 secs and check if account is not inactivated, expected 0
733 7. Wait for +3 secs and check if account is inactivated, error 19
734 8. Modify accountInactivityLimit to 3 secs
735 9. Add few users to ou=groups subtree in the default suffix
736 10. Wait for 3 secs and check if account is inactivated, error 19
737 11. Modify accountInactivityLimit to 30 secs
738 12. Add few users to ou=groups subtree in the default suffix
739 13. Wait for 90 secs and check if account is not inactivated, expected 0
740 14. Wait for +28 secs and check if account is not inactivated, expected 0
741 15. Wait for +2 secs and check if account is inactivated, error 19
742 16. Replace the lastLoginTime attribute and check if account is activated
743 17. Modify accountInactivityLimit to 12 secs, which is the default
744 18. Run ldapsearch as normal user, expected 0.
745 :expectedresults:
746 1. Success
747 2. Success
748 3. Success
749 4. Success
750 5. Success
751 6. Success
752 7. Success
753 8. Success
754 9. Success
755 10. Success
756 11. Success
757 12. Success
758 13. Success
759 14. Success
760 15. Success
761 16. Success
762 17. Success
763 18. Success
764 """
765
766 suffix = DEFAULT_SUFFIX
767 subtree = "ou=groups"
768 userid = "nologinusr"
769 nousrs = 3
770
771 log.info('AccountInactivityLimit set to 12. Account will be inactivated if not accessed in 12 secs')
772 log.info('Set attribute StateAttrName to createTimestamp, loginTime attr wont be considered')
773 modify_attr(topology_st, ACCP_CONF, 'stateattrname', 'createTimestamp')
774 topology_st.standalone.restart(timeout=10)
775 add_users(topology_st, suffix, subtree, userid, nousrs, 2)
776 log.info('Sleep for 9 secs to check if account is not inactivated, expected 0')
777 time.sleep(9)
778 account_status(topology_st, suffix, subtree, userid, nousrs, 2, "Enabled")
779
780 modify_attr(topology_st, ACCP_CONF, 'accountInactivityLimit', '20')
781 time.sleep(9)
782 account_status(topology_st, suffix, subtree, userid, nousrs, 2, "Enabled")
783 time.sleep(3)
784 account_status(topology_st, suffix, subtree, userid, nousrs, 2, "Disabled")
785
786 modify_attr(topology_st, ACCP_CONF, 'accountInactivityLimit', '3')
787 add_users(topology_st, suffix, subtree, userid, 2, 1)
788 time.sleep(2)
789 account_status(topology_st, suffix, subtree, userid, 2, 1, "Enabled")
790 time.sleep(2)
791 account_status(topology_st, suffix, subtree, userid, 2, 1, "Disabled")
792
793 modify_attr(topology_st, ACCP_CONF, 'accountInactivityLimit', '30')
794 add_users(topology_st, suffix, subtree, userid, 1, 0)
795 time.sleep(28)
796 account_status(topology_st, suffix, subtree, userid, 1, 0, "Enabled")
797 time.sleep(2)
798 account_status(topology_st, suffix, subtree, userid, 1, 0, "Disabled")
799
800 modify_attr(topology_st, ACCP_CONF, 'accountInactivityLimit', '12')
801 log.info('Set attribute StateAttrName to lastLoginTime, the default')
802 modify_attr(topology_st, ACCP_CONF, 'stateattrname', 'lastLoginTime')
803 topology_st.standalone.restart(timeout=10)
804 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
805 log.info('Check if account is activated, expected 0')
806 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
807 del_users(topology_st, suffix, subtree, userid, nousrs)
808
809 #unstable or unstatus tests, skipped for now
810 @pytest.mark.flaky(max_runs=2, min_passes=1)
811 def test_glnoalt_stattr(topology_st, accpol_global):
812 """Verify if user account can be inactivated based on lastLoginTime attribute, altstateattrname set to 1.1
813
814 :id: 8dcc3540-578f-422a-bb44-28c2cf20dbcd
815 :setup: Standalone instance, Global account policy plugin configuration,
816 set accountInactivityLimit to few secs.
817 :steps:
818 1. Configure Global account policy plugin with altstateattrname to 1.1
819 2. Add few users to ou=groups subtree in the default suffix
820 3. Wait till it reaches accountInactivityLimit
821 4. Remove lastLoginTime attribute from the user entry
822 5. Run ldapsearch as normal user, expected 0. no lastLoginTime attribute present
823 6. Wait till it reaches accountInactivityLimit and check users, expected error 19
824 :expectedresults:
825 1. Success
826 2. Success
827 3. Success
828 4. Success
829 5. Success
830 6. Success
831 """
832
833 suffix = DEFAULT_SUFFIX
834 subtree = "ou=groups"
835 userid = "nologinusr"
836 nousrs = 3
837 log.info('Set attribute altStateAttrName to 1.1')
838 modify_attr(topology_st, ACCP_CONF, 'altstateattrname', '1.1')
839 topology_st.standalone.restart(timeout=10)
840 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
841 log.info('Sleep for 13 secs to check if account is not inactivated, expected 0')
842 time.sleep(13)
843 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
844 log.info('lastLoginTime attribute is added from the above ldap bind by userdn')
845 time.sleep(13)
846 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
847 del_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
848 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
849 modify_attr(topology_st, ACCP_CONF, 'altstateattrname', 'createTimestamp')
850 topology_st.standalone.restart(timeout=10)
851 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
852 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
853 del_users(topology_st, suffix, subtree, userid, nousrs)
854
855
856 #unstable or unstatus tests, skipped for now
857 @pytest.mark.flaky(max_runs=2, min_passes=1)
858 def test_glattr_modtime(topology_st, accpol_global):
859 """Verify if user account can be inactivated based on modifyTimeStamp attribute
860
861 :id: 67380839-2966-45dc-848a-167a954153e1
862 :setup: Standalone instance, Global account policy plugin configuration,
863 set accountInactivityLimit to few secs.
864 :steps:
865 1. Configure Global account policy plugin with altstateattrname to modifyTimestamp
866 2. Add few users to ou=groups subtree in the default suffix
867 3. Wait till the accountInactivityLimit exceeded and check users, expected error 19
868 4. Modify cn attribute for user, ModifyTimeStamp is updated.
869 5. Check if user is activated based on ModifyTimeStamp attribute, expected 0
870 6. Change the plugin to use createTimeStamp and remove lastLoginTime attribute
871 7. Check if account is inactivated, expected error 19
872 :expectedresults:
873 1. Success
874 2. Success
875 3. Success
876 4. Success
877 5. Success
878 6. Success
879 7. Success
880 """
881
882 suffix = DEFAULT_SUFFIX
883 subtree = "ou=groups"
884 userid = "modtimeusr"
885 nousrs = 3
886 log.info('Set attribute altStateAttrName to modifyTimestamp')
887 modify_attr(topology_st, ACCP_CONF, 'altstateattrname', 'modifyTimestamp')
888 topology_st.standalone.restart(timeout=10)
889 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
890 log.info('Sleep for 13 secs to check if account is inactivated, expected 0')
891 time.sleep(13)
892 check_attr(topology_st, suffix, subtree, userid, nousrs, "modifyTimeStamp=*")
893 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
894 attr_name = "cn"
895 attr_value = "cnewusr"
896 modusr_attr(topology_st, suffix, subtree, userid, nousrs, attr_name, attr_value)
897 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
898 modify_attr(topology_st, ACCP_CONF, 'altstateattrname', 'createTimestamp')
899 del_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
900 topology_st.standalone.restart(timeout=10)
901 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
902 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
903 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
904 del_users(topology_st, suffix, subtree, userid, nousrs)
905
906
907 #unstable or unstatus tests, skipped for now
908 @pytest.mark.flaky(max_runs=2, min_passes=1)
909 def test_glnoalt_nologin(topology_st, accpol_global):
910 """Verify if account policy plugin works if we set altstateattrname set to 1.1 and alwaysrecordlogin to NO
911
912 :id: 49eda7db-84de-47ba-8f81-ac5e4de3a500
913 :setup: Standalone instance, Global account policy plugin configuration,
914 set accountInactivityLimit to few secs.
915 :steps:
916 1. Configure Global account policy plugin with altstateattrname to 1.1
917 2. Set alwaysrecordlogin to NO.
918 3. Add few users to ou=groups subtree in the default suffix
919 4. Wait till accountInactivityLimit exceeded and check users, expected 0
920 5. Check for lastLoginTime attribute, it should not be present
921 6. Wait for few more secs and check if account is not inactivated, expected 0
922 7. Run ldapsearch as normal user, expected 0. no lastLoginTime attribute present
923 8. Set altstateattrname to createTimeStamp
924 9. Check if user account is inactivated based on createTimeStamp attribute.
925 10. Account should be inactivated, expected error 19
926 :expectedresults:
927 1. Success
928 2. Success
929 3. Success
930 4. Success
931 5. Success
932 6. Success
933 7. Success
934 8. Success
935 9. Success
936 10. Success
937 """
938
939 suffix = DEFAULT_SUFFIX
940 subtree = "ou=groups"
941 userid = "norecrodlogusr"
942 nousrs = 3
943 log.info('Set attribute altStateAttrName to 1.1')
944 modify_attr(topology_st, ACCP_CONF, 'altstateattrname', '1.1')
945 log.info('Set attribute alwaysrecordlogin to No')
946 modify_attr(topology_st, ACCP_CONF, 'alwaysrecordlogin', 'no')
947 topology_st.standalone.restart(timeout=10)
948 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
949 log.info('Sleep for 13 secs to check if account is not inactivated, expected 0')
950 time.sleep(13)
951 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
952 time.sleep(3)
953 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
954 log.info('Set attribute altStateAttrName to createTimestamp')
955 modify_attr(topology_st, ACCP_CONF, 'altstateattrname', 'createTimestamp')
956 topology_st.standalone.restart(timeout=10)
957 time.sleep(2)
958 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
959 log.info('Reset the default attribute values')
960 modify_attr(topology_st, ACCP_CONF, 'alwaysrecordlogin', 'yes')
961 topology_st.standalone.restart(timeout=10)
962 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
963 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
964 del_users(topology_st, suffix, subtree, userid, nousrs)
965
966
967 #unstable or unstatus tests, skipped for now
968 @pytest.mark.flaky(max_runs=2, min_passes=1)
969 def test_glinact_nsact(topology_st, accpol_global):
970 """Verify if user account can be activated using dsidm.
971
972 :id: 876a7a7c-0b3f-4cd2-9b45-1dc80846e334
973 :setup: Standalone instance, Global account policy plugin configuration,
974 set accountInactivityLimit to few secs.
975 :steps:
976 1. Configure Global account policy plugin
977 2. Add few users to ou=groups subtree in the default suffix
978 3. Wait for 3 seconds
979 4. Check that trying to unlock the account fails
980 5. Sleep for 10 seconds so the account becomes inactivated
981 6. Verify account is inactive BEFORE unlocking
982 7. Unlock account
983 8. Replace the lastLoginTime attribute
984 9. Check the account is now active
985 :expectedresults:
986 1. Success
987 2. Success
988 3. Success
989 4. Success
990 5. Success
991 6. Success
992 7. Success
993 8. Success
994 9. Success
995 """
996
997 suffix = DEFAULT_SUFFIX
998 subtree = "ou=groups"
999 userid = "nsactusr"
1000 nousrs = 1
1001
1002 log.info('AccountInactivityLimit set to 12. Account will be inactivated if not accessed in 12 secs')
1003 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
1004
1005 log.info('Sleep for 3 secs to check if account is not inactivated')
1006 time.sleep(3)
1007
1008 log.info('Try to unlock account that is still active, should fail')
1009 nsact_inact(topology_st, suffix, subtree, userid, nousrs, "unlock", "")
1010
1011 log.info('Sleep for 10 secs so the account becomes inactivated')
1012 time.sleep(10)
1013
1014 log.info('Verify account is inactive BEFORE unlocking')
1015 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
1016 nsact_inact(topology_st, suffix, subtree, userid, nousrs, "entry-status", "inactivity limit exceeded")
1017
1018 log.info('Unlock account')
1019 nsact_inact(topology_st, suffix, subtree, userid, nousrs, "unlock", "")
1020
1021 log.info('Replace the lastLoginTime attribute and check the account is now active')
1022 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
1023 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
1024 nsact_inact(topology_st, suffix, subtree, userid, nousrs, "entry-status", "activated")
1025 del_users(topology_st, suffix, subtree, userid, nousrs)
1026
1027
1028 #unstable or unstatus tests, skipped for now
1029 @pytest.mark.flaky(max_runs=2, min_passes=1)
1030 def test_glinact_acclock(topology_st, accpol_global):
1031 """Verify if user account is activated when account is unlocked by passwordlockoutduration.
1032
1033 :id: 43601a61-065c-4c80-a7c2-e4f6ae17beb8
1034 :setup: Standalone instance, Global account policy plugin configuration,
1035 set accountInactivityLimit to few secs.
1036 :steps:
1037 1. Add few users to ou=groups subtree in the default suffix
1038 2. Wait for few secs and attempt invalid binds for user
1039 3. User account should be locked based on Account Lockout policy.
1040 4. Wait till accountInactivityLimit exceeded and check users, expected error 19
1041 5. Wait for passwordlockoutduration and check if account is active
1042 6. Check if account is unlocked, expected error 19, since account is inactivated
1043 7. Replace the lastLoginTime attribute and check users, expected 0
1044 :expectedresults:
1045 1. Success
1046 2. Success
1047 3. Success
1048 4. Success
1049 5. Success
1050 6. Success
1051 7. Success
1052 """
1053
1054 suffix = DEFAULT_SUFFIX
1055 subtree = "ou=groups"
1056 userid = "pwlockusr"
1057 nousrs = 1
1058 log.info('AccountInactivityLimit set to 12. Account will be inactivated if not accessed in 12 secs')
1059 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
1060 log.info('Sleep for 3 secs and try invalid binds to lockout the user')
1061 time.sleep(3)
1062
1063 pwacc_lock(topology_st, suffix, subtree, userid, nousrs)
1064 log.info('Sleep for 10 secs to check if account is inactivated, expected value 19')
1065 time.sleep(10)
1066 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
1067
1068 log.info('Add lastLoginTime to activate the user account')
1069 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
1070 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
1071
1072 log.info('Checking if account is unlocked after passwordlockoutduration, but inactivated after accountInactivityLimit')
1073 pwacc_lock(topology_st, suffix, subtree, userid, nousrs)
1074 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
1075
1076 log.info('Account is expected to be unlocked after 5 secs of passwordlockoutduration')
1077 time.sleep(5)
1078 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
1079
1080 log.info('Sleep 13s and check if account inactivated based on accountInactivityLimit, expected 19')
1081 time.sleep(13)
1082 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
1083 del_users(topology_st, suffix, subtree, userid, nousrs)
1084
1085
1086 #unstable or unstatus tests, skipped for now
1087 @pytest.mark.flaky(max_runs=2, min_passes=1)
1088 def test_glnact_pwexp(topology_st, accpol_global):
1089 """Verify if user account is activated when password is reset after password is expired
1090
1091 :id: 3bb97992-101a-4e5a-b60a-4cc21adcc76e
1092 :setup: Standalone instance, Global account policy plugin configuration,
1093 set accountInactivityLimit to few secs.
1094 :steps:
1095 1. Add few users to ou=groups subtree in the default suffix
1096 2. Set passwordmaxage to few secs
1097 3. Wait for passwordmaxage to reach and check if password expired
1098 4. Run ldapsearch as normal user, expected error 19.
1099 5. Reset the password for user account
1100 6. Wait till accountInactivityLimit exceeded and check users
1101 7. Run ldapsearch as normal user, expected error 19.
1102 8. Replace the lastLoginTime attribute and check if account is activated
1103 9. Run ldapsearch as normal user, expected 0.
1104 :expectedresults:
1105 1. Success
1106 2. Success
1107 3. Success
1108 4. Success
1109 5. Success
1110 6. Success
1111 7. Success
1112 8. Success
1113 9. Success
1114 """
1115
1116 suffix = DEFAULT_SUFFIX
1117 subtree = "ou=groups"
1118 userid = "pwexpusr"
1119 nousrs = 1
1120 try:
1121 topology_st.standalone.config.set('passwordmaxage', '9')
1122 except ldap.LDAPError as e:
1123 log.error('Failed to change the value of passwordmaxage to 9')
1124 raise e
1125 log.info('AccountInactivityLimit set to 12. Account will be inactivated if not accessed in 12 secs')
1126 log.info('Passwordmaxage is set to 9. Password will expire in 9 secs')
1127 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
1128
1129 log.info('Sleep for 9 secs and check if password expired')
1130 time.sleep(9)
1131 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Expired")
1132 time.sleep(4) # Passed inactivity
1133 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
1134
1135 log.info('Add lastLoginTime to activate the user account')
1136 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
1137 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Expired")
1138 userpw_reset(topology_st, suffix, subtree, userid, nousrs, "DirMgr", PASSWORD, USER_PASW)
1139 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
1140
1141 # Allow password to expire again, but inactivity continues
1142 time.sleep(7)
1143
1144 # reset password to counter expiration, we will test expiration again later
1145 userpw_reset(topology_st, suffix, subtree, userid, nousrs, "DirMgr", PASSWORD, USER_PASW)
1146 log.info('Sleep for 4 secs and check if account is now inactivated, expected error 19')
1147 time.sleep(4)
1148 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
1149 userpw_reset(topology_st, suffix, subtree, userid, nousrs, "DirMgr", PASSWORD, USER_PASW)
1150 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
1151
1152 # Reset inactivity and check for expiration
1153 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
1154 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
1155 time.sleep(8)
1156 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Expired")
1157
1158 # Reset account
1159 userpw_reset(topology_st, suffix, subtree, userid, nousrs, "DirMgr", PASSWORD, USER_PASW)
1160 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
1161
1162 # Reset maxage
1163 try:
1164 topology_st.standalone.config.set('passwordmaxage', '400')
1165 except ldap.LDAPError as e:
1166 log.error('Failed to change the value of passwordmaxage to 400')
1167 raise e
1168 del_users(topology_st, suffix, subtree, userid, nousrs)
1169
1170
1171 #unstable or unstatus tests, skipped for now
1172 @pytest.mark.flaky(max_runs=2, min_passes=1)
1173 def test_locact_inact(topology_st, accpol_local):
1174 """Verify if user account is inactivated when accountInactivityLimit is exceeded.
1175
1176 :id: 02140e36-79eb-4d88-ba28-66478689289b
1177 :setup: Standalone instance, ou=people subtree configured for Local account
1178 policy plugin configuration, set accountInactivityLimit to few secs.
1179 :steps:
1180 1. Add few users to ou=people subtree in the default suffix
1181 2. Wait for few secs before it reaches accountInactivityLimit and check users.
1182 3. Run ldapsearch as normal user, expected 0
1183 4. Wait till accountInactivityLimit is exceeded
1184 5. Run ldapsearch as normal user and check if its inactivated, expected error 19.
1185 6. Replace user's lastLoginTime attribute and check if its activated, expected 0
1186 :expectedresults:
1187 1. Success
1188 2. Success
1189 3. Success
1190 4. Success
1191 5. Success
1192 6. Should return error code 19
1193 """
1194
1195 suffix = DEFAULT_SUFFIX
1196 subtree = "ou=people"
1197 userid = "inactusr"
1198 nousrs = 3
1199 log.info('AccountInactivityLimit set to 10. Account will be inactivated if not accessed in 10 secs')
1200 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
1201 log.info('Sleep for 9 secs to check if account is not inactivated, expected value 0')
1202 time.sleep(9)
1203 log.info('Account should not be inactivated since AccountInactivityLimit not exceeded')
1204 account_status(topology_st, suffix, subtree, userid, 3, 2, "Enabled")
1205 log.info('Sleep for 2 more secs to check if account is inactivated')
1206 time.sleep(2)
1207 account_status(topology_st, suffix, subtree, userid, 2, 0, "Disabled")
1208 log.info('Sleep +9 secs to check if account {}3 is inactivated'.format(userid))
1209 time.sleep(9)
1210 account_status(topology_st, suffix, subtree, userid, 3, 2, "Disabled")
1211 log.info('Add lastLoginTime attribute to all users and check if its activated')
1212 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
1213 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
1214 del_users(topology_st, suffix, subtree, userid, nousrs)
1215
1216
1217 #unstable or unstatus tests, skipped for now
1218 @pytest.mark.flaky(max_runs=2, min_passes=1)
1219 def test_locinact_modrdn(topology_st, accpol_local):
1220 """Verify if user account is inactivated when moved from ou=groups to ou=people subtree.
1221
1222 :id: 5f25bea3-fab0-4db4-b43d-2d47cc6e5ad1
1223 :setup: Standalone instance, ou=people subtree configured for Local account
1224 policy plugin configuration, set accountInactivityLimit to few secs.
1225 :steps:
1226 1. Add few users to ou=groups subtree in the default suffix
1227 2. Plugin configured to ou=people subtree only.
1228 3. Wait for few secs before it reaches accountInactivityLimit and check users.
1229 4. Run ldapsearch as normal user, expected 0
1230 5. Wait till accountInactivityLimit exceeded
1231 6. Move users from ou=groups subtree to ou=people subtree
1232 7. Check if users are inactivated, expected error 19
1233 :expectedresults:
1234 1. Success
1235 2. Success
1236 3. Success
1237 4. Success
1238 5. Success
1239 6. Success
1240 7. Should return error code 0 and 19
1241 """
1242
1243 suffix = DEFAULT_SUFFIX
1244 subtree = "ou=groups"
1245 userid = "nolockusr"
1246 nousrs = 1
1247 log.info('Account should not be inactivated since the subtree is not configured')
1248 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
1249 log.info('Sleep for 11 secs to check if account is not inactivated, expected value 0')
1250 time.sleep(11)
1251 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
1252 log.info('Moving users from ou=groups to ou=people subtree')
1253 user = UserAccount(topology_st.standalone, dn='uid=nolockusr1,ou=groups,dc=example,dc=com')
1254 try:
1255 user.rename('uid=nolockusr1', newsuperior='ou=people,dc=example,dc=com')
1256 except ldap.LDAPError as e:
1257 log.error('Failed to move user uid=nolockusr1 from ou=groups to ou=people')
1258 raise e
1259 subtree = "ou=people"
1260 log.info('Then wait for 11 secs and check if entries are inactivated')
1261 time.sleep(11)
1262 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
1263 add_time_attr(topology_st, suffix, subtree, userid, nousrs, 'lastLoginTime')
1264 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Enabled")
1265 del_users(topology_st, suffix, subtree, userid, nousrs)
1266
1267
1268 def test_locact_modrdn(topology_st, accpol_local):
1269 """Verify if user account is inactivated when users moved from ou=people to ou=groups subtree.
1270
1271 :id: e821cbae-bfc3-40d3-947d-b228c809987f
1272 :setup: Standalone instance, ou=people subtree configured for Local account
1273 policy plugin configuration, set accountInactivityLimit to few secs.
1274 :steps:
1275 1. Add few users to ou=people subtree in the default suffix
1276 2. Wait for few secs and check if users not inactivated, expected 0.
1277 3. Move users from ou=people to ou=groups subtree
1278 4. Wait till accountInactivityLimit is exceeded
1279 5. Check if users are active in ou=groups subtree, expected 0
1280 :expectedresults:
1281 1. Success
1282 2. Success
1283 3. Success
1284 4. Success
1285 5. Success
1286 """
1287
1288 suffix = DEFAULT_SUFFIX
1289 subtree = "ou=people"
1290 userid = "lockusr"
1291 nousrs = 1
1292 log.info('Account should be inactivated since the subtree is configured')
1293 add_users(topology_st, suffix, subtree, userid, nousrs, 0)
1294 log.info('Sleep for 11 secs to check if account is inactivated, expected value 19')
1295 time.sleep(11)
1296 account_status(topology_st, suffix, subtree, userid, nousrs, 0, "Disabled")
1297 log.info('Moving users from ou=people to ou=groups subtree')
1298 user = UserAccount(topology_st.standalone, dn='uid=lockusr1,ou=people,dc=example,dc=com')
1299 try:
1300 user.rename('uid=lockusr1', newsuperior='ou=groups,dc=example,dc=com')
1301 except ldap.LDAPError as e:
1302 log.error('Failed to move user uid=lockusr1 from ou=people to ou=groups')
1303 raise e
1304 log.info('Sleep for +2 secs and check users from both ou=people and ou=groups subtree')
1305 time.sleep(2)
1306 subtree = "ou=groups"
1307 account_status(topology_st, suffix, subtree, userid, 1, 0, "Enabled")
1308 del_users(topology_st, suffix, subtree, userid, nousrs)
1309
1310 def test_acct_policy_consumer(topology_m1c1, request):
1311 """Test the lastLoginHistory is updated on consumer without
1312 referral error
1313
1314 :id: 53a9a2c7-6b10-41c9-b9f9-bde412d04acb
1315 :setup: Supplier Instance, Consumer Instance
1316 :steps:
1317 1. Create a test entry on the supplier
1318 2. Configure lastLoginTime on supplier and consumer
1319 3. On supplier 3 binds of the test entry
1320 4. On supplier check there is 3 lastLoginHistory values
1321 5. On supplier check there is no error in error logs
1322 6. On consumer 3 binds of the test entry
1323 7. On consumer check there is 3 lastLoginHistory values
1324 8. On consumer check there is no error in error logs
1325 :expectedresults:
1326 1. Success
1327 2. Success
1328 3. Success
1329 4. Success
1330 5. Success
1331 6. Success
1332 7. Success
1333 8. Success
1334 """
1335
1336 supplier = topology_m1c1.ms['supplier1']
1337 consumer = topology_m1c1.cs['consumer1']
1338 USER_PW = 'password'
1339
1340 # Add on the supplier a test user entry and wait it is on the consumer
1341 users_supplier = UserAccounts(supplier, DEFAULT_SUFFIX, rdn=None)
1342 user_supplier = users_supplier.create_test_user(uid=1000, gid=2000)
1343 user_supplier.replace('userPassword', USER_PW)
1344
1345 users_consumer = UserAccounts(consumer, DEFAULT_SUFFIX, rdn=None)
1346 for i in range(0, 10):
1347 try:
1348 user_consumer = users_consumer.get("test_user_1000")
1349 break
1350 except ldap.NO_SUCH_OBJECT:
1351 time.sleep(1)
1352
1353 # Configure lastLoginTime on supplier and consumer
1354 plugin = AccountPolicyPlugin(supplier)
1355 plugin.enable()
1356 ACCPOL_DN = "cn={},{}".format(PLUGIN_ACCT_POLICY, DN_PLUGIN)
1357 ACCP_CONF = "{},{}".format(DN_CONFIG, ACCPOL_DN)
1358 plugin.set('nsslapd-pluginarg0', ACCP_CONF)
1359 accp = AccountPolicyConfig(supplier, dn=ACCP_CONF)
1360 accp.set('alwaysrecordlogin', 'yes')
1361 accp.set('stateattrname', 'lastLoginTime')
1362 supplier.restart(timeout=10)
1363
1364 plugin = AccountPolicyPlugin(consumer)
1365 plugin.enable()
1366 ACCPOL_DN = "cn={},{}".format(PLUGIN_ACCT_POLICY, DN_PLUGIN)
1367 ACCP_CONF = "{},{}".format(DN_CONFIG, ACCPOL_DN)
1368 plugin.set('nsslapd-pluginarg0', ACCP_CONF)
1369 accp = AccountPolicyConfig(consumer, dn=ACCP_CONF)
1370 accp.set('alwaysrecordlogin', 'yes')
1371 accp.set('stateattrname', 'lastLoginTime')
1372 consumer.restart(timeout=10)
1373
1374 # On supplier
1375 # Do 3 binds with a delay to
1376 # allow several values lastLoginHistory
1377 user_supplier.bind(USER_PW)
1378 time.sleep(2)
1379 user_supplier = users_supplier.get("test_user_1000")
1380 user_supplier.bind(USER_PW)
1381 time.sleep(2)
1382 user_supplier = users_supplier.get("test_user_1000")
1383 user_supplier.bind(USER_PW)
1384 time.sleep(2)
1385
1386 # Verify there is no referral error
1387 results = supplier.ds_error_log.match('.*.acct_update_login_history - Modify error 10 on entry*')
1388 assert not results
1389
1390 # Verify that we got 3 values for lastLoginHistory
1391 assert len(user_supplier.get_attr_vals_utf8_l('lastLoginHistory')) == 3
1392
1393 # On Consumer
1394 # Do 3 binds with a delay to
1395 # allow several values lastLoginHistory
1396 user_supplier.bind(USER_PW)
1397 user_consumer.bind(USER_PW)
1398 time.sleep(2)
1399 user_consumer = users_supplier.get("test_user_1000")
1400 user_consumer.bind(USER_PW)
1401 time.sleep(2)
1402 user_consumer = users_supplier.get("test_user_1000")
1403 user_consumer.bind(USER_PW)
1404 time.sleep(2)
1405
1406 # Verify there is no referral error
1407 results = consumer.ds_error_log.match('.*.acct_update_login_history - Modify error 10 on entry*')
1408 assert not results
1409
1410 # Verify that we got at least 3 values for lastLoginHistory
1411 assert len(user_consumer.get_attr_vals_utf8_l('lastLoginHistory')) >= 3
1412
1413
1414 def fin():
1415 user_supplier.delete()
1416 log.info('Disabling Global accpolicy plugin and removing pwpolicy attrs')
1417 try:
1418 plugin = AccountPolicyPlugin(supplier)
1419 plugin.disable()
1420 except ldap.LDAPError as e:
1421 log.error('Failed to disable Global accpolicy plugin, {}'.format(e.message['desc']))
1422 assert False
1423 supplier.restart(timeout=10)
1424 try:
1425 plugin = AccountPolicyPlugin(consumer)
1426 plugin.disable()
1427 except ldap.LDAPError as e:
1428 log.error('Failed to disable Global accpolicy plugin, {}'.format(e.message['desc']))
1429 assert False
1430 consumer.restart(timeout=10)
1431
1432 request.addfinalizer(fin)
1433
1434 if __name__ == '__main__':
1435 # Run isolated
1436 # -s for DEBUG mode
1437 CURRENT_FILE = os.path.realpath(__file__)
1438 pytest.main("-s {}".format(CURRENT_FILE))