From d5e64d8623c1af9773e609ae46a115588c39f5f7 Mon Sep 17 00:00:00 2001 From: Sankar Ramalingam Date: Thu, 12 Oct 2017 22:10:06 +0530 Subject: [PATCH] Ticket #48085 - CI tests - replication state tests Description: Adding replication state tests to check attribute value and operational attributes after each operation. Each set of tests will check for adding and deleting attribute values. The tests cover multi-valued, single-valued, binary-type and sub-type attributes. https://pagure.io/389-ds-base/issue/48085 Reviewed by: ? --- dirsrvtests/tests/suites/replication/state_test.py | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 dirsrvtests/tests/suites/replication/state_test.py diff --git a/dirsrvtests/tests/suites/replication/state_test.py b/dirsrvtests/tests/suites/replication/state_test.py new file mode 100644 index 000000000..942636960 --- /dev/null +++ b/dirsrvtests/tests/suites/replication/state_test.py @@ -0,0 +1,99 @@ +# --- BEGIN COPYRIGHT BLOCK --- +# Copyright (C) 2017 Red Hat, Inc. +# All rights reserved. +# +# License: GPL (version 3 or any later version). +# See LICENSE for details. +# --- END COPYRIGHT BLOCK --- +# +import os +import logging +import ldap +import pytest +from lib389.idm.user import UserAccounts +from lib389.topologies import topology_m2 as topo +from lib389._constants import * + +DEBUGGING = os.getenv("DEBUGGING", default=False) +if DEBUGGING: + logging.getLogger(__name__).setLevel(logging.DEBUG) +else: + logging.getLogger(__name__).setLevel(logging.INFO) +log = logging.getLogger(__name__) + +USER_PROPERTIES = { + 'uid': 'state1usr', + 'cn': 'state1usr', + 'sn': 'state1usr', + 'uidNumber': '1001', + 'gidNumber': '2001', + 'userpassword': PASSWORD, + 'homeDirectory': '/home/testuser' +} + + +def _check_user_oper_attrs(topo, tuser, attr_name, attr_value, exp_values, oper_attr, delete=False): + """Check if list of operational attributes present for a given entry""" + + log.info('Checking if operational attrs present for attr: {} '.format(attr_name)) + entry = tuser.get_attr_vals_utf8('nscpentrywsi') + for line in str(entry).split('\n'): + if attr_name + ';' in line: + if delete: + assert 'deleted' in line and oper_attr in line and attr_value in line + else: + assert any(attr in line for attr in exp_values) and oper_attr in line + + +@pytest.mark.parametrize("test_entry, attr_name, attr_values", + [('TestCN1', 'cn', ['TestCN1', 'TestCN2', 'TestCN3', 'TestCN4']), + ('TestSN1', 'sn', ['TestSN1', 'TestSN2', 'TestSN3', 'TestSN4'])]) +def test_check_cn_attr_state(topo, test_entry, attr_name, attr_values): + """Modify user's cn and sn attribute and check if cn attribute is modified and operational + attributes vucsn, adcsn and vdcsn are present. + + :id: f25107fc-4e0d-4d03-a492-bea0acf65158 + :setup: Replication with two masters. + :steps: 1. Add user to Master1 with cn, sn attributes. + 2. Make modify operation and try add new cn, sn attribute values. + Check if two cn, sn values exist and operational attribute vucsn exist + 3. Make modify operation and try add new cn, sn attribute values. + Check if three cn, sn values exist and operational attribute vucsn exist + 4. Make modify operation and try replace cn, sn attribute values. + Check if only one cn, sn values exist and operational attribute adcsn exist + 5. Make modify operation and try delete cn, sn attribute values. + Check if it throws ldap.OBJECT_CLASS_VIOLATION error. + :expectedresults: + 1. It should PASS. + 2. It should PASS. + 3. It should PASS. + 4. It should PASS. + 5. It should PASS. + """ + + log.info('Add user: {}'.format(test_entry)) + users = UserAccounts(topo.ms['master1'], DEFAULT_SUFFIX) + USER_PROPERTIES.update(dict.fromkeys(['uid', 'cn', 'sn'], test_entry)) + tuser = users.create(properties=USER_PROPERTIES) + + tuser.set(attr_name, attr_values[1], ldap.MOD_ADD) + assert sorted(tuser.get_attr_vals(attr_name)) == sorted(attr_values[:2]) + _check_user_oper_attrs(topo, tuser, attr_name, attr_values[1], attr_values[:2], 'vucsn') + + tuser.set(attr_name, attr_values[2], ldap.MOD_ADD) + assert sorted(tuser.get_attr_vals(attr_name)) == sorted(attr_values[:3]) + _check_user_oper_attrs(topo, tuser, attr_name, attr_values[2], attr_values[:3], 'vucsn') + + tuser.set(attr_name, attr_values[3], ldap.MOD_REPLACE) + assert tuser.get_attr_vals(attr_name) == attr_values[3:] + _check_user_oper_attrs(topo, tuser, attr_name, attr_values[3], attr_values[3:], 'adcsn') + + with pytest.raises(ldap.OBJECT_CLASS_VIOLATION): + tuser.set(attr_name, attr_values[3:], ldap.MOD_DELETE) + + +if __name__ == '__main__': + # Run isolated + # -s for DEBUG mode + CURRENT_FILE = os.path.realpath(__file__) + pytest.main("-s {}".format(CURRENT_FILE)) -- 2.13.5