From 0176a9e300062ae2edf2f0ba2e365a8c2c4dbc99 Mon Sep 17 00:00:00 2001 From: sterni Date: Fri, 29 Jan 2021 12:22:40 +0100 Subject: fix(panettone): handle missing DNs when looking up displaynames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix find-user-by-dn raising an error condition if the search returns no results, return nil instead. * Adopt strategy of defaulting to “someone” as displayname if lookup fails for all usage of displaynames in panettone. I've tested this change for issues and comments created by missing users. Adjusting the displayname seems to fix all 500 being created by missing users both logged out and logged in. Change-Id: I0a84eb0631c4a49f1664bed6d03afa60dce6eb47 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2448 Tested-by: BuildkiteCI Reviewed-by: glittershark --- web/panettone/src/authentication.lisp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'web/panettone/src/authentication.lisp') diff --git a/web/panettone/src/authentication.lisp b/web/panettone/src/authentication.lisp index 2051025753..50befbc7a1 100644 --- a/web/panettone/src/authentication.lisp +++ b/web/panettone/src/authentication.lisp @@ -79,12 +79,18 @@ and a retry" (defun find-user-by-dn (dn) (with-ldap () - (progn - (ldap:search *ldap* `(= objectClass organizationalPerson) - :base dn - :scope 'ldap:base) - (when-let ((ldap-entry (ldap:next-search-result *ldap*))) - (ldap-entry->user ldap-entry))))) + (let ((have-results + (handler-case + (ldap:search *ldap* `(= objectClass organizationalPerson) + :base dn + :scope 'ldap:base) + ; catch ldap-errors generated by trivial-ldap:parse-ldap-message + ; since this is thrown on conditions which we don't want this + ; function to fail like when there are no search results + (trivial-ldap:ldap-error (e) nil)))) + (when have-results + (when-let ((ldap-entry (ldap:next-search-result *ldap*))) + (ldap-entry->user ldap-entry)))))) (comment (find-user-by-dn "cn=glittershark,ou=users,dc=tvl,dc=fyi") -- cgit 1.4.1