Skip to content

Commit 8bc787e

Browse files
committed
Test case for invalid PLAINTEXT signature.
1 parent 2ac56e1 commit 8bc787e

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

lib/passport-http-oauth/strategies/token.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ TokenStrategy.prototype.authenticate = function(req) {
175175
var computedSignature = utils.plaintext(consumerSecret, tokenSecret);
176176

177177
if (signature !== computedSignature) {
178-
return self.fail(self._challenge());
178+
return self.fail(self._challenge('signature_invalid'));
179179
}
180180
} else{
181181
return self.fail(self._challenge('signature_method_rejected'), 400);

test/strategies/token-test.js

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ vows.describe('TokenStrategy').addBatch({
8282
},
8383
},
8484

85-
'strategy handling a valid request with credentials in header using PLAINTEXT method': {
85+
'strategy handling a valid request with credentials in header using PLAINTEXT signature': {
8686
topic: function() {
8787
var strategy = new TokenStrategy(
8888
// consumer callback
@@ -548,7 +548,58 @@ vows.describe('TokenStrategy').addBatch({
548548
},
549549
},
550550

551-
// TODO: Implement test case for invalid PLAINTEXT signature
551+
'strategy handling a request with invalid PLAINTEXT signature': {
552+
topic: function() {
553+
var strategy = new TokenStrategy(
554+
// consumer callback
555+
function(consumerKey, done) {
556+
done(null, { id: '1' }, 'ssh-secret');
557+
},
558+
// verify callback
559+
function(accessToken, done) {
560+
done(null, { username: 'bob' }, 'not-mmyauoBm7rRv0kLsNKAicmtsxsxKWJDmoEo7obTqglkyGNHs8hn78pkTj70tXatl');
561+
}
562+
);
563+
return strategy;
564+
},
565+
566+
'after augmenting with actions': {
567+
topic: function(strategy) {
568+
var self = this;
569+
var req = {};
570+
strategy.success = function(user, info) {
571+
self.callback(new Error('should not be called'));
572+
}
573+
strategy.fail = function(challenge, status) {
574+
self.callback(null, challenge, status);
575+
}
576+
strategy.error = function(err) {
577+
self.callback(new Error('should not be called'));
578+
}
579+
580+
req.url = '/api/userinfo';
581+
req.method = 'GET';
582+
req.headers = {};
583+
req.headers['host'] = '127.0.0.1:3000';
584+
req.headers['authorization'] = 'OAuth oauth_consumer_key="abc123",oauth_nonce="bSzaRm1X9uu6DwjAuAsOnn6cnxYoVibS",oauth_signature_method="PLAINTEXT",oauth_timestamp="1341195485",oauth_token="Xe4F8Cf5vw68BoZF",oauth_version="1.0",oauth_signature="ssh-secret%2526mmyauoBm7rRv0kLsNKAicmtsxsxKWJDmoEo7obTqglkyGNHs8hn78pkTj70tXatl"';
585+
req.query = url.parse(req.url, true).query;
586+
req.connection = { encrypted: false };
587+
process.nextTick(function () {
588+
strategy.authenticate(req);
589+
});
590+
},
591+
592+
'should not generate an error' : function(err, challenge, status) {
593+
assert.isNull(err);
594+
},
595+
'should respond with challenge' : function(err, challenge, status) {
596+
assert.equal(challenge, 'OAuth realm="Users", oauth_problem="signature_invalid"');
597+
},
598+
'should respond with default status' : function(err, challenge, status) {
599+
assert.isUndefined(status);
600+
},
601+
},
602+
},
552603

553604
'strategy handling a request with unknown signature method': {
554605
topic: function() {

0 commit comments

Comments
 (0)