Browse Source

Issue 4415 - unable to query schema if there are extra parenthesis

Bug Description:  When a client does a schema lookup in lib389 asking
                  for theresult in JSON, the X-ORIGIN is not correctly
                  parsed if it contains an extra parenthesis

Fix Description:  When parsing between the X-ORIGIN encapsulating parenthesis
                  find the right most match, not the first match.


Reviewed by: spichugi(Thanks!)
Mark Reynolds 11 months ago
2 changed files with 62 additions and 1 deletions
  1. +61
  2. +1

+ 61
- 0
dirsrvtests/tests/suites/clu/ View File

@@ -0,0 +1,61 @@
import logging
import pytest
import os
from lib389.topologies import topology_st as topo
from lib389.schema import Schema

log = logging.getLogger(__name__)

def test_origins_with_extra_parenthesis(topo):
"""Test the custom schema with extra parenthesis in X-ORIGIN can be parsed
into JSON

:id: 4230f83b-0dc3-4bc4-a7a8-5ab0826a4f05
:setup: Standalone Instance
1. Add attribute with X-ORIGIN that contains extra parenthesis
2. Querying for that attribute with JSON flag
1. Success
2. Success

ATTR_NAME = 'testAttribute'
X_ORG_VAL = 'test (TEST)'
schema = Schema(topo.standalone)

# Add new attribute
parameters = {
'names': [ATTR_NAME],
'oid': '',
'desc': 'Test extra parenthesis in X-ORIGIN',
'x_origin': X_ORG_VAL,
'syntax': '',
'syntax_len': None,
'x_ordered': None,
'collective': None,
'obsolete': None,
'single_value': None,
'no_user_mod': None,
'equality': None,
'substr': None,
'ordering': None,
'usage': None,
'sup': None

# Search for attribute with JSON option
attr_result = schema.query_attributetype(ATTR_NAME, json=True)

# Verify the x-origin value is correct
assert attr_result['at']['x_origin'][0] == X_ORG_VAL

if __name__ == '__main__':
# Run isolated
# -s for DEBUG mode
CURRENT_FILE = os.path.realpath(__file__)
pytest.main(["-s", CURRENT_FILE])

+ 1
- 1
src/lib389/lib389/ View File

@@ -142,7 +142,7 @@ class Schema(DSLdapObject):
remainder = obj.split(" X-ORIGIN ")[1]
if remainder[:1] == "(":
# Have multiple values
end = remainder.find(')')
end = remainder.rfind(')')
vals = remainder[1:end]
vals = re.findall(X_ORIGIN_REGEX, vals)
# For now use the first value, but this should be a set (another bug in python-ldap)