Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Modules/LDAPObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ attrs_from_List(PyObject *attrlist, char ***attrsp)
if (seq == NULL)
goto error;

len = PySequence_Length(attrlist);
len = PySequence_Size(seq);
if (len == -1) {
goto error;
}

attrs = PyMem_NEW(char *, len + 1);

Expand Down
33 changes: 33 additions & 0 deletions Tests/t_ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ def test_dse(self):
[self.server.suffix.encode('utf-8')]
)


def test_compare_s_true(self):
base = self.server.suffix
l = self._ldap_conn
Expand Down Expand Up @@ -569,6 +570,38 @@ def test_slapadd(self):
("myAttribute", b'foobar'),
])

def test_valid_attrlist_parameter_types(self):
"""Tests the case when a valid parameter type is passed to search_ext

Any iterable which only contains strings should not raise any errors.
"""

l = self._ldap_conn

valid_attrlist_parameters = [{"a": "2"}, ["a", "b"], {}, set(), set(["a", "b"])]

for attrlist in valid_attrlist_parameters:
out = l.search_ext(
"%s" % self.server.suffix, ldap.SCOPE_SUBTREE, attrlist=attrlist
)

def test_invalid_attrlist_parameter_types(self):
"""Tests the case when an invalid parameter type is passed to search_ext

Any object type that is either not a interable or does contain something
that isn't a string should raise a TypeError. The exception is the string type itself.
"""

invalid_attrlist_parameters = [{1: 2}, 0, object(), "string"]

l = self._ldap_conn

for attrlist in invalid_attrlist_parameters:
with self.assertRaises(TypeError):
l.search_ext(
"%s" % self.server.suffix, ldap.SCOPE_SUBTREE, attrlist=attrlist
)


class Test01_ReconnectLDAPObject(Test00_SimpleLDAPObject):
"""
Expand Down