Skip to content

When using multiple LDAP servers, do not fail at first server error #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/passport-ldapauth/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ var handleAuthentication = function(req, options) {
return this.fail({ message: options.constraintViolation || 'Exceeded password retry limit, account locked' }, 401);
}

// Other errors are (most likely) real errors
return errorHandler(err);
// Other errors are (most likely) real errors and are handled with the 'error' event listener
return;
}

if (!user) {
Expand Down
39 changes: 39 additions & 0 deletions test/strategy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,43 @@ describe('LDAP authentication strategy', function() {
});
});
});

describe('with multiple server URLs', function() {
after(stop_servers);

it('should fail the authentication with an error when all servers fail', function(cb) {
var TWO_SERVERS_ALL_FAIL = JSON.parse(JSON.stringify(BASE_OPTS));

TWO_SERVERS_ALL_FAIL.server.url = [
'ldap://255.255.255.255', // Unreachable network
'ldap://i.do.not.exist.local:65433' // Non-existing domain
];

start_servers(TWO_SERVERS_ALL_FAIL, BASE_TEST_OPTS)(function() {
request(expressapp)
.post('/login')
.send({username: 'valid', password: 'valid'})
.expect(500)
.end(cb);
});
});

it('should succeed when a server replies with success', function(cb) {
var THREE_SERVERS_LAST_SUCCEEDS = JSON.parse(JSON.stringify(BASE_OPTS));

THREE_SERVERS_LAST_SUCCEEDS.server.url = [
'ldap://255.255.255.255', // Unreachable network
'ldap://i.do.not.exist.local:65433', // Non-existing domain
'ldap://localhost:' + LDAP_PORT.toString()
];

start_servers(THREE_SERVERS_LAST_SUCCEEDS, BASE_TEST_OPTS)(function() {
request(expressapp)
.post('/login')
.send({username: 'valid', password: 'valid'})
.expect(200)
.end(cb);
});
});
});
});