Blame SOURCES/0042-Ticket-49249-cos_cache-is-erroneously-logging-schema.patch

61f723
From 834b5f7355d4233c4b9d6931ba6ec8482413bca8 Mon Sep 17 00:00:00 2001
61f723
From: Thierry Bordaz <tbordaz@redhat.com>
61f723
Date: Thu, 11 May 2017 09:21:38 +0200
61f723
Subject: [PATCH] Ticket 49249 - cos_cache is erroneously logging schema
61f723
 checking failure
61f723
61f723
Bug Description:
61f723
    cos is generating virtual attributes in several steps.
61f723
    One of the first step is to check that the generated attribute will
61f723
    conform the schema.
61f723
    Then additional checks (override/merge and cos scope) are performed.
61f723
    If the entry does not conform the schema, it skips the additional checks.
61f723
    In such case it logs a message stating that the virtual attribute does not
61f723
    apply.
61f723
    During slapi-log-err refactoring (https://pagure.io/389-ds-base/issue/48978)
61f723
    the logging level, in case of schema violation, was move from SLAPI_LOG_PLUGIN
61f723
    to SLAPI_LOG_ERR.
61f723
61f723
    This change is incorrect because the potential failure to schema check is
61f723
    normal and does not imply the cos would apply to the entry (for example if
61f723
    the entry was not in the scope, the cos would also be skipped).
61f723
61f723
Fix Description:
61f723
    Move back the logging level from SLAPI_LOG_ERR to SLAPI_LOG_PLUGIN
61f723
61f723
https://pagure.io/389-ds-base/issue/49249
61f723
61f723
Reviewed by: Mark Reynolds
61f723
61f723
Platforms tested: F23
61f723
61f723
Flag Day: no
61f723
61f723
Doc impact: no
61f723
---
61f723
 dirsrvtests/tests/tickets/ticket49249_test.py | 140 ++++++++++++++++++++++++++
61f723
 ldap/servers/plugins/cos/cos_cache.c          |   2 +-
61f723
 2 files changed, 141 insertions(+), 1 deletion(-)
61f723
 create mode 100644 dirsrvtests/tests/tickets/ticket49249_test.py
61f723
61f723
diff --git a/dirsrvtests/tests/tickets/ticket49249_test.py b/dirsrvtests/tests/tickets/ticket49249_test.py
61f723
new file mode 100644
61f723
index 0000000..1dfd07e
61f723
--- /dev/null
61f723
+++ b/dirsrvtests/tests/tickets/ticket49249_test.py
61f723
@@ -0,0 +1,140 @@
61f723
+import time
61f723
+import ldap
61f723
+import logging
61f723
+import pytest
61f723
+from lib389 import DirSrv, Entry, tools, tasks
61f723
+from lib389.tools import DirSrvTools
61f723
+from lib389._constants import *
61f723
+from lib389.properties import *
61f723
+from lib389.tasks import *
61f723
+from lib389.utils import *
61f723
+from lib389.topologies import topology_st as topo
61f723
+
61f723
+DEBUGGING = os.getenv("DEBUGGING", default=False)
61f723
+if DEBUGGING:
61f723
+    logging.getLogger(__name__).setLevel(logging.DEBUG)
61f723
+else:
61f723
+    logging.getLogger(__name__).setLevel(logging.INFO)
61f723
+log = logging.getLogger(__name__)
61f723
+
61f723
+COS_BRANCH = 'ou=cos_scope,' + DEFAULT_SUFFIX
61f723
+COS_DEF = 'cn=cos_definition,' + COS_BRANCH
61f723
+COS_TEMPLATE = 'cn=cos_template,' + COS_BRANCH
61f723
+INVALID_USER_WITH_COS = 'cn=cos_user_no_mail,' + COS_BRANCH
61f723
+VALID_USER_WITH_COS = 'cn=cos_user_with_mail,' + COS_BRANCH
61f723
+
61f723
+NO_COS_BRANCH = 'ou=no_cos_scope,' + DEFAULT_SUFFIX
61f723
+INVALID_USER_WITHOUT_COS = 'cn=no_cos_user_no_mail,' + NO_COS_BRANCH
61f723
+VALID_USER_WITHOUT_COS = 'cn=no_cos_user_with_mail,' + NO_COS_BRANCH
61f723
+
61f723
+def test_ticket49249(topo):
61f723
+    """Write your testcase here...
61f723
+
61f723
+    Also, if you need any testcase initialization,
61f723
+    please, write additional fixture for that(include finalizer).
61f723
+    """
61f723
+    # Add the branches
61f723
+    try:
61f723
+        topo.standalone.add_s(Entry((COS_BRANCH, {
61f723
+            'objectclass': 'top extensibleObject'.split(),
61f723
+            'ou': 'cos_scope'
61f723
+        })))
61f723
+    except ldap.LDAPError as e:
61f723
+        log.error('Failed to add cos_scope: error ' + e.message['desc'])
61f723
+        assert False
61f723
+
61f723
+    try:
61f723
+        topo.standalone.add_s(Entry((NO_COS_BRANCH, {
61f723
+            'objectclass': 'top extensibleObject'.split(),
61f723
+            'ou': 'no_cos_scope'
61f723
+        })))
61f723
+    except ldap.LDAPError as e:
61f723
+        log.error('Failed to add no_cos_scope: error ' + e.message['desc'])
61f723
+        assert False
61f723
+
61f723
+    try:
61f723
+        topo.standalone.add_s(Entry((COS_TEMPLATE, {
61f723
+            'objectclass': 'top ldapsubentry costemplate extensibleObject'.split(),
61f723
+            'cn': 'cos_template',
61f723
+            'cosPriority': '1',
61f723
+            'cn': 'cn=nsPwTemplateEntry,ou=level1,dc=example,dc=com',
61f723
+            'mailAlternateAddress': 'hello@world'
61f723
+        })))
61f723
+    except ldap.LDAPError as e:
61f723
+        log.error('Failed to add cos_template: error ' + e.message['desc'])
61f723
+        assert False
61f723
+
61f723
+    try:
61f723
+        topo.standalone.add_s(Entry((COS_DEF, {
61f723
+            'objectclass': 'top ldapsubentry cosSuperDefinition cosPointerDefinition'.split(),
61f723
+            'cn': 'cos_definition',
61f723
+            'costemplatedn': COS_TEMPLATE,
61f723
+            'cosAttribute': 'mailAlternateAddress default'
61f723
+        })))
61f723
+    except ldap.LDAPError as e:
61f723
+        log.error('Failed to add cos_definition: error ' + e.message['desc'])
61f723
+        assert False
61f723
+
61f723
+    try:
61f723
+        # This entry is not allowed to have mailAlternateAddress
61f723
+        topo.standalone.add_s(Entry((INVALID_USER_WITH_COS, {
61f723
+            'objectclass': 'top person'.split(),
61f723
+            'cn': 'cos_user_no_mail',
61f723
+            'sn': 'cos_user_no_mail'
61f723
+        })))
61f723
+    except ldap.LDAPError as e:
61f723
+        log.error('Failed to add cos_user_no_mail: error ' + e.message['desc'])
61f723
+        assert False
61f723
+
61f723
+    try:
61f723
+        # This entry is allowed to have mailAlternateAddress
61f723
+        topo.standalone.add_s(Entry((VALID_USER_WITH_COS, {
61f723
+            'objectclass': 'top mailGroup'.split(),
61f723
+            'cn': 'cos_user_with_mail'
61f723
+        })))
61f723
+    except ldap.LDAPError as e:
61f723
+        log.error('Failed to add cos_user_no_mail: error ' + e.message['desc'])
61f723
+        assert False
61f723
+
61f723
+    try:
61f723
+        # This entry is not allowed to have mailAlternateAddress
61f723
+        topo.standalone.add_s(Entry((INVALID_USER_WITHOUT_COS, {
61f723
+            'objectclass': 'top person'.split(),
61f723
+            'cn': 'no_cos_user_no_mail',
61f723
+            'sn': 'no_cos_user_no_mail'
61f723
+        })))
61f723
+    except ldap.LDAPError as e:
61f723
+        log.error('Failed to add no_cos_user_no_mail: error ' + e.message['desc'])
61f723
+        assert False
61f723
+
61f723
+    try:
61f723
+        # This entry is  allowed to have mailAlternateAddress
61f723
+        topo.standalone.add_s(Entry((VALID_USER_WITHOUT_COS, {
61f723
+            'objectclass': 'top mailGroup'.split(),
61f723
+            'cn': 'no_cos_user_with_mail'
61f723
+        })))
61f723
+    except ldap.LDAPError as e:
61f723
+        log.error('Failed to add no_cos_user_with_mail: error ' + e.message['desc'])
61f723
+        assert False
61f723
+
61f723
+    try:
61f723
+        entries = topo.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, '(mailAlternateAddress=*)')
61f723
+        assert len(entries) == 1
61f723
+        assert entries[0].hasValue('mailAlternateAddress', 'hello@world')
61f723
+    except ldap.LDAPError as e:
61f723
+        log.fatal('Unable to retrieve cos_user_with_mail (only entry with mailAlternateAddress) : error %s' % (USER1_DN, e.message['desc']))
61f723
+        assert False
61f723
+
61f723
+    assert not topo.standalone.ds_error_log.match(".*cos attribute mailAlternateAddress failed schema.*")
61f723
+
61f723
+    if DEBUGGING:
61f723
+        # Add debugging steps(if any)...
61f723
+        pass
61f723
+
61f723
+
61f723
+if __name__ == '__main__':
61f723
+    # Run isolated
61f723
+    # -s for DEBUG mode
61f723
+    CURRENT_FILE = os.path.realpath(__file__)
61f723
+    pytest.main("-s %s" % CURRENT_FILE)
61f723
+
61f723
diff --git a/ldap/servers/plugins/cos/cos_cache.c b/ldap/servers/plugins/cos/cos_cache.c
61f723
index 8942254..66c6c7f 100644
61f723
--- a/ldap/servers/plugins/cos/cos_cache.c
61f723
+++ b/ldap/servers/plugins/cos/cos_cache.c
61f723
@@ -2362,7 +2362,7 @@ static int cos_cache_query_attr(cos_cache *ptheCache, vattr_context *context,
61f723
 
61f723
 		if(!cos_cache_schema_check(pCache, attr_index, pObjclasses))
61f723
 		{
61f723
-			slapi_log_err(SLAPI_LOG_ERR, COS_PLUGIN_SUBSYSTEM, "cos_cache_query_attr - cos attribute %s failed schema check on dn: %s\n",type,pDn);
61f723
+			slapi_log_err(SLAPI_LOG_PLUGIN, COS_PLUGIN_SUBSYSTEM, "cos_cache_query_attr - cos attribute %s failed schema check on dn: %s\n",type,pDn);
61f723
 			goto bail;
61f723
 		}
61f723
 	}
61f723
-- 
61f723
2.9.4
61f723