Skip to content

Passing an empty list to __in filter creates an incorrect LDAP search filter #3

@ivanov17

Description

@ivanov17

Hello,

I need to find several LDAP groups and then work with the search results. I want to set the list of groups using a settings variable. If this variable is not set, it seems reasonable to pass an empty list (containing no groups).

group_entries = GroupEntry.objects.filter(
    cn__in=getattr(settings, 'LDAP_ACCOUNT_INITIAL_GROUPS', [])).all()
for group_entry in group_entries:
...

Unfortunately, when an empty list is passed to the __in filter, this creates an invalid LDAP search filter. So I get ldap.PROTOCOL_ERROR exception.

On the Django debug page I see the following:

Variable Value
attrlist ['cn', 'member', 'objectclass']
attrsonly 0
base 'cn=groups,cn=accounts,dc=demo1,dc=freeipa,dc=org'
clientctrls None
filterstr '(&(objectclass=groupOfNames)(|))'
msgid 3
scope 2
self <ldap.ldapobject.SimpleLDAPObject object at 0x7f8970189220>
serverctrls None
sizelimit 0
timeout -1

As we can see, only the pipe is added to the filter.

I think it makes more sense to return a ValueError instead.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions