empty filterstr should not raise ParseError

Issue #1 new
Theo Chatzimichos
created an issue

Just found the following two issues in search_s:

1) This test fails, it raises ParserError instead (the test is not committed yet):

def test_search_s_filter_error(self):
    with self.assertRaises(ldap.FILTER_ERROR):
        self.ldapobj.search_s("ou=example,o=test", ldap.SCOPE_ONELEVEL, '(blah)')

2) This test is wrong, according to python-ldap '(blah=)' is valid, and acts like wildcard. Thus, it should instead return empty list here

def test_search_s_unparsable_filterstr_test(self):                
    with self.assertRaises(ParserError):
        self.ldapobj.search_s("ou=example,o=test", ldap.SCOPE_ONELEVEL, '(invalid=)')

Comments (7)

  1. Peter Sagerson repo owner

    2) I just tested with openldap and got this:

    >>> import ldap
    >>> c = ldap.initialize('ldap://localhost')
    >>> c.simple_bind_s()
    (97, [], 1, [])
    >>> c.search_s('ou=people,dc=perlocution,dc=local', ldap.SCOPE_ONELEVEL, '(objectClass=)')
    []
    >>> c.search_s('ou=people,dc=perlocution,dc=local', ldap.SCOPE_ONELEVEL, '(objectClass=*)')
    [('cn=Peter Sagerson,ou=people,dc=perlocution,dc=local', {'uid': ['psagers'], 'objectClass': ['inetOrgPerson', 'top'], 'userPassword': ['{MD5}exqOv/U6BPdnHC/FYViLhg=='], 'sn': ['Sagerson'], 'givenName': ['Peter'], 'cn': ['Peter Sagerson']})]
    

    Maybe (foo=) matches an empty string ({'foo': ['']})? Needs a little more investigation.

  2. Theo Chatzimichos reporter

    Maybe (foo=) matches an empty string ({'foo': ['']})? Needs a little more investigation.

    You're probably right, and apparently what I said in the summary is wrong, it does not act as wildcard

  3. Peter Sagerson repo owner

    Actually, I don't think empty values are allowed. It seems like (foo=) just always fails. In openldap, the empty comparison also seems to interact strangely with negation, but not with unions or intersections:

    >>> c.search_s('ou=groups,dc=perlocution,dc=local', ldap.SCOPE_BASE, '(objectClass=*)')
    [('ou=groups,dc=perlocution,dc=local', {'objectClass': ['organizationalUnit', 'top'], 'ou': ['groups']})]
    >>> c.search_s('ou=groups,dc=perlocution,dc=local', ldap.SCOPE_BASE, '(objectClass=)')
    []
    >>> c.search_s('ou=groups,dc=perlocution,dc=local', ldap.SCOPE_BASE, '(!(objectClass=))')
    []
    >>> c.search_s('ou=groups,dc=perlocution,dc=local', ldap.SCOPE_BASE, '(|(objectClass=*)(objectClass=))')
    [('ou=groups,dc=perlocution,dc=local', {'objectClass': ['organizationalUnit', 'top'], 'ou': ['groups']})]
    >>> c.search_s('ou=groups,dc=perlocution,dc=local', ldap.SCOPE_BASE, '(&(objectClass=*)(objectClass=))')
    []
    
  4. Log in to comment