| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2019 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 |
|
| 10 |
import logging |
| 11 |
import pytest |
| 12 |
from lib389.tasks import * |
| 13 |
from test389.topologies import topology_st |
| 14 |
from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES |
| 15 |
from lib389._constants import DEFAULT_SUFFIX |
| 16 |
|
| 17 |
pytestmark = pytest.mark.tier1 |
| 18 |
|
| 19 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 20 |
log = logging.getLogger(__name__) |
| 21 |
|
| 22 |
|
| 23 |
def test_hide_unhashed_pwd(topology_st): |
| 24 |
"""Change userPassword, enable hiding of un-hashed |
| 25 |
password and check the audit logs. |
| 26 |
|
| 27 |
:id: c4a5d08d-f525-459b-82b9-3f68dae6fc71 |
| 28 |
:setup: Standalone instance |
| 29 |
:steps: |
| 30 |
1. Add a test user entry |
| 31 |
2. Set a new password for user and nsslapd-auditlog-logging-enabled to 'on' |
| 32 |
3. Disable nsslapd-auditlog-logging-hide-unhashed-pw |
| 33 |
4. Check the audit logs |
| 34 |
5. Set a new password for user and nsslapd-auditlog-logging-hide-unhashed-pw to 'on' |
| 35 |
6. Check the audit logs |
| 36 |
:expectedresults: |
| 37 |
1. User addition should be successful |
| 38 |
2. New password should be set and audit logs should be enabled |
| 39 |
3. Operation should be successful |
| 40 |
4. Audit logs should show password without hash |
| 41 |
5. Operation should be successful |
| 42 |
6. Audit logs should hide password which is un-hashed |
| 43 |
""" |
| 44 |
|
| 45 |
users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX) |
| 46 |
user_props = TEST_USER_PROPERTIES.copy() |
| 47 |
user_props.update({'uid': 'user', 'cn': 'buser', 'userpassword': 'Secret123'}) |
| 48 |
user = users.create(properties=user_props) |
| 49 |
|
| 50 |
# Enable the audit log |
| 51 |
topology_st.standalone.config.set('nsslapd-auditlog-logging-enabled','on') |
| 52 |
|
| 53 |
# Allow the unhashed password to be written to audit log |
| 54 |
topology_st.standalone.config.set('nsslapd-auditlog-logging-hide-unhashed-pw', 'off') |
| 55 |
topology_st.standalone.config.set('nsslapd-unhashed-pw-switch', 'on') |
| 56 |
|
| 57 |
# Set new password, and check the audit log |
| 58 |
user.reset_password('mypassword') |
| 59 |
|
| 60 |
# Check audit log |
| 61 |
time.sleep(1) |
| 62 |
if not topology_st.standalone.searchAuditLog('unhashed#user#password: mypassword'): |
| 63 |
log.fatal('failed to find unhashed password in auditlog') |
| 64 |
assert False |
| 65 |
|
| 66 |
# Hide unhashed password in audit log |
| 67 |
topology_st.standalone.config.set('nsslapd-auditlog-logging-hide-unhashed-pw', 'on') |
| 68 |
|
| 69 |
# Modify password, and check the audit log |
| 70 |
user.reset_password('hidepassword') |
| 71 |
|
| 72 |
# Check audit log |
| 73 |
time.sleep(1) |
| 74 |
if topology_st.standalone.searchAuditLog('unhashed#user#password: hidepassword'): |
| 75 |
log.fatal('Found unhashed password in auditlog') |
| 76 |
assert False |
| 77 |
|
| 78 |
log.info('Test complete') |
| 79 |
|
| 80 |
|
| 81 |
if __name__ == '__main__': |
| 82 |
# Run isolated |
| 83 |
# -s for DEBUG mode |
| 84 |
CURRENT_FILE = os.path.realpath(__file__) |
| 85 |
pytest.main("-s %s" % CURRENT_FILE) |
| 86 |
|