Skip to content
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
5 changes: 3 additions & 2 deletions lib/passport-http/strategies/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function BasicStrategy(options, verify) {
this._verify = verify;
this._realm = options.realm || 'Users';
this._passReqToCallback = options.passReqToCallback;
this._acceptEmptyPassword = options.acceptEmptyPassword;
}

/**
Expand All @@ -75,11 +76,11 @@ BasicStrategy.prototype.authenticate = function(req) {
, credentials = new Buffer(parts[1], 'base64').toString().split(':');

if (!/Basic/i.test(scheme)) { return this.fail(this._challenge()); }
if (credentials.length < 2) { return this.fail(400); }
if (!this._acceptEmptyPassword && (credentials.length < 2)) { return this.fail(400); }

var userid = credentials[0];
var password = credentials[1];
if (!userid || !password) {
if (!userid || (!password && !this._acceptEmptyPassword)) {
return this.fail(this._challenge());
}

Expand Down
26 changes: 19 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
"name": "passport-http",
"version": "0.2.2",
"description": "HTTP Basic and Digest authentication strategies for Passport.",
"keywords": ["passport", "http", "basic", "digest", "auth", "authn", "authentication"],
"keywords": [
"passport",
"http",
"basic",
"digest",
"auth",
"authn",
"authentication"
],
"repository": {
"type": "git",
"url": "git://github.com/jaredhanson/passport-http.git"
Expand All @@ -15,20 +23,24 @@
"email": "jaredhanson@gmail.com",
"url": "http://www.jaredhanson.net/"
},
"licenses": [ {
"type": "MIT",
"url": "http://www.opensource.org/licenses/MIT"
} ],
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/MIT"
}
],
"main": "./lib/passport-http",
"dependencies": {
"pkginfo": "0.2.x",
"passport": "~0.1.3"
},
"devDependencies": {
"vows": "0.6.x"
"vows": "^0.7.0"
},
"scripts": {
"test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js test/**/*-test.js"
},
"engines": { "node": ">= 0.4.0" }
"engines": {
"node": ">= 0.4.0"
}
}
36 changes: 36 additions & 0 deletions test/strategies/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,40 @@ vows.describe('BasicStrategy').addBatch({
},
},

'strategy handling a request with empty password with acceptEmptyPassword=true option': {
topic: function() {
var strategy = new BasicStrategy({acceptEmptyPassword:true}, function(userid, password, done) {
done(null, { username: userid, password: password });
});
return strategy;
},

'after augmenting with actions': {
topic: function(strategy) {
var self = this;
var req = {};
strategy.success = function(user) {
self.callback(null, user);
}
strategy.fail = function() {
self.callback(new Error('should not be called'));
}

req.headers = {};
req.headers.authorization = 'Basic Ym9iOg==';
process.nextTick(function () {
strategy.authenticate(req);
});
},

'should not generate an error' : function(err, user) {
assert.isNull(err);
},
'should authenticate' : function(err, user) {
assert.equal(user.username, 'bob');
assert.equal(user.password, '');
},
},
},

}).export(module);