Skip to content
Snippets Groups Projects
Commit 38eeb41c authored by Julian Rother's avatar Julian Rother
Browse files

Search constraint extraction for single-valued OR

EntryTemplate.extract_search_constraints now returns constraints for
"(|(FILTER))" as if it were "(FILTER)".
parent 7f16ead0
No related branches found
No related tags found
No related merge requests found
Pipeline #9377 passed
...@@ -493,6 +493,8 @@ class EntryTemplate(AttributeDict): ...@@ -493,6 +493,8 @@ class EntryTemplate(AttributeDict):
for name, values in self.__extract_filter_constraints(subfilter).items(): for name, values in self.__extract_filter_constraints(subfilter).items():
result[name] += values result[name] += values
return result return result
if isinstance(filter_obj, ldap.FilterOr) and len(filter_obj.filters) == 1:
return self.__extract_filter_constraints(filter_obj.filters[0])
return AttributeDict(self.schema) return AttributeDict(self.schema)
def match_search(self, base_obj, scope, filter_obj): def match_search(self, base_obj, scope, filter_obj):
......
...@@ -743,6 +743,7 @@ class TestEntryTemplate(unittest.TestCase): ...@@ -743,6 +743,7 @@ class TestEntryTemplate(unittest.TestCase):
template = EntryTemplate(schema, 'dc=example,dc=com', 'cn', objectclass=['top'], cn=WILDCARD, uid=['foobar']) template = EntryTemplate(schema, 'dc=example,dc=com', 'cn', objectclass=['top'], cn=WILDCARD, uid=['foobar'])
self.assertEqual(dict(template.extract_search_constraints('dc=exapmle,dc=com', ldap.SearchScope.wholeSubtree, ldap.FilterEqual('cn', b'foo')).items()), {'cn': ['foo']}) self.assertEqual(dict(template.extract_search_constraints('dc=exapmle,dc=com', ldap.SearchScope.wholeSubtree, ldap.FilterEqual('cn', b'foo')).items()), {'cn': ['foo']})
self.assertEqual(dict(template.extract_search_constraints('dc=exapmle,dc=com', ldap.SearchScope.wholeSubtree, ldap.FilterAnd([ldap.FilterEqual('objectclass', b'top'), ldap.FilterEqual('cn', b'foo')])).items()), {'cn': ['foo'], 'objectClass': ['top']}) self.assertEqual(dict(template.extract_search_constraints('dc=exapmle,dc=com', ldap.SearchScope.wholeSubtree, ldap.FilterAnd([ldap.FilterEqual('objectclass', b'top'), ldap.FilterEqual('cn', b'foo')])).items()), {'cn': ['foo'], 'objectClass': ['top']})
self.assertEqual(dict(template.extract_search_constraints('dc=exapmle,dc=com', ldap.SearchScope.wholeSubtree, ldap.FilterOr([ldap.FilterEqual('cn', b'foo')])).items()), {'cn': ['foo']})
self.assertEqual(dict(template.extract_search_constraints('cn=foo,dc=example,dc=com', ldap.SearchScope.baseObject, ldap.FilterPresent('objectClass')).items()), {'cn': ['foo']}) self.assertEqual(dict(template.extract_search_constraints('cn=foo,dc=example,dc=com', ldap.SearchScope.baseObject, ldap.FilterPresent('objectClass')).items()), {'cn': ['foo']})
self.assertEqual(dict(template.extract_search_constraints('dc=example,dc=com', ldap.SearchScope.baseObject, ldap.FilterPresent('objectClass')).items()), {}) self.assertEqual(dict(template.extract_search_constraints('dc=example,dc=com', ldap.SearchScope.baseObject, ldap.FilterPresent('objectClass')).items()), {})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment