| 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 time |
| 10 |
import subprocess |
| 11 |
import pytest |
| 12 |
from lib389.tasks import * |
| 13 |
from lib389.utils import * |
| 14 |
from test389.topologies import topology_st |
| 15 |
|
| 16 |
pytestmark = pytest.mark.tier0 |
| 17 |
|
| 18 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 19 |
log = logging.getLogger(__name__) |
| 20 |
|
| 21 |
|
| 22 |
def test_clu_pwdhash(topology_st): |
| 23 |
"""Test the pwdhash script output and encrypted password length |
| 24 |
|
| 25 |
:id: faaafd01-6748-4451-9d2b-f3bd47902447 |
| 26 |
|
| 27 |
:setup: Standalone instance |
| 28 |
|
| 29 |
:steps: |
| 30 |
1. Execute /usr/bin/pwdhash -s ssha testpassword command from command line |
| 31 |
2. Check if there is any output |
| 32 |
3. Check the length of the generated output |
| 33 |
|
| 34 |
:expectedresults: |
| 35 |
1. Execution should PASS |
| 36 |
2. There should be an output from the command |
| 37 |
3. Output length should not be less than 20 |
| 38 |
""" |
| 39 |
|
| 40 |
log.info('Running test_clu_pwdhash...') |
| 41 |
|
| 42 |
cmd = '%s -s ssha testpassword' % os.path.join(topology_st.standalone.get_bin_dir(), 'pwdhash') |
| 43 |
p = os.popen(cmd) |
| 44 |
result = p.readline() |
| 45 |
p.close() |
| 46 |
|
| 47 |
if not result: |
| 48 |
log.fatal('test_clu_pwdhash: Failed to run pwdhash') |
| 49 |
assert False |
| 50 |
|
| 51 |
if len(result) < 20: |
| 52 |
log.fatal('test_clu_pwdhash: Encrypted password is too short') |
| 53 |
assert False |
| 54 |
log.info('pwdhash generated: ' + result) |
| 55 |
log.info('test_clu_pwdhash: PASSED') |
| 56 |
|
| 57 |
|
| 58 |
def test_clu_pwdhash_mod(topology_st): |
| 59 |
"""Test the pwdhash script output with -D configdir |
| 60 |
|
| 61 |
:id: 874ab5e2-207b-4a95-b4c0-22d97b8ab643 |
| 62 |
|
| 63 |
:setup: Standalone instance |
| 64 |
|
| 65 |
:steps: |
| 66 |
1. Set nsslapd-rootpwstoragescheme & passwordStorageScheme to SSHA256 & SSHA384 respectively |
| 67 |
2. Execute /usr/bin/pwdhash -D /etc/dirsrv/slapd-instance_name/ <password> |
| 68 |
3. Check if there is any output |
| 69 |
4. Check if the command returns the hashed string using the algorithm set in nsslapd-rootpwstoragescheme |
| 70 |
|
| 71 |
:expectedresults: |
| 72 |
1. nsslapd-rootpwstoragescheme & passwordStorageScheme should set to SSHA256 & SSHA384 respectively |
| 73 |
2. Execution should PASS |
| 74 |
3. There should be an output from the command |
| 75 |
4. Command should return the hashed string using the algorithm set in nsslapd-rootpwstoragescheme |
| 76 |
""" |
| 77 |
|
| 78 |
log.info('Running test_clu_pwdhash_mod...') |
| 79 |
topology_st.standalone.config.set('nsslapd-rootpwstoragescheme', 'SSHA256') |
| 80 |
topology_st.standalone.config.set('passwordStorageScheme', 'SSHA384') |
| 81 |
cmd = [os.path.join(topology_st.standalone.get_bin_dir(), 'pwdhash'), '-D', '/etc/dirsrv/slapd-standalone1', |
| 82 |
'password'] |
| 83 |
result = subprocess.check_output(cmd) |
| 84 |
stdout = ensure_str(result) |
| 85 |
assert result, "Failed to run pwdhash" |
| 86 |
assert 'SSHA256' in stdout |
| 87 |
log.info('pwdhash generated: ' + stdout) |
| 88 |
log.info('returned the hashed string using the algorithm set in nsslapd-rootpwstoragescheme') |
| 89 |
|
| 90 |
|
| 91 |
if __name__ == '__main__': |
| 92 |
# Run isolated |
| 93 |
# -s for DEBUG mode |
| 94 |
CURRENT_FILE = os.path.realpath(__file__) |
| 95 |
pytest.main("-s %s" % CURRENT_FILE) |