Added escape_filter_chars() to filter the filter
parent
f6a3cb42ae
commit
e74b09bb50
|
@ -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
|
||||
+++
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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'], [])
|
||||
|
||||
|
|
Loading…
Reference in New Issue