ldap: make .build_external_id() resilient to missing attribute (#54080)
This commit is contained in:
parent
019159d30e
commit
a6350703d1
|
@ -1370,7 +1370,10 @@ class LDAPBackend(object):
|
|||
if ':' in attribute:
|
||||
attribute, param = attribute.split(':')
|
||||
quote = 'noquote' not in param.split(',')
|
||||
try:
|
||||
part = attributes[attribute]
|
||||
except KeyError:
|
||||
return None
|
||||
if isinstance(part, list):
|
||||
part = part[0]
|
||||
if quote:
|
||||
|
|
|
@ -1744,3 +1744,10 @@ def test_switch_user_ldap_user(slapd, settings, app, db):
|
|||
assert app.session['_auth_user_backend'] == 'authentic2.backends.ldap_backend.LDAPBackendPasswordLost'
|
||||
template_user = response.context['user']
|
||||
assert 'carlicense' in template_user.get_attributes(object(), {})
|
||||
|
||||
|
||||
def test_build_external_id(slapd, settings, client, db):
|
||||
backend = ldap_backend.LDAPBackend()
|
||||
|
||||
assert backend.build_external_id(['uid'], {'uid': 'john.doe'}) == 'john.doe'
|
||||
assert backend.build_external_id(['uid'], {}) is None
|
||||
|
|
Loading…
Reference in New Issue