Skip to content

Commit

Permalink
* fixing bug where no user results would cause unpredictable behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
bhoriuchi committed Aug 18, 2016
1 parent 5b4d563 commit 8962a18
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ Strategy.prototype.authenticate = function (req) {

return this._ad.find({ filter: filter, attributes: attributes }, function (err, results) {
if (err) return _this.error(err);
var users = results.users;
if (!Array.isArray(users) || !users.length) return _this.fail('The user "' + username + '" was not found');
var userProfile = _this.mapProfile(users[0]);
if (!results || !results.users || !Array.isArray(results.users) || !results.users.length) {
return _this.fail('The user "' + username + '" was not found');
}
var userProfile = _this.mapProfile(results.users[0]);
return _this._integrated ? verify(userProfile) : auth(userProfile);
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passport-activedirectory",
"version": "1.0.2",
"version": "1.0.3",
"description": "Active Directory strategy for passport.js",
"license": "MIT",
"main": "index.js",
Expand Down
7 changes: 4 additions & 3 deletions src/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ Strategy.prototype.authenticate = function (req, options = {}) {

return this._ad.find({ filter, attributes }, (err, results) => {
if (err) return this.error(err)
let users = results.users
if (!Array.isArray(users) || !users.length) return this.fail(`The user "${username}" was not found`)
let userProfile = this.mapProfile(users[0])
if (!results || !results.users || !Array.isArray(results.users) || !results.users.length) {
return this.fail(`The user "${username}" was not found`)
}
let userProfile = this.mapProfile(results.users[0])
return this._integrated ? verify(userProfile) : auth(userProfile)
})
}
Expand Down

0 comments on commit 8962a18

Please sign in to comment.