From 77ee9d644489f52e99f5303dadd4075bacfb4674 Mon Sep 17 00:00:00 2001 From: Anuj Borah Date: Jan 14 2020 02:12:29 +0000 Subject: Issue: 50690 - Port Password Storage test cases from TET to python3 part 2 Port Password Storage test cases from TET to python3 part 2 Relates: https://pagure.io/389-ds-base/issue/50690 Author: aborah Reviewed by: ??? --- diff --git a/dirsrvtests/tests/suites/check_storage.py b/dirsrvtests/tests/suites/check_storage.py new file mode 100644 index 0000000..7d7c84f --- /dev/null +++ b/dirsrvtests/tests/suites/check_storage.py @@ -0,0 +1,104 @@ +# --- BEGIN COPYRIGHT BLOCK --- +# Copyright (C) 2020 Red Hat, Inc. +# All rights reserved. +# +# License: GPL (version 3 or any later version). +# See LICENSE for details. +# --- END COPYRIGHT BLOCK ---- + + +""" +This file contains the test for password storage scheme +""" + +import os +import pytest +import ldap + +from lib389.topologies import topology_st as topo +from lib389.idm.user import UserAccounts +from lib389._constants import DEFAULT_SUFFIX +from lib389.config import Config +from password_plugins import SHAPlugin + +pytestmark = pytest.mark.tier1 + + +def change_config_create_user(topo, field_value): + """ + Will change passwordStorageScheme + """ + Config(topo.standalone).replace("passwordStorageScheme", field_value) + user = UserAccounts(topo.standalone, DEFAULT_SUFFIX).create_test_user() + user.set('userpassword', 'HayItsMEAnuj') + return user + + +def test_clear_text(topo): + """Check clear Scheme + + :id: 66219b92-33c1-11ea-ac46-8c16451d917b + :setup: Standalone + :steps: + 1. Create a user without password + 2. Update the user with a password + 3. Check user can be bind + :expected results: + 1. Pass + 2. Pass + 3. Pass + """ + user = change_config_create_user(topo, "CLEAR") + conn = user.bind("HayItsMEAnuj") + user.delete() + + +def test_sha(topo): + """Check SHA Scheme + + :id: 5c514112-33c1-11ea-a298-8c16451d917b + :setup: Standalone + :steps: + 1. Disable SHA Plugin + 2. Activate SHA Plugin + 3. Enable SHA Plugin + :expected results: + 1. Pass + 2. Pass + 3. Pass + """ + sha = SHAPlugin(topo.standalone) + assert sha.status() + sha.disable() + assert not sha.status() + topo.standalone.restart() + with pytest.raises(ldap.OPERATIONS_ERROR): + Config(topo.standalone).replace("passwordStorageScheme", "SHA") + Config(topo.standalone).replace("passwordStorageScheme", "CLEAR") + sha.enable() + assert sha.status() + + +def test_crypt(topo): + """Check CRYPT scheme + + :id: 618207fc-33c1-11ea-93ce-8c16451d917b + :setup: Standalone + :steps: + 1. Create a user without password + 2. Update the user with a password + 3. Check the encryption of the pwd + :expected results: + 1. Pass + 2. Pass + 3. Pass + """ + user = change_config_create_user(topo, "CRYPT") + assert '{' + "crypt" + '}' in user.get_attr_val_utf8('userpassword').lower() + user.set("userpassword", "AnujBorah") + assert '{' + "crypt" + '}' in user.get_attr_val_utf8('userpassword').lower() + + +if __name__ == "__main__": + CURRENT_FILE = os.path.realpath(__file__) + pytest.main("-s -v %s" % CURRENT_FILE)