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
4 changes: 3 additions & 1 deletion lib/passport-http/strategies/digest.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ DigestStrategy.prototype.authenticate = function(req) {
if (!creds.username) {
return this.fail(this._challenge());
}
if (req.url !== creds.uri) {

var url = req.originalUrl || req.url;
if (url !== creds.uri) {
return this.fail(400);
}

Expand Down
43 changes: 43 additions & 0 deletions test/strategies/digest-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,49 @@ vows.describe('DigestStrategy').addBatch({
},
},

'strategy handling a request for endpoint mounted with `app.use` at a different route': {
topic: function() {
var strategy = new DigestStrategy(
function(username, done) {
done(null, { username: username }, 'secret');
},
function(options, done) {
done(null, true);
}
);
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.url = '/login';
req.originalUrl = '/auth/login';
req.method = 'HEAD';
req.headers = {};
req.headers.authorization = 'Digest username="bob", realm="Users", nonce="NOIEDJ3hJtqSKaty8KF8xlkaYbItAkiS", uri="/auth/login", response="966fae1f81aa1bb0e413e0e832e647c0"';
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');
},
},
},

'strategy handling a request with unknown algorithm': {
topic: function() {
var strategy = new DigestStrategy({ algorithm: 'MD5' },
Expand Down