Skip to content

Commit

Permalink
[FIX] users_ldap_groups: safe LDAP decode
Browse files Browse the repository at this point in the history
The group mapping in query mode fails if LDAP returns binary data in any
of the fields. This adds a function that handles such situation by
base64 encoding it.
  • Loading branch information
oh2fih committed Dec 25, 2023
1 parent 83060f7 commit 5f6189f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion users_ldap_groups/models/res_company_ldap_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ def equals(self, ldap_entry, mapping):

def query(self, ldap_entry, mapping):
query_string = Template(mapping.value).safe_substitute(
{attr: ldap_entry[1][attr][0].decode() for attr in ldap_entry[1]}
{attr: self.safe_ldap_decode(ldap_entry[1][attr][0]) for attr in ldap_entry[1]}
)

results = mapping.ldap_id._query(mapping.ldap_id.read()[0], query_string)
_logger.debug('Performed LDAP query "%s" results: %s', query_string, results)

return bool(results)

def safe_ldap_decode(self, attr):
import base64
try:
return attr.decode()
except:
return base64.b64encode(attr)

Check warning on line 48 in users_ldap_groups/models/res_company_ldap_operator.py

View check run for this annotation

Codecov / codecov/patch

users_ldap_groups/models/res_company_ldap_operator.py#L47-L48

Added lines #L47 - L48 were not covered by tests

0 comments on commit 5f6189f

Please sign in to comment.