377e9ba5e70d40f2b353634524b285894cd4d786
[krb5.git] / src / tests / t_lockout.py
1 # Copyright (C) 2010 by the Massachusetts Institute of Technology.
2 # All rights reserved.
3
4 # Export of this software from the United States of America may
5 #   require a specific license from the United States Government.
6 #   It is the responsibility of any person or organization contemplating
7 #   export to obtain such a license before exporting.
8 #
9 # WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
10 # distribute this software and its documentation for any purpose and
11 # without fee is hereby granted, provided that the above copyright
12 # notice appear in all copies and that both that copyright notice and
13 # this permission notice appear in supporting documentation, and that
14 # the name of M.I.T. not be used in advertising or publicity pertaining
15 # to distribution of the software without specific, written prior
16 # permission.  Furthermore if you modify this software you must label
17 # your software as modified software and not distribute it in such a
18 # fashion that it might be confused with the original M.I.T. software.
19 # M.I.T. makes no representations about the suitability of
20 # this software for any purpose.  It is provided "as is" without express
21 # or implied warranty.
22
23 #!/usr/bin/python
24 from k5test import *
25
26 realm = K5Realm(create_host=False, start_kadmind=False)
27
28 realm.run_kadminl('addpol -maxfailure 2 -failurecountinterval 5m lockout')
29 realm.run_kadminl('modprinc +requires_preauth -policy lockout user')
30
31 # kinit twice with the wrong password.
32 output = realm.run_as_client([kinit, realm.user_princ], input='wrong\n',
33                              expected_code=1)
34 if 'Password incorrect while getting initial credentials' not in output:
35     fail('Expected error message not seen in kinit output')
36 output = realm.run_as_client([kinit, realm.user_princ], input='wrong\n',
37                              expected_code=1)
38 if 'Password incorrect while getting initial credentials' not in output:
39     fail('Expected error message not seen in kinit output')
40
41 # Now the account should be locked out.
42 output = realm.run_as_client([kinit, realm.user_princ], expected_code=1)
43 if 'Clients credentials have been revoked while getting initial credentials' \
44         not in output:
45     fail('Expected lockout error message not seen in kinit output')
46
47 # Check that modprinc -unlock allows a further attempt.
48 output = realm.run_kadminl('modprinc -unlock user')
49 realm.kinit(realm.user_princ, password('user'))
50
51 success('Account lockout')
52