From f38f75202964061899dfe720c6d157d10f8106de Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Thu, 15 Jun 2017 00:12:38 +0300 Subject: [PATCH] Fix exception when the attribute_name is dn/distinguishedName and the search fails When the search fails to find the user, the search result doesn't necessarily contain `dn`/`distinguishedName`. Trying to get it will cause an exception instead of returning an "unknown" status. This should fix the issue, but note that I'm recalling the fix from memory and I didn't test this. --- devpi_ldap/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/devpi_ldap/main.py b/devpi_ldap/main.py index ecfc72e..e0a2d96 100644 --- a/devpi_ldap/main.py +++ b/devpi_ldap/main.py @@ -180,7 +180,10 @@ def extract_search(s): return [] elif attribute_name in ('dn', 'distinguishedName'): def extract_search(s): - return [s[attribute_name]] + if attribute_name in s: + return [s[attribute_name]] + else: + return [] else: threadlog.error('configured attribute_name {} not found in any search results'.format(attribute_name)) return []