Blame SOURCES/0002-Issue-4701-RFE-Exclude-attributes-from-retro-changel.patch

91ce38
From 1e1c2b23c35282481628af7e971ac683da334502 Mon Sep 17 00:00:00 2001
91ce38
From: James Chapman <jachapma@redhat.com>
91ce38
Date: Tue, 27 Apr 2021 17:00:15 +0100
91ce38
Subject: [PATCH 02/12] Issue 4701 - RFE - Exclude attributes from retro
91ce38
 changelog (#4723)
91ce38
91ce38
Description: When the retro changelog plugin is enabled it writes the
91ce38
             added/modified values to the "cn-changelog" suffix. In
91ce38
             some cases an entries attribute values can be of a
91ce38
             sensitive nature and should be excluded. This RFE adds
91ce38
             functionality that will allow an admin exclude certain
91ce38
             attributes from the retro changelog DB.
91ce38
91ce38
Relates: https://github.com/389ds/389-ds-base/issues/4701
91ce38
91ce38
Reviewed by: mreynolds389, droideck (Thanks folks)
91ce38
---
91ce38
 .../tests/suites/retrocl/basic_test.py        | 292 ++++++++++++++++++
91ce38
 1 file changed, 292 insertions(+)
91ce38
 create mode 100644 dirsrvtests/tests/suites/retrocl/basic_test.py
91ce38
91ce38
diff --git a/dirsrvtests/tests/suites/retrocl/basic_test.py b/dirsrvtests/tests/suites/retrocl/basic_test.py
91ce38
new file mode 100644
91ce38
index 000000000..112c73cb9
91ce38
--- /dev/null
91ce38
+++ b/dirsrvtests/tests/suites/retrocl/basic_test.py
91ce38
@@ -0,0 +1,292 @@
91ce38
+# --- BEGIN COPYRIGHT BLOCK ---
91ce38
+# Copyright (C) 2021 Red Hat, Inc.
91ce38
+# All rights reserved.
91ce38
+#
91ce38
+# License: GPL (version 3 or any later version).
91ce38
+# See LICENSE for details.
91ce38
+# --- END COPYRIGHT BLOCK ---
91ce38
+
91ce38
+import logging
91ce38
+import ldap
91ce38
+import time
91ce38
+import pytest
91ce38
+from lib389.topologies import topology_st
91ce38
+from lib389.plugins import RetroChangelogPlugin
91ce38
+from lib389._constants import *
91ce38
+from lib389.utils import *
91ce38
+from lib389.tasks import *
91ce38
+from lib389.cli_base import FakeArgs, connect_instance, disconnect_instance
91ce38
+from lib389.cli_base.dsrc import dsrc_arg_concat
91ce38
+from lib389.cli_conf.plugins.retrochangelog import retrochangelog_add
91ce38
+from lib389.idm.user import UserAccount, UserAccounts, nsUserAccounts
91ce38
+
91ce38
+pytestmark = pytest.mark.tier1
91ce38
+
91ce38
+USER1_DN = 'uid=user1,ou=people,'+ DEFAULT_SUFFIX
91ce38
+USER2_DN = 'uid=user2,ou=people,'+ DEFAULT_SUFFIX
91ce38
+USER_PW = 'password'
91ce38
+ATTR_HOMEPHONE = 'homePhone'
91ce38
+ATTR_CARLICENSE = 'carLicense'
91ce38
+
91ce38
+log = logging.getLogger(__name__)
91ce38
+
91ce38
+def test_retrocl_exclude_attr_add(topology_st):
91ce38
+    """ Test exclude attribute feature of the retrocl plugin for add operation
91ce38
+
91ce38
+    :id: 3481650f-2070-45ef-9600-2500cfc51559
91ce38
+
91ce38
+    :setup: Standalone instance
91ce38
+
91ce38
+    :steps:
91ce38
+        1. Enable dynamic plugins
91ce38
+        2. Confige retro changelog plugin
91ce38
+        3. Add an entry
91ce38
+        4. Ensure entry attrs are in the changelog
91ce38
+        5. Exclude an attr
91ce38
+        6. Add another entry
91ce38
+        7. Ensure excluded attr is not in the changelog
91ce38
+
91ce38
+    :expectedresults:
91ce38
+        1. Success
91ce38
+        2. Success
91ce38
+        3. Success
91ce38
+        4. Success
91ce38
+        5. Success
91ce38
+        6. Success
91ce38
+        7. Success
91ce38
+    """
91ce38
+
91ce38
+    st = topology_st.standalone
91ce38
+
91ce38
+    log.info('Enable dynamic plugins')
91ce38
+    try:
91ce38
+        st.config.set('nsslapd-dynamic-plugins', 'on')
91ce38
+    except ldap.LDAPError as e:
91ce38
+        ldap.error('Failed to enable dynamic plugins ' + e.args[0]['desc'])
91ce38
+        assert False
91ce38
+
91ce38
+    log.info('Configure retrocl plugin')
91ce38
+    rcl = RetroChangelogPlugin(st)
91ce38
+    rcl.disable()
91ce38
+    rcl.enable()
91ce38
+    rcl.replace('nsslapd-attribute', 'nsuniqueid:targetUniqueId')
91ce38
+
91ce38
+    log.info('Restarting instance')
91ce38
+    try:
91ce38
+        st.restart()
91ce38
+    except ldap.LDAPError as e:
91ce38
+        ldap.error('Failed to restart instance ' + e.args[0]['desc'])
91ce38
+        assert False
91ce38
+
91ce38
+    users = UserAccounts(st, DEFAULT_SUFFIX)
91ce38
+
91ce38
+    log.info('Adding user1')
91ce38
+    try:
91ce38
+        user1 = users.create(properties={
91ce38
+            'sn': '1',
91ce38
+            'cn': 'user 1',
91ce38
+            'uid': 'user1',
91ce38
+            'uidNumber': '11',
91ce38
+            'gidNumber': '111',
91ce38
+            'givenname': 'user1',
91ce38
+            'homePhone': '0861234567',
91ce38
+            'carLicense': '131D16674',
91ce38
+            'mail': 'user1@whereever.com',
91ce38
+            'homeDirectory': '/home/user1',
91ce38
+            'userpassword': USER_PW})
91ce38
+    except ldap.ALREADY_EXISTS:
91ce38
+        pass
91ce38
+    except ldap.LDAPError as e:
91ce38
+        log.error("Failed to add user1")
91ce38
+
91ce38
+    log.info('Verify homePhone and carLicense attrs are in the changelog changestring')
91ce38
+    try:
91ce38
+        cllist = st.search_s(RETROCL_SUFFIX, ldap.SCOPE_SUBTREE, '(targetDn=%s)' % USER1_DN)
91ce38
+    except ldap.LDAPError as e:
91ce38
+        log.fatal("Changelog search failed, error: " +str(e))
91ce38
+        assert False
91ce38
+    assert len(cllist) > 0
91ce38
+    if  cllist[0].hasAttr('changes'):
91ce38
+        clstr = (cllist[0].getValue('changes')).decode()
91ce38
+        assert ATTR_HOMEPHONE in clstr
91ce38
+        assert ATTR_CARLICENSE in clstr
91ce38
+
91ce38
+    log.info('Excluding attribute ' + ATTR_HOMEPHONE)
91ce38
+    args = FakeArgs()
91ce38
+    args.connections = [st.host + ':' + str(st.port) + ':' + DN_DM + ':' + PW_DM]
91ce38
+    args.instance = 'standalone1'
91ce38
+    args.basedn = None
91ce38
+    args.binddn = None
91ce38
+    args.starttls = False
91ce38
+    args.pwdfile = None
91ce38
+    args.bindpw = None
91ce38
+    args.prompt = False
91ce38
+    args.exclude_attrs = ATTR_HOMEPHONE
91ce38
+    args.func = retrochangelog_add
91ce38
+    dsrc_inst = dsrc_arg_concat(args, None)
91ce38
+    inst = connect_instance(dsrc_inst, False, args)
91ce38
+    result = args.func(inst, None, log, args)
91ce38
+    disconnect_instance(inst)
91ce38
+    assert result is None
91ce38
+
91ce38
+    log.info("5s delay for retrocl plugin to restart")
91ce38
+    time.sleep(5)
91ce38
+
91ce38
+    log.info('Adding user2')
91ce38
+    try:
91ce38
+        user2 = users.create(properties={
91ce38
+            'sn': '2',
91ce38
+            'cn': 'user 2',
91ce38
+            'uid': 'user2',
91ce38
+            'uidNumber': '22',
91ce38
+            'gidNumber': '222',
91ce38
+            'givenname': 'user2',
91ce38
+            'homePhone': '0879088363',
91ce38
+            'carLicense': '04WX11038',
91ce38
+            'mail': 'user2@whereever.com',
91ce38
+            'homeDirectory': '/home/user2',
91ce38
+            'userpassword': USER_PW})
91ce38
+    except ldap.ALREADY_EXISTS:
91ce38
+        pass
91ce38
+    except ldap.LDAPError as e:
91ce38
+        log.error("Failed to add user2")
91ce38
+
91ce38
+    log.info('Verify homePhone attr is not in the changelog changestring')
91ce38
+    try:
91ce38
+        cllist = st.search_s(RETROCL_SUFFIX, ldap.SCOPE_SUBTREE, '(targetDn=%s)' % USER2_DN)
91ce38
+        assert len(cllist) > 0
91ce38
+        if  cllist[0].hasAttr('changes'):
91ce38
+            clstr = (cllist[0].getValue('changes')).decode()
91ce38
+            assert ATTR_HOMEPHONE not in clstr
91ce38
+            assert ATTR_CARLICENSE in clstr
91ce38
+    except ldap.LDAPError as e:
91ce38
+        log.fatal("Changelog search failed, error: " +str(e))
91ce38
+        assert False
91ce38
+
91ce38
+def test_retrocl_exclude_attr_mod(topology_st):
91ce38
+    """ Test exclude attribute feature of the retrocl plugin for mod operation
91ce38
+
91ce38
+    :id: f6bef689-685b-4f86-a98d-f7e6b1fcada3
91ce38
+
91ce38
+    :setup: Standalone instance
91ce38
+
91ce38
+    :steps:
91ce38
+        1. Enable dynamic plugins
91ce38
+        2. Confige retro changelog plugin
91ce38
+        3. Add user1 entry
91ce38
+        4. Ensure entry attrs are in the changelog
91ce38
+        5. Exclude an attr
91ce38
+        6. Modify user1 entry
91ce38
+        7. Ensure excluded attr is not in the changelog
91ce38
+
91ce38
+    :expectedresults:
91ce38
+        1. Success
91ce38
+        2. Success
91ce38
+        3. Success
91ce38
+        4. Success
91ce38
+        5. Success
91ce38
+        6. Success
91ce38
+        7. Success
91ce38
+    """
91ce38
+
91ce38
+    st = topology_st.standalone
91ce38
+
91ce38
+    log.info('Enable dynamic plugins')
91ce38
+    try:
91ce38
+        st.config.set('nsslapd-dynamic-plugins', 'on')
91ce38
+    except ldap.LDAPError as e:
91ce38
+        ldap.error('Failed to enable dynamic plugins ' + e.args[0]['desc'])
91ce38
+        assert False
91ce38
+
91ce38
+    log.info('Configure retrocl plugin')
91ce38
+    rcl = RetroChangelogPlugin(st)
91ce38
+    rcl.disable()
91ce38
+    rcl.enable()
91ce38
+    rcl.replace('nsslapd-attribute', 'nsuniqueid:targetUniqueId')
91ce38
+
91ce38
+    log.info('Restarting instance')
91ce38
+    try:
91ce38
+        st.restart()
91ce38
+    except ldap.LDAPError as e:
91ce38
+        ldap.error('Failed to restart instance ' + e.args[0]['desc'])
91ce38
+        assert False
91ce38
+
91ce38
+    users = UserAccounts(st, DEFAULT_SUFFIX)
91ce38
+
91ce38
+    log.info('Adding user1')
91ce38
+    try:
91ce38
+        user1 = users.create(properties={
91ce38
+            'sn': '1',
91ce38
+            'cn': 'user 1',
91ce38
+            'uid': 'user1',
91ce38
+            'uidNumber': '11',
91ce38
+            'gidNumber': '111',
91ce38
+            'givenname': 'user1',
91ce38
+            'homePhone': '0861234567',
91ce38
+            'carLicense': '131D16674',
91ce38
+            'mail': 'user1@whereever.com',
91ce38
+            'homeDirectory': '/home/user1',
91ce38
+            'userpassword': USER_PW})
91ce38
+    except ldap.ALREADY_EXISTS:
91ce38
+        pass
91ce38
+    except ldap.LDAPError as e:
91ce38
+        log.error("Failed to add user1")
91ce38
+
91ce38
+    log.info('Verify homePhone and carLicense attrs are in the changelog changestring')
91ce38
+    try:
91ce38
+        cllist = st.search_s(RETROCL_SUFFIX, ldap.SCOPE_SUBTREE, '(targetDn=%s)' % USER1_DN)
91ce38
+    except ldap.LDAPError as e:
91ce38
+        log.fatal("Changelog search failed, error: " +str(e))
91ce38
+        assert False
91ce38
+    assert len(cllist) > 0
91ce38
+    if  cllist[0].hasAttr('changes'):
91ce38
+        clstr = (cllist[0].getValue('changes')).decode()
91ce38
+        assert ATTR_HOMEPHONE in clstr
91ce38
+        assert ATTR_CARLICENSE in clstr
91ce38
+
91ce38
+    log.info('Excluding attribute ' + ATTR_CARLICENSE)
91ce38
+    args = FakeArgs()
91ce38
+    args.connections = [st.host + ':' + str(st.port) + ':' + DN_DM + ':' + PW_DM]
91ce38
+    args.instance = 'standalone1'
91ce38
+    args.basedn = None
91ce38
+    args.binddn = None
91ce38
+    args.starttls = False
91ce38
+    args.pwdfile = None
91ce38
+    args.bindpw = None
91ce38
+    args.prompt = False
91ce38
+    args.exclude_attrs = ATTR_CARLICENSE
91ce38
+    args.func = retrochangelog_add
91ce38
+    dsrc_inst = dsrc_arg_concat(args, None)
91ce38
+    inst = connect_instance(dsrc_inst, False, args)
91ce38
+    result = args.func(inst, None, log, args)
91ce38
+    disconnect_instance(inst)
91ce38
+    assert result is None
91ce38
+
91ce38
+    log.info("5s delay for retrocl plugin to restart")
91ce38
+    time.sleep(5)
91ce38
+
91ce38
+    log.info('Modify user1 carLicense attribute')
91ce38
+    try:
91ce38
+        st.modify_s(USER1_DN, [(ldap.MOD_REPLACE, ATTR_CARLICENSE, b"123WX321")])
91ce38
+    except ldap.LDAPError as e:
91ce38
+        log.fatal('test_retrocl_exclude_attr_mod: Failed to update user1 attribute: error ' + e.message['desc'])
91ce38
+        assert False
91ce38
+
91ce38
+    log.info('Verify carLicense attr is not in the changelog changestring')
91ce38
+    try:
91ce38
+        cllist = st.search_s(RETROCL_SUFFIX, ldap.SCOPE_SUBTREE, '(targetDn=%s)' % USER1_DN)
91ce38
+        assert len(cllist) > 0
91ce38
+        # There will be 2 entries in the changelog for this user, we are only
91ce38
+        #interested in the second one, the modify operation.
91ce38
+        if  cllist[1].hasAttr('changes'):
91ce38
+            clstr = (cllist[1].getValue('changes')).decode()
91ce38
+            assert ATTR_CARLICENSE not in clstr
91ce38
+    except ldap.LDAPError as e:
91ce38
+        log.fatal("Changelog search failed, error: " +str(e))
91ce38
+        assert False
91ce38
+
91ce38
+if __name__ == '__main__':
91ce38
+    # Run isolated
91ce38
+    # -s for DEBUG mode
91ce38
+    CURRENT_FILE = os.path.realpath(__file__)
91ce38
+    pytest.main("-s %s" % CURRENT_FILE)
91ce38
-- 
91ce38
2.26.3
91ce38