Skip to content

Commit

Permalink
Clarify passReqToCallback test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 10, 2016
1 parent 0f4f8d9 commit 8618111
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 151 deletions.
151 changes: 0 additions & 151 deletions test/oauth.passreq.test.js

This file was deleted.

133 changes: 133 additions & 0 deletions test/oauth.test.js
Expand Up @@ -394,6 +394,139 @@ describe('OAuthStrategy', function() {
});
}); // that was approved using verify callback that accepts params

describe('that was approved using verify callback, in passReqToCallback mode', 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',
passReqToCallback: true
}, function(req, token, tokenSecret, profile, done) {
if (req.method != 'GET') { return callback(new Error('incorrect req argument')); }
if (token != 'nnch734d00sl2jdk') { return callback(new Error('incorrect token argument')); }
if (tokenSecret != 'pfkkdhi9sl3r4s00') { return callback(new Error('incorrect tokenSecret argument')); }
if (typeof profile !== 'object') { return done(new Error('incorrect profile argument')); }
if (Object.keys(profile).length !== 0) { return done(new Error('incorrect profile argument')); }

return done(null, { id: '1234' }, { message: 'Hello' });
});

strategy._oauth.getOAuthAccessToken = function(token, tokenSecret, verifier, callback) {
if (token != 'hh5s93j4hdidpola') { return callback(new Error('incorrect token argument')); }
if (tokenSecret != 'hdhd0244k9j7ao03') { return callback(new Error('incorrect tokenSecret argument')); }
if (verifier != 'hfdp7dh39dks9884') { return callback(new Error('incorrect verifier argument')); }

return callback(null, 'nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00', {});
};


var request
, user
, info;

before(function(done) {
chai.passport.use(strategy)
.success(function(u, i) {
user = u;
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 supply user', function() {
expect(user).to.be.an.object;
expect(user.id).to.equal('1234');
});

it('should supply info', function() {
expect(info).to.be.an.object;
expect(info.message).to.equal('Hello');
});

it('should remove token and token secret from session', function() {
expect(request.session['oauth']).to.be.undefined;
});
}); // that was approved using verify callback, in passReqToCallback mode

describe('that was approved using verify callback that accepts params, in passReqToCallback mode', 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',
passReqToCallback: true
}, function(req, token, tokenSecret, params, profile, done) {
if (req.method != 'GET') { return callback(new Error('incorrect req argument')); }
if (token != 'nnch734d00sl2jdk') { return callback(new Error('incorrect token argument')); }
if (tokenSecret != 'pfkkdhi9sl3r4s00') { return callback(new Error('incorrect tokenSecret argument')); }
if (typeof profile !== 'object') { return done(new Error('incorrect profile argument')); }
if (Object.keys(profile).length !== 0) { return done(new Error('incorrect profile argument')); }
if (params.elephant != 'purple') { return callback(new Error('incorrect params argument')); }

return done(null, { id: '1234' }, { message: 'Hello' });
});

strategy._oauth.getOAuthAccessToken = function(token, tokenSecret, verifier, callback) {
if (token != 'hh5s93j4hdidpola') { return callback(new Error('incorrect token argument')); }
if (tokenSecret != 'hdhd0244k9j7ao03') { return callback(new Error('incorrect tokenSecret argument')); }
if (verifier != 'hfdp7dh39dks9884') { return callback(new Error('incorrect verifier argument')); }

return callback(null, 'nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00', { elephant: 'purple' });
};


var request
, user
, info;

before(function(done) {
chai.passport.use(strategy)
.success(function(u, i) {
user = u;
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 supply user', function() {
expect(user).to.be.an.object;
expect(user.id).to.equal('1234');
});

it('should supply info', function() {
expect(info).to.be.an.object;
expect(info.message).to.equal('Hello');
});

it('should remove token and token secret from session', function() {
expect(request.session['oauth']).to.be.undefined;
});
}); // that was approved using verify callback that accepts params, in passReqToCallback mode

describe('that fails due to verify callback supplying false', function() {
var strategy = new OAuthStrategy({
requestTokenURL: 'https://www.example.com/oauth/request_token',
Expand Down

0 comments on commit 8618111

Please sign in to comment.