ldap: make .build_external_id() resilient to missing attribute (#54080)

This commit is contained in:
Benjamin Dauvergne 2021-05-18 22:53:22 +02:00
parent 019159d30e
commit a6350703d1
2 changed files with 11 additions and 1 deletions

View File

@ -1370,7 +1370,10 @@ class LDAPBackend(object):
if ':' in attribute:
attribute, param = attribute.split(':')
quote = 'noquote' not in param.split(',')
part = attributes[attribute]
try:
part = attributes[attribute]
except KeyError:
return None
if isinstance(part, list):
part = part[0]
if quote:

View File

@ -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