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

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