Skip to content

Commit

Permalink
Increase test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Aug 15, 2013
1 parent a7d5ed7 commit b65e274
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/oauth2.error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,51 @@ describe('OAuth2Strategy', function() {
});
});

describe('that encounters a node-oauth object literal error with nearly-OAuth-compatible body obtaining an access token', 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',
},
function(accessToken, refreshToken, params, profile, done) {
if (accessToken == '2YotnFZFEjr1zCsicMWpAA' && refreshToken == 'tGzv3JOkF0XG5Qx2TlKWIA') {
return done(null, { id: '1234' }, { message: 'Hello' });
}
return done(null, false);
});

// inject a "mock" oauth2 instance
strategy._oauth2.getOAuthAccessToken = function(code, options, callback) {
return callback({ statusCode: 400, data: '{"error_code":"invalid_grant"}'});
}

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

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

it('should error', function() {
expect(err).to.be.an.instanceof(InternalOAuthError)
expect(err.message).to.equal('Failed to obtain access token');
expect(err.oauthError.statusCode).to.equal(400);
expect(err.oauthError.data).to.equal('{"error_code":"invalid_grant"}');
});
});
});

describe('that encounters a node-oauth object literal error with non-OAuth-compatible body obtaining an access token', function() {
var strategy = new OAuth2Strategy({
authorizationURL: 'https://www.example.com/oauth2/authorize',
Expand Down

0 comments on commit b65e274

Please sign in to comment.