Skip to content

Commit

Permalink
Clean up OAuth failure test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Aug 13, 2013
1 parent 355ea97 commit b698cc9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 58 deletions.
32 changes: 32 additions & 0 deletions test/strategies/oauth.default.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,38 @@ describe('OAuthStrategy', function() {
expect(request.session['oauth']['oauth_token_secret']).to.equal('hdhd0244k9j7ao03');
});
});

describe('handling a callback request that fails verification', function() {
var request
, info;

before(function(done) {
chai.passport(strategy)
.fail(function(i) {
info = i;
done();
})
.req(function(req) {
request = req;
req.query = {};
req.query['oauth_token'] = 'wrong-token';
req.query['oauth_verifier'] = 'wrong-verifier';
req.session = {};
req.session['oauth'] = {};
req.session['oauth']['oauth_token'] = 'hh5s93j4hdidpola';
req.session['oauth']['oauth_token_secret'] = 'hdhd0244k9j7ao03';
})
.authenticate();
});

it('should not supply info', function() {
expect(info).to.be.undefined;
});

it('should remove token and token secret from session', function() {
expect(request.session['oauth']).to.be.undefined;
});
});


describe('with user authorization URL that contains query parameters', function() {
Expand Down
61 changes: 3 additions & 58 deletions test/strategies/oauth.fail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,9 @@ var chai = require('chai')
, OAuthStrategy = require('../../lib/strategies/oauth');


describe('OAuthStrategy that fails verification', function() {

describe('without additional information', function() {

var strategy = new OAuthStrategy({
requestTokenURL: 'https://www.example.com/oauth/request_token',
accessTokenURL: 'https://www.example.com/oauth/access_token',
userAuthorizationURL: 'https://www.example.com/oauth/authorize',
consumerKey: 'ABC123',
consumerSecret: 'secret'
}, function(token, tokenSecret, profile, done) {
return done(null, false);
});

// inject a "mock" oauth instance
strategy._oauth.getOAuthAccessToken = function(token, tokenSecret, verifier, callback) {
if (token == 'hh5s93j4hdidpola' && tokenSecret == 'hdhd0244k9j7ao03' && verifier == 'hfdp7dh39dks9884') {
return callback(null, 'nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00', {});
} else {
return callback(null, 'wrong-token', 'wrong-token-secret');
}
}

describe('handling an authorized callback request', function() {
var request
, info;

before(function(done) {
chai.passport(strategy)
.fail(function(i) {
info = i;
done();
})
.req(function(req) {
request = req;
req.query = {};
req.query['oauth_token'] = 'hh5s93j4hdidpola';
req.query['oauth_verifier'] = 'hfdp7dh39dks9884';
req.session = {};
req.session['oauth'] = {};
req.session['oauth']['oauth_token'] = 'hh5s93j4hdidpola';
req.session['oauth']['oauth_token_secret'] = 'hdhd0244k9j7ao03';
})
.authenticate();
});

it('should not supply info', function() {
expect(info).to.be.undefined;
});

it('should remove token and token secret from session', function() {
expect(request.session['oauth']).to.be.undefined;
});
});
});
describe('OAuthStrategy', function() {

describe('with additional information', function() {

describe('failing verification with additional information', function() {
var strategy = new OAuthStrategy({
requestTokenURL: 'https://www.example.com/oauth/request_token',
accessTokenURL: 'https://www.example.com/oauth/access_token',
Expand All @@ -79,7 +24,7 @@ describe('OAuthStrategy that fails verification', function() {
}
}

describe('handling an authorized callback request', function() {
describe('handling a callback request that fails verification', function() {
var request
, info;

Expand Down

0 comments on commit b698cc9

Please sign in to comment.