Skip to content

Commit

Permalink
Clarify test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 12, 2016
1 parent a231390 commit 3a66eb8
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 138 deletions.
138 changes: 0 additions & 138 deletions test/oauth2.passreq.test.js

This file was deleted.

113 changes: 113 additions & 0 deletions test/oauth2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,119 @@ describe('OAuth2Strategy', function() {
});
}); // that was approved using verify callback that accepts params

describe('that was approved using verify callback, in passReqToCallback mode', function() {
var strategy = new OAuth2Strategy({
authorizationURL: 'https://www.example.com/oauth2/authorize',
tokenURL: 'https://www.example.com/oauth2/token',
clientID: 'ABC123',
clientSecret: 'secret',
callbackURL: 'https://www.example.net/auth/example/callback',
passReqToCallback: true
},
function(req, accessToken, refreshToken, profile, done) {
if (req.method != 'GET') { return done(new Error('incorrect req argument')); }
if (accessToken !== '2YotnFZFEjr1zCsicMWpAA') { return done(new Error('incorrect accessToken argument')); }
if (refreshToken !== 'tGzv3JOkF0XG5Qx2TlKWIA') { return done(new Error('incorrect refreshToken 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._oauth2.getOAuthAccessToken = function(code, options, callback) {
if (code !== 'SplxlOBeZQQYbYS6WxSbIA') { return callback(new Error('incorrect code argument')); }
if (options.grant_type !== 'authorization_code') { return callback(new Error('incorrect options.grant_type argument')); }
if (options.redirect_uri !== 'https://www.example.net/auth/example/callback') { return callback(new Error('incorrect options.redirect_uri argument')); }

return callback(null, '2YotnFZFEjr1zCsicMWpAA', 'tGzv3JOkF0XG5Qx2TlKWIA', { token_type: 'example', expires_in: 3600 });
}


var user
, info;

before(function(done) {
chai.passport.use(strategy)
.success(function(u, i) {
user = u;
info = i;
done();
})
.req(function(req) {
req.query = {};
req.query.code = 'SplxlOBeZQQYbYS6WxSbIA';
})
.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');
});
}); // 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 OAuth2Strategy({
authorizationURL: 'https://www.example.com/oauth2/authorize',
tokenURL: 'https://www.example.com/oauth2/token',
clientID: 'ABC123',
clientSecret: 'secret',
callbackURL: 'https://www.example.net/auth/example/callback',
passReqToCallback: true
},
function(req, accessToken, refreshToken, params, profile, done) {
if (req.method != 'GET') { return done(new Error('incorrect req argument')); }
if (accessToken !== '2YotnFZFEjr1zCsicMWpAA') { return done(new Error('incorrect accessToken argument')); }
if (refreshToken !== 'tGzv3JOkF0XG5Qx2TlKWIA') { return done(new Error('incorrect refreshToken argument')); }
if (params.example_parameter !== 'example_value') { return done(new Error('incorrect params 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._oauth2.getOAuthAccessToken = function(code, options, callback) {
if (code !== 'SplxlOBeZQQYbYS6WxSbIA') { return callback(new Error('incorrect code argument')); }
if (options.grant_type !== 'authorization_code') { return callback(new Error('incorrect options.grant_type argument')); }
if (options.redirect_uri !== 'https://www.example.net/auth/example/callback') { return callback(new Error('incorrect options.redirect_uri argument')); }

return callback(null, '2YotnFZFEjr1zCsicMWpAA', 'tGzv3JOkF0XG5Qx2TlKWIA', { token_type: 'example', expires_in: 3600, example_parameter: 'example_value' });
}


var user
, info;

before(function(done) {
chai.passport.use(strategy)
.success(function(u, i) {
user = u;
info = i;
done();
})
.req(function(req) {
req.query = {};
req.query.code = 'SplxlOBeZQQYbYS6WxSbIA';
})
.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');
});
}); // 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 OAuth2Strategy({
authorizationURL: 'https://www.example.com/oauth2/authorize',
Expand Down

0 comments on commit 3a66eb8

Please sign in to comment.