Skip to content

Commit

Permalink
More test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 3, 2016
1 parent 742f428 commit d175fee
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion test/strategy.test.js
Expand Up @@ -125,6 +125,60 @@ describe('Strategy', function() {
expect(err.message).to.equal('The code passed is incorrect or expired.');
expect(err.code).to.equal('bad_verification_code');
});
}); // error caused by invalid code sent to token endpoint, with response indicating success
}); // error caused by invalid code sent to token endpoint, with response erroneously indicating success

describe('error caused by invalid code sent to token endpoint, with response correctly indicating success', function() {
var OAuth2Strategy = require('passport-oauth2').Strategy;
var OAuth2;
if (existsSync('node_modules/oauth')) { // npm 3.x
OAuth2 = require('oauth').OAuth2;
} else {
OAuth2 = require('passport-oauth2/node_modules/oauth').OAuth2;
}

var MockOAuth2Strategy = function(options, verify) {
OAuth2Strategy.call(this, options, verify);

this._oauth2 = new OAuth2(options.clientID, options.clientSecret,
'', options.authorizationURL, options.tokenURL, options.customHeaders);
this._oauth2.getOAuthAccessToken = function(code, options, callback) {
return callback({
statusCode: 401,
data: '{"error":"bad_verification_code","error_description":"The code passed is incorrect or expired.","error_uri":"https://developer.github.com/v3/oauth/#bad-verification-code"}' });
};
}
util.inherits(MockOAuth2Strategy, OAuth2Strategy);

var GitHubStrategy = $require('../lib/strategy', {
'passport-oauth2': MockOAuth2Strategy
})

var strategy = new GitHubStrategy({
clientID: 'ABC123',
clientSecret: 'secret'
}, function() {});


var err;

before(function(done) {
chai.passport.use(strategy)
.error(function(e) {
err = e;
done();
})
.req(function(req) {
req.query = {};
req.query.code = 'SplxlOBeZQQYbYS6WxSbIA+ALT1';
})
.authenticate();
});

it('should error', function() {
expect(err.constructor.name).to.equal('TokenError');
expect(err.message).to.equal('The code passed is incorrect or expired.');
expect(err.code).to.equal('bad_verification_code');
});
}); // error caused by invalid code sent to token endpoint, with response correctly indicating success

});

0 comments on commit d175fee

Please sign in to comment.