diff --git a/CHANGES.rst b/CHANGES.rst index f786671..d39998b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Changelog 0.1.5 +++++ +- Added escape_filter_chars() to filter the filter - Override of cidicts __getitem__ so that user.attrs['nonexistent'] won't raise an exception, but instead returns an empty list 0.1.2 @@ -14,9 +15,9 @@ Changelog 0.1.1 +++++ -- fixed pretty print of binary attribute -- fixed ldap.get sizelimit=1 exception for now -- added try catch to api +- Fixed pretty print of binary attribute +- Fixed ldap.get sizelimit=1 exception for now +- Added try catch to api 0.1 +++ diff --git a/ldappr/connection.py b/ldappr/connection.py index 8226d99..9247b28 100644 --- a/ldappr/connection.py +++ b/ldappr/connection.py @@ -1,4 +1,5 @@ import ldap +import ldap.filter from ldapprobject import LdapprObject @@ -19,11 +20,11 @@ class Connection(object): raise def search(self, search_filter): - # TODO: use the escape_filter_chars() and filter_format() functions """Get list of objects that match the search_filter :param search_filter: filter to find the objects :return: list of LdapperObjects (or empty list) """ + search_filter = ldap.filter.escape_filter_chars(search_filter) result = self.conn.search_s(self.search_base, ldap.SCOPE_SUBTREE, search_filter) return [LdapprObject(item, self.conn) for item in result] @@ -35,6 +36,7 @@ class Connection(object): :return: LdapprObject or None """ # TODO: use sizelimit=1 with proper exception handling + search_filter = ldap.filter.escape_filter_chars(search_filter) result = self.conn.search_ext_s(self.search_base, ldap.SCOPE_SUBTREE, search_filter, sizelimit=0) @@ -55,6 +57,7 @@ class Connection(object): :param search_filter: filter to find the dn's :return: list of dn's """ + search_filter = ldap.filter.escape_filter_chars(search_filter) result = self.conn.search_s(self.search_base, ldap.SCOPE_SUBTREE, search_filter) return [dn for (dn, item) in result] diff --git a/ldappr/test/test_ldappr.py b/ldappr/test/test_ldappr.py index 4bbc041..e0c8938 100644 --- a/ldappr/test/test_ldappr.py +++ b/ldappr/test/test_ldappr.py @@ -41,12 +41,12 @@ class TestLdappr(unittest.TestCase): ldap = connect_to(self.server, port=self.ldap_port) ldap.close() - def test_get_attributes_from_ldapper_object(self): + def test_get_attributes_from_ldappr_object(self): user = self.ldap.get('cn=jdoe') self.assertEqual(user.attrs['givenname'], ['John']) self.assertEqual(user.attrs['gIvEnNaMe'], ['John']) - def test_get_nonexisting_attribute_ldapper_object(self): + def test_get_nonexisting_attribute_from_ldappr_object(self): user = self.ldap.get('cn=jdoe') self.assertEqual(user.attrs['nonexisting'], [])