Debian Codegraph @

dirsrvtests/tests/suites/password/pwd_lockout_bypass_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 from lib389.tasks import *
11 from lib389.utils import *
12 from test389.topologies import topology_st
13 from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES
14 import ldap
15
16 pytestmark = pytest.mark.tier1
17
18 # The irony of these names is not lost on me.
19 GOOD_PASSWORD = 'password'
20 BAD_PASSWORD = 'aontseunao'
21
22 logging.getLogger(__name__).setLevel(logging.INFO)
23 log = logging.getLogger(__name__)
24
25
26 def test_lockout_bypass(topology_st):
27 """Check basic password lockout functionality
28
29 :id: 2482a992-1719-495c-b75b-78fe5c48c873
30 :setup: Standalone instance
31 :steps:
32 1. Set passwordMaxFailure to 1
33 2. Set passwordLockDuration to 7
34 3. Set passwordLockout to 'on'
35 4. Create a user
36 5. Set a userPassword attribute
37 6. Bind as the user with a bad credentials
38 7. Bind as the user with a bad credentials
39 8. Bind as the user with a good credentials
40 :expectedresults:
41 1. passwordMaxFailure should be successfully set
42 2. passwordLockDuration should be successfully set
43 3. passwordLockout should be successfully set
44 4. User should be created
45 5. userPassword should be successfully set
46 6. Should throw an invalid credentials error
47 7. Should throw a constraint violation error
48 8. Should throw a constraint violation error
49 """
50
51 inst = topology_st.standalone
52
53 # Configure the lock policy
54 inst.config.set('passwordMaxFailure', '1')
55 inst.config.set('passwordLockoutDuration', '99999')
56 inst.config.set('passwordLockout', 'on')
57
58 # Create the account
59 users = UserAccounts(inst, DEFAULT_SUFFIX)
60 testuser = users.create(properties=TEST_USER_PROPERTIES)
61 testuser.set('userPassword', GOOD_PASSWORD)
62
63 conn = testuser.bind(GOOD_PASSWORD)
64 assert conn != None
65 conn.unbind_s()
66
67 # Bind with bad creds twice
68 # This is the failure.
69 with pytest.raises(ldap.INVALID_CREDENTIALS):
70 conn = testuser.bind(BAD_PASSWORD)
71 # Now we should not be able to ATTEMPT the bind. It doesn't matter that
72 # we disclose that we have hit the rate limit here, what matters is that
73 # it exists.
74 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
75 conn = testuser.bind(BAD_PASSWORD)
76
77 # now bind with good creds
78 # Should be error 19 still.
79 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
80 conn = testuser.bind(GOOD_PASSWORD)
81
82