Skip to content

Commit 49d9588

Browse files
committed
Readibility and comment clarity. Fixes #288
1 parent fc0ee12 commit 49d9588

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

user_sync/connector/directory_ldap.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ def find_ldap_group_dn(self, group):
178178
base_dn = six.text_type(options['base_dn'])
179179
group_filter_format = six.text_type(options['group_filter_format'])
180180
try:
181+
filter_string = self.format_ldap_query_string(group_filter_format, group=group)
181182
res = connection.search_s(base_dn, ldap.SCOPE_SUBTREE,
182-
filterstr=self.format_ldap_query_string(group_filter_format, group=group), attrsonly=1)
183+
filterstr=filter_string, attrsonly=1)
183184
except Exception as e:
184185
raise AssertionException('Unexpected LDAP failure reading group info: %s' % e)
185186
group_dn = None
@@ -327,12 +328,13 @@ def iter_search_result(self, base_dn, scope, filter_string, attributes):
327328
@staticmethod
328329
def format_ldap_query_string(query, **kwargs):
329330
"""
330-
To be used with any string that will be injected into a LDAP query - this escapes a few special characters that
331-
may appear in DNs, group names, etc.
331+
Escape LDAP special characters that may appear in injected query strings
332+
Should be used with any string that will be injected into an LDAP query.
332333
:param query:
333334
:param kwargs:
334335
:return:
335336
"""
337+
# See http://www.rfc-editor.org/rfc/rfc4515.txt
336338
escape_chars = six.text_type('*()\\&|<>~!:')
337339
escaped_args = {}
338340
# kwargs is a dict that would normally be passed to string.format

0 commit comments

Comments
 (0)