Ensure ldap client always has an error handler

This commit is contained in:
Johannes Zellner
2023-01-12 14:39:58 +01:00
parent e9168092f7
commit 41b03e3fef

View File

@@ -83,17 +83,18 @@ async function getClient(externalLdapConfig, options) {
throw new BoxError(BoxError.INTERNAL_ERROR, e);
}
// skip bind auth if none exist or if not wanted
if (!externalLdapConfig.bindDn || !options.bind) return client;
return await new Promise((resolve, reject) => {
reject = once(reject);
// ensure we don't just crash
client.on('error', function (error) {
console.error('ExternalLdap client error:', error);
reject(new BoxError(BoxError.EXTERNAL_ERROR, error));
});
// skip bind auth if none exist or if not wanted
if (!externalLdapConfig.bindDn || !options.bind) return resolve(client);
client.bind(externalLdapConfig.bindDn, externalLdapConfig.bindPassword, function (error) {
if (error instanceof ldap.InvalidCredentialsError) return reject(new BoxError(BoxError.INVALID_CREDENTIALS));
if (error) return reject(new BoxError(BoxError.EXTERNAL_ERROR, error));