andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0010-Ticket-49968-Confusing-CRITICAL-message-list_candida.patch

fb6657
From 3796e26e93991ded631ac57053049e9aad44c53b Mon Sep 17 00:00:00 2001
fb6657
From: Thierry Bordaz <tbordaz@redhat.com>
fb6657
Date: Wed, 10 Oct 2018 15:35:12 +0200
fb6657
Subject: [PATCH] Ticket 49968 - Confusing CRITICAL message: list_candidates -
fb6657
 NULL idl was recieved from filter_candidates_ext
fb6657
fb6657
Bug Description:
fb6657
	When a filter component is indexed but returns an empty IDL
fb6657
	an alarming message is logged although it is normal.
fb6657
fb6657
Fix Description:
fb6657
	Remove the alarming message
fb6657
fb6657
https://pagure.io/389-ds-base/issue/49968
fb6657
fb6657
Reviewed by: Mark Reynolds
fb6657
fb6657
Platforms tested: F27 + testcase
fb6657
fb6657
Flag Day: no
fb6657
fb6657
Doc impact: no
fb6657
---
fb6657
 dirsrvtests/tests/suites/basic/basic_test.py | 202 +++++++++++++++++++
fb6657
 ldap/servers/slapd/back-ldbm/filterindex.c   |  10 +-
fb6657
 2 files changed, 204 insertions(+), 8 deletions(-)
fb6657
fb6657
diff --git a/dirsrvtests/tests/suites/basic/basic_test.py b/dirsrvtests/tests/suites/basic/basic_test.py
fb6657
index 45988dc7a..dc366cd67 100644
fb6657
--- a/dirsrvtests/tests/suites/basic/basic_test.py
fb6657
+++ b/dirsrvtests/tests/suites/basic/basic_test.py
fb6657
@@ -868,6 +868,208 @@ adds nsslapd-return-default-opattr attr with value of one operation attribute.
fb6657
         log.fatal('Search failed, error: ' + e.message['desc'])
fb6657
         assert False
fb6657
 
fb6657
+
fb6657
+@pytest.fixture(scope="module")
fb6657
+def create_users(topology_st):
fb6657
+    """Add users to the default suffix
fb6657
+    """
fb6657
+
fb6657
+    users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX)
fb6657
+    user_names = ["Directory", "Server", "389", "lib389", "pytest"]
fb6657
+
fb6657
+    log.info('Adding 5 test users')
fb6657
+    for name in user_names:
fb6657
+        user = users.create(properties={
fb6657
+            'uid': name,
fb6657
+            'sn': name,
fb6657
+            'cn': name,
fb6657
+            'uidNumber': '1000',
fb6657
+            'gidNumber': '1000',
fb6657
+            'homeDirectory': '/home/%s' % name,
fb6657
+            'mail': '%s@example.com' % name,
fb6657
+            'userpassword': 'pass%s' % name,
fb6657
+        })
fb6657
+
fb6657
+
fb6657
+def test_basic_anonymous_search(topology_st, create_users):
fb6657
+    """Tests basic anonymous search operations
fb6657
+
fb6657
+    :id: c7831e04-f458-4e50-83c7-b6f77109f639
fb6657
+    :setup: Standalone instance
fb6657
+            Add 5 test users with different user names
fb6657
+    :steps:
fb6657
+         1. Execute anonymous search with different filters
fb6657
+    :expectedresults:
fb6657
+         1. Search should be successful
fb6657
+    """
fb6657
+
fb6657
+    filters = ["uid=Directory", "(|(uid=S*)(uid=3*))", "(&(uid=l*)(mail=l*))", "(&(!(uid=D*))(ou=People))"]
fb6657
+    log.info("Execute anonymous search with different filters")
fb6657
+    for filtr in filters:
fb6657
+        entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, filtr)
fb6657
+        assert len(entries) != 0
fb6657
+
fb6657
+
fb6657
+@pytest.mark.ds604
fb6657
+@pytest.mark.bz915801
fb6657
+def test_search_original_type(topology_st, create_users):
fb6657
+    """Test ldapsearch returning original attributes
fb6657
+        using nsslapd-search-return-original-type-switch
fb6657
+
fb6657
+    :id: d7831d04-f558-4e50-93c7-b6f77109f640
fb6657
+    :setup: Standalone instance
fb6657
+            Add some test entries
fb6657
+    :steps:
fb6657
+         1. Set nsslapd-search-return-original-type-switch to ON
fb6657
+         2. Check that ldapsearch *does* return unknown attributes
fb6657
+         3. Turn off nsslapd-search-return-original-type-switch
fb6657
+         4. Check that ldapsearch doesn't return any unknown attributes
fb6657
+    :expectedresults:
fb6657
+         1. nsslapd-search-return-original-type-switch should be set to ON
fb6657
+         2. ldapsearch should return unknown attributes
fb6657
+         3. nsslapd-search-return-original-type-switch should be OFF
fb6657
+         4. ldapsearch should not return any unknown attributes
fb6657
+    """
fb6657
+
fb6657
+    log.info("Set nsslapd-search-return-original-type-switch to ON")
fb6657
+    topology_st.standalone.config.set('nsslapd-search-return-original-type-switch', 'on')
fb6657
+
fb6657
+    log.info("Check that ldapsearch *does* return unknown attributes")
fb6657
+    entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'uid=Directory',
fb6657
+                                              ['objectclass overflow', 'unknown'])
fb6657
+    assert "objectclass overflow" in entries[0].getAttrs()
fb6657
+
fb6657
+    log.info("Set nsslapd-search-return-original-type-switch to Off")
fb6657
+    topology_st.standalone.config.set('nsslapd-search-return-original-type-switch', 'off')
fb6657
+    log.info("Check that ldapsearch *does not* return unknown attributes")
fb6657
+    entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'uid=Directory',
fb6657
+                                              ['objectclass overflow', 'unknown'])
fb6657
+    assert "objectclass overflow" not in entries[0].getAttrs()
fb6657
+
fb6657
+
fb6657
+@pytest.mark.bz192901
fb6657
+def test_search_ou(topology_st):
fb6657
+    """Test that DS should not return an entry that does not match the filter
fb6657
+
fb6657
+    :id: d7831d05-f117-4e89-93c7-b6f77109f640
fb6657
+    :setup: Standalone instance
fb6657
+    :steps:
fb6657
+         1. Create an OU entry without sub entries
fb6657
+         2. Search from the OU with the filter that does not match the OU
fb6657
+    :expectedresults:
fb6657
+         1. Creation of OU should be successful
fb6657
+         2. Search should not return any results
fb6657
+    """
fb6657
+
fb6657
+    log.info("Create a test OU without sub entries")
fb6657
+    ou = OrganizationalUnits(topology_st.standalone, DEFAULT_SUFFIX)
fb6657
+    ou.create(properties={
fb6657
+        'ou': 'test_ou',
fb6657
+    })
fb6657
+
fb6657
+    search_base = ("ou=test_ou,%s" % DEFAULT_SUFFIX)
fb6657
+    log.info("Search from the OU with the filter that does not match the OU, it should not return anything")
fb6657
+    entries = topology_st.standalone.search_s(search_base, ldap.SCOPE_SUBTREE, 'uid=*', ['dn'])
fb6657
+    assert len(entries) == 0
fb6657
+
fb6657
+
fb6657
+@pytest.mark.bz1044135
fb6657
+@pytest.mark.ds47319
fb6657
+def test_connection_buffer_size(topology_st):
fb6657
+    """Test connection buffer size adjustable with different values(valid values and invalid)
fb6657
+
fb6657
+    :id: e7831d05-f117-4ec9-1203-b6f77109f117
fb6657
+    :setup: Standalone instance
fb6657
+    :steps:
fb6657
+         1. Set nsslapd-connection-buffer to some valid values (2, 0 , 1)
fb6657
+         2. Set nsslapd-connection-buffer to some invalid values (-1, a)
fb6657
+    :expectedresults:
fb6657
+         1. This should pass
fb6657
+         2. This should fail
fb6657
+    """
fb6657
+
fb6657
+    valid_values = ['2', '0', '1']
fb6657
+    for value in valid_values:
fb6657
+        topology_st.standalone.config.replace('nsslapd-connection-buffer', value)
fb6657
+
fb6657
+    invalid_values = ['-1', 'a']
fb6657
+    for value in invalid_values:
fb6657
+        with pytest.raises(ldap.OPERATIONS_ERROR):
fb6657
+            topology_st.standalone.config.replace('nsslapd-connection-buffer', value)
fb6657
+
fb6657
+@pytest.mark.bz1637439
fb6657
+def test_critical_msg_on_empty_range_idl(topology_st):
fb6657
+    """Doing a range index lookup should not report a critical message even if IDL is empty
fb6657
+
fb6657
+    :id: a07a2222-0551-44a6-b113-401d23799364
fb6657
+    :setup: Standalone instance
fb6657
+    :steps:
fb6657
+         1. Create an index for internationalISDNNumber. (attribute chosen because it is
fb6657
+         unlikely that previous tests used it)
fb6657
+         2. telephoneNumber being indexed by default create 20 users without telephoneNumber
fb6657
+         3. add a telephoneNumber value and delete it to trigger an empty index database
fb6657
+         4. Do a search that triggers a range lookup on empty telephoneNumber
fb6657
+         5. Check that the critical message is not logged in error logs
fb6657
+    :expectedresults:
fb6657
+         1. This should pass
fb6657
+         2. This should pass
fb6657
+         3. This should pass
fb6657
+         4. This should pass on normal build but could abort a debug build
fb6657
+         4. This should pass
fb6657
+    """
fb6657
+    indexedAttr = 'internationalISDNNumber'
fb6657
+
fb6657
+    # Step 1
fb6657
+    from lib389.index import Indexes
fb6657
+
fb6657
+    indexes = Indexes(topology_st.standalone)
fb6657
+    indexes.create(properties={
fb6657
+        'cn': indexedAttr,
fb6657
+        'nsSystemIndex': 'false',
fb6657
+        'nsIndexType': 'eq'
fb6657
+        })
fb6657
+    topology_st.standalone.restart()
fb6657
+
fb6657
+    # Step 2
fb6657
+    users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX)
fb6657
+    log.info('Adding 20 users without "%s"' % indexedAttr)
fb6657
+    for i in range(20):
fb6657
+        name = 'user_%d' % i
fb6657
+        last_user = users.create(properties={
fb6657
+            'uid': name,
fb6657
+            'sn': name,
fb6657
+            'cn': name,
fb6657
+            'uidNumber': '1000',
fb6657
+            'gidNumber': '1000',
fb6657
+            'homeDirectory': '/home/%s' % name,
fb6657
+            'mail': '%s@example.com' % name,
fb6657
+            'userpassword': 'pass%s' % name,
fb6657
+        })
fb6657
+
fb6657
+    # Step 3
fb6657
+    # required update to create the indexAttr (i.e. 'loginShell') database, and then make it empty
fb6657
+    topology_st.standalone.modify_s(last_user.dn, [(ldap.MOD_ADD, indexedAttr, b'1234')])
fb6657
+    ent = topology_st.standalone.getEntry(last_user.dn, ldap.SCOPE_BASE,)
fb6657
+    assert ent
fb6657
+    assert ent.hasAttr(indexedAttr)
fb6657
+    topology_st.standalone.modify_s(last_user.dn, [(ldap.MOD_DELETE, indexedAttr, None)])
fb6657
+    ent = topology_st.standalone.getEntry(last_user.dn, ldap.SCOPE_BASE,)
fb6657
+    assert ent
fb6657
+    assert not ent.hasAttr(indexedAttr)
fb6657
+
fb6657
+    # Step 4
fb6657
+    # The first component being not indexed the range on second is evaluated
fb6657
+    try:
fb6657
+        ents = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(&(sudoNotAfter=*)(%s>=111))' % indexedAttr)
fb6657
+        assert len(ents) == 0
fb6657
+    except ldap.SERVER_DOWN:
fb6657
+        log.error('Likely testing against a debug version that asserted')
fb6657
+        pass
fb6657
+
fb6657
+    # Step 5
fb6657
+    assert not topology_st.standalone.searchErrorsLog('CRIT - list_candidates - NULL idl was recieved from filter_candidates_ext.')
fb6657
+
fb6657
+
fb6657
 if __name__ == '__main__':
fb6657
     # Run isolated
fb6657
     # -s for DEBUG mode
fb6657
diff --git a/ldap/servers/slapd/back-ldbm/filterindex.c b/ldap/servers/slapd/back-ldbm/filterindex.c
fb6657
index 6d36ba33e..3ef04f884 100644
fb6657
--- a/ldap/servers/slapd/back-ldbm/filterindex.c
fb6657
+++ b/ldap/servers/slapd/back-ldbm/filterindex.c
fb6657
@@ -803,16 +803,10 @@ list_candidates(
fb6657
         }
fb6657
 
fb6657
         /*
fb6657
-         * Assert we recieved a valid idl. If it was NULL, it means somewhere we failed
fb6657
-         * during the dblayer interactions.
fb6657
-         *
fb6657
-         * idl_set requires a valid idl structure to generate the linked list of
fb6657
-         * idls that we insert.
fb6657
+         * The IDL for that component is NULL, so no candidate retrieved from that component. This is all normal
fb6657
+         * Just build a idl with an empty set
fb6657
          */
fb6657
         if (tmp == NULL) {
fb6657
-            slapi_log_err(SLAPI_LOG_CRIT, "list_candidates", "NULL idl was recieved from filter_candidates_ext.");
fb6657
-            slapi_log_err(SLAPI_LOG_CRIT, "list_candidates", "Falling back to empty IDL set. This may affect your search results.");
fb6657
-            PR_ASSERT(tmp);
fb6657
             tmp = idl_alloc(0);
fb6657
         }
fb6657
 
fb6657
-- 
fb6657
2.17.2
fb6657