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
2 changes: 1 addition & 1 deletion lib/passport-http/strategies/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ BasicStrategy.prototype.authenticate = function(req) {
if (parts.length < 2) { return this.fail(400); }

var scheme = parts[0]
, credentials = new Buffer(parts[1], 'base64').toString().split(':');
, 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); }
Expand Down
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 containing a colon in the password': {
topic: function() {
var strategy = new BasicStrategy(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 Ym9iOnNlY3JldDpwYXNzd29yZA==';
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, 'secret:password');
},
},
},

}).export(module);