diff --git a/src/externalldap.js b/src/externalldap.js index 3e09e51e6..7dc26e94c 100644 --- a/src/externalldap.js +++ b/src/externalldap.js @@ -83,8 +83,8 @@ function testConfig(config, callback) { if (error) return callback(new BoxError(BoxError.EXTERNAL_ERROR, error)); result.on('searchEntry', function (/* entry */) {}); - result.on('error', function (error) { callback(new BoxError(BoxError.BAD_FIELD, `Unable to search directory: ${error.message}`)); }); - result.on('end', function (/* result */) { callback(); }); + result.on('error', function (error) { client.unbind(); callback(new BoxError(BoxError.BAD_FIELD, `Unable to search directory: ${error.message}`)); }); + result.on('end', function (/* result */) { client.unbind(); callback(); }); }); }); } @@ -179,6 +179,11 @@ function sync(progressCallback, callback) { const username = user[externalLdapConfig.usernameField]; + if (!username) { + debug(`[empty username] username=${username} email=${user.mail} cn=${user.cn} usernameField=${externalLdapConfig.usernameField}`); + return iteratorCallback(); + } + users.getByUsername(username, function (error, result) { if (error && error.reason !== BoxError.NOT_FOUND) { debug(`Could not find user with username ${username}: ${error.message}`); @@ -213,6 +218,7 @@ function sync(progressCallback, callback) { }); }, function () { debug('User sync done.'); + client.unbind(); callback(); }); });