Skip to content

Commit

Permalink
More ECONNRESET fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
smattingly committed Jan 14, 2021
1 parent 06e653a commit af5354d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions api/helpers/ldap-authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,36 @@ module.exports = {
let client = ldap.createClient(clientOptions);

client.on("error", function (error) {
_handleError(`LDAP client error handler: ${error.message}`);
return _handleError(`LDAP client error handler: ${error.message}`);
});

client.on("connectError", function (error) {
_handleError(`LDAP connectError handler: ${error.message}`);
return _handleError(`LDAP connectError handler: ${error.message}`);
});

client.on("connect", function (_socket, error) {
if (error) {
_handleError(`LDAP connect handler: ${error.message}`);
return _handleError(`LDAP connect handler: ${error.message}`);
}

client.bind(inputs.username, inputs.password, function (error) {
if (error) {
if (error instanceof ldap.InvalidCredentialsError) {
client.destroy(); // Must destroy client before resolving
resolve(error);
return resolve(error);
}
_handleError(`LDAP bind handler: ${error.message}`);
return _handleError(`LDAP bind handler: ${error.message}`);
}

// Authentication was successful. Get information about user.
ldapConfig.searchOptions.filter = `(userPrincipalName=${inputs.username})`;
client.search(ldapConfig.searchBaseDn, ldapConfig.searchOptions, function (error, searchResponse) {
if (error) {
_handleError(`LDAP client search: ${error.message}`);
return _handleError(`LDAP client search: ${error.message}`);
}

searchResponse.on("error", function (error) {
_handleError(`LDAP search response error handler: ${error.message}`);
return _handleError(`LDAP search response error handler: ${error.message}`);
});

searchResponse.on("searchEntry", function (entry) {
Expand All @@ -85,11 +85,10 @@ module.exports = {

// User must have at least one role.
if (!result.role) {
resolve(new ldap.InsufficientAccessRightsError());
sails.log.error("resolve returned (this should never print ?!)");
return resolve(new ldap.InsufficientAccessRightsError());
}

resolve(result);
return resolve(result);
});
});
});
Expand All @@ -98,7 +97,7 @@ module.exports = {
function _handleError(message) {
sails.log.warn(message);
client.destroy(); // Must destroy client before resolving
resolve(new ldap.UnavailableError());
return resolve(new ldap.UnavailableError());
}
}));
}
Expand Down
2 changes: 1 addition & 1 deletion config/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


module.exports.bootstrap = async function () {
sails.log.info(await sails.helpers.getStatus());
sails.log.debug(await sails.helpers.getStatus());

if (sails.config.environment !== "production") {
// The following models should create reference records for use in all
Expand Down

0 comments on commit af5354d

Please sign in to comment.