Browse Source

Ticket #48109 - substring index with nssubstrbegin: 1 is not being used with filters like (attr=x*)

Description: In case, index entry has this style of substr width definition:
   nsMatchingRule: nsSubstr{Begin,Middle,End}=<NUM>
it should be converted to
   nssubstr{Begin,Middle,End}: <NUM>
and skip the following nsMatchingRule evaluation.  There was a bug in the
logic to skip.  The feature itself was not effected, but this bogus error
was logged in the error log:
[..] from ldbm instance init: line 0: unknown or invalid matching rule
"nssubstrbegin=3" in index configuration (ignored)

Plus, the test script ticket48109_test.py is adjusted to the new format.

https://fedorahosted.org/389/ticket/48109

Reviewed by [email protected] (Thank you, Mark!!)
Noriko Hosoi 9 years ago
parent
commit
230ace2aa6

+ 17 - 24
dirsrvtests/tests/tickets/ticket48109_test.py

@@ -26,6 +26,13 @@ installation1_prefix = None
 
 UID_INDEX = 'cn=uid,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config'
 
+
+logging.getLogger(__name__).setLevel(logging.DEBUG)
+log = logging.getLogger(__name__)
+
+installation1_prefix = None
+
+
 class TopologyStandalone(object):
     def __init__(self, standalone):
         standalone.open()
@@ -52,13 +59,18 @@ def topology(request):
     standalone.create()
     standalone.open()
 
+    # Delete each instance in the end
+    def fin():
+        standalone.delete()
+    request.addfinalizer(fin)
+
     # Clear out the tmp dir
     standalone.clearTmpDir(__file__)
 
     return TopologyStandalone(standalone)
 
 
-def test_ticket48109_0(topology):
+def test_ticket48109(topology):
     '''
     Set SubStr lengths to cn=uid,cn=index,...
       objectClass: extensibleObject
@@ -147,8 +159,6 @@ def test_ticket48109_0(topology):
         log.error('Failed to delete substr lengths: error ' + e.message['desc'])
         assert False
 
-
-def test_ticket48109_1(topology):
     '''
     Set SubStr lengths to cn=uid,cn=index,...
       nsIndexType: sub
@@ -234,8 +244,6 @@ def test_ticket48109_1(topology):
         log.error('Failed to delete substr lengths: error ' + e.message['desc'])
         assert False
 
-
-def test_ticket48109_2(topology):
     '''
     Set SubStr conflict formats/lengths to cn=uid,cn=index,...
       objectClass: extensibleObject
@@ -369,26 +377,11 @@ def test_ticket48109_2(topology):
     except ldap.LDAPError as e:
         log.error('Failed to delete substr lengths: error ' + e.message['desc'])
         assert False
-
-    log.info('Test complete')
-
-
-def test_ticket48109_final(topology):
-    topology.standalone.delete()
     log.info('Testcase PASSED')
 
 
-def run_isolated():
-    global installation1_prefix
-    installation1_prefix = None
-
-    topo = topology(True)
-    test_ticket48109_0(topo)
-    test_ticket48109_1(topo)
-    test_ticket48109_2(topo)
-    test_ticket48109_final(topo)
-
-
 if __name__ == '__main__':
-    run_isolated()
-
+    # Run isolated
+    # -s for DEBUG mode
+    CURRENT_FILE = os.path.realpath(__file__)
+    pytest.main("-s %s" % CURRENT_FILE)

+ 9 - 9
ldap/servers/slapd/back-ldbm/ldbm_attr.c

@@ -790,23 +790,23 @@ attr_index_config(
 			 *   nsMatchingRule: nsSubstrMiddle=2
 			 *   nsMatchingRule: nsSubstrEnd=2
 			 */ 
-			if (!a->ai_substr_lens || !a->ai_substr_lens[INDEX_SUBSTRBEGIN]) {
-				if (PL_strcasestr(attrValue->bv_val, INDEX_ATTR_SUBSTRBEGIN)) {
+			if (PL_strcasestr(attrValue->bv_val, INDEX_ATTR_SUBSTRBEGIN)) {
+				if (!a->ai_substr_lens || !a->ai_substr_lens[INDEX_SUBSTRBEGIN]) {
 					_set_attr_substrlen(INDEX_SUBSTRBEGIN, attrValue->bv_val, &substrlens);
-					do_continue = 1; /* done with j - next j */
 				}
+				do_continue = 1; /* done with j - next j */
 			}
-			if (!a->ai_substr_lens || !a->ai_substr_lens[INDEX_SUBSTRMIDDLE]) {
-				if (PL_strcasestr(attrValue->bv_val, INDEX_ATTR_SUBSTRMIDDLE)) {
+			if (PL_strcasestr(attrValue->bv_val, INDEX_ATTR_SUBSTRMIDDLE)) {
+				if (!a->ai_substr_lens || !a->ai_substr_lens[INDEX_SUBSTRMIDDLE]) {
 					_set_attr_substrlen(INDEX_SUBSTRMIDDLE, attrValue->bv_val, &substrlens);
-					do_continue = 1; /* done with j - next j */
 				}
+				do_continue = 1; /* done with j - next j */
 			}
-			if (!a->ai_substr_lens || !a->ai_substr_lens[INDEX_SUBSTREND]) {
-				if (PL_strcasestr(attrValue->bv_val, INDEX_ATTR_SUBSTREND)) {
+			if (PL_strcasestr(attrValue->bv_val, INDEX_ATTR_SUBSTREND)) {
+				if (!a->ai_substr_lens || !a->ai_substr_lens[INDEX_SUBSTREND]) {
 					_set_attr_substrlen(INDEX_SUBSTREND, attrValue->bv_val, &substrlens);
-					do_continue = 1; /* done with j - next j */
 				}
+				do_continue = 1; /* done with j - next j */
 			}
 			/* check if this is a simple ordering specification
 			   for an attribute that has no ordering matching rule */