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 13, 2016
1 parent 2891b47 commit a6447db
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 95 deletions.
72 changes: 0 additions & 72 deletions test/oauth2.sub.tokenparams.test.js

This file was deleted.

44 changes: 23 additions & 21 deletions test/oauth2.subclass.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,33 @@ describe('OAuth2Strategy subclass', function() {
return { type: options.type };
}


describe('subclass that overrides tokenParams function', function() {
var strategy = new FooOAuth2Strategy({
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',
},
function(accessToken, refreshToken, profile, done) {
if (accessToken == '2YotnFZFEjr1zCsicMWpAA' && refreshToken == 'tGzv3JOkF0XG5Qx2TlKWIA') {
return done(null, { id: '1234' }, { message: 'Hello' });
}
return done(null, false);
});

// inject a "mock" oauth2 instance
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',
},
function(accessToken, refreshToken, profile, done) {
if (accessToken !== '2YotnFZFEjr1zCsicMWpAA') { return done(new Error('incorrect accessToken argument')); }
if (refreshToken !== 'tGzv3JOkF0XG5Qx2TlKWIA') { return done(new Error('incorrect refreshToken argument')); }

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

strategy._oauth2.getOAuthAccessToken = function(code, options, callback) {
if (code == 'SplxlOBeZQQYbYS6WxSbIA' && options.grant_type == 'authorization_code' && options.redirect_uri == 'https://www.example.net/auth/example/callback' && options.type == 'web_server') {
callback(null, '2YotnFZFEjr1zCsicMWpAA', 'tGzv3JOkF0XG5Qx2TlKWIA', { token_type: 'example' });
} else {
callback(null, 'wrong-access-token', 'wrong-refresh-token');
}
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')); }
if (options.type !== 'web_server') { return callback(new Error('incorrect options.type argument')); }

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

describe('handling an authorized return request', function() {


describe('processing response to authorization request that was approved', function() {
var user
, info;

Expand Down
2 changes: 0 additions & 2 deletions test/oauth2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ describe('OAuth2Strategy', function() {
});

strategy._oauth2.getOAuthAccessToken = function(code, options, callback) {
console.log(options)

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 !== undefined) { return callback(new Error('incorrect options.redirect_uri argument')); }
Expand Down

0 comments on commit a6447db

Please sign in to comment.