summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-06-08 03:56:39 +0000
committerGerrit Code Review <review@openstack.org>2022-06-08 03:56:39 +0000
commitf4946fc8640cba9014856c93dbbedfef40367416 (patch)
tree217c200595a23b5dcdc7bfad09784fddb88499a1
parente8045af63119b201093c424d5f8d029535197c97 (diff)
parentd4062b2c14715a9d98b631c7b54e865b29b83783 (diff)
downloadkeystone-f4946fc8640cba9014856c93dbbedfef40367416.tar.gz
Merge "Fix issue with LDAP backend returning bytes instead of string" into stable/victoria
-rw-r--r--keystone/identity/backends/ldap/common.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/keystone/identity/backends/ldap/common.py b/keystone/identity/backends/ldap/common.py
index 4af42de29..1033a4efd 100644
--- a/keystone/identity/backends/ldap/common.py
+++ b/keystone/identity/backends/ldap/common.py
@@ -1401,9 +1401,24 @@ class BaseLdap(object):
pass
else:
try:
- obj[k] = v[0]
+ value = v[0]
except IndexError:
- obj[k] = None
+ value = None
+
+ # NOTE(xek): Some LDAP servers return bytes data type
+ # We convert it to string here, so that it is consistent with
+ # the other (SQL) backends.
+ # Bytes data type caused issues in the past, because it could
+ # be cached and then passed into str() method to be used as
+ # LDAP filters, which results in an unexpected b'...' prefix.
+ if isinstance(value, bytes):
+ try:
+ value = value.decode('utf-8')
+ except UnicodeDecodeError:
+ LOG.error("Error decoding value %r (object id %r).",
+ value, res[0])
+ raise
+ obj[k] = value
return obj