Skip to content

Commit 7be73ea

Browse files
committed
Expand test coverage.
1 parent 2369cde commit 7be73ea

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test/oauth2.subclass.profile.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,56 @@ describe('OAuth2Strategy subclass', function() {
400400
});
401401
}); // skipping user profile due to skipUserProfile asynchronously returning true
402402

403+
describe('error due to skipUserProfile asynchronously returning error', function() {
404+
var strategy = new FooOAuth2Strategy({
405+
authorizationURL: 'https://www.example.com/oauth2/authorize',
406+
tokenURL: 'https://www.example.com/oauth2/token',
407+
clientID: 'ABC123',
408+
clientSecret: 'secret',
409+
callbackURL: 'https://www.example.net/auth/example/callback',
410+
skipUserProfile: function(accessToken, done) {
411+
return done(new Error('something went wrong'));
412+
}
413+
},
414+
function(accessToken, refreshToken, profile, done) {
415+
if (accessToken !== '2YotnFZFEjr1zCsicMWpAA') { return done(new Error('incorrect accessToken argument')); }
416+
if (refreshToken !== 'tGzv3JOkF0XG5Qx2TlKWIA') { return done(new Error('incorrect refreshToken argument')); }
417+
if (profile !== undefined) { return done(new Error('incorrect profile argument')); }
418+
419+
return done(null, { id: '1234' }, { message: 'Hello' });
420+
});
421+
422+
strategy._oauth2.getOAuthAccessToken = function(code, options, callback) {
423+
if (code !== 'SplxlOBeZQQYbYS6WxSbIA') { return callback(new Error('incorrect code argument')); }
424+
if (options.grant_type !== 'authorization_code') { return callback(new Error('incorrect options.grant_type argument')); }
425+
if (options.redirect_uri !== 'https://www.example.net/auth/example/callback') { return callback(new Error('incorrect options.redirect_uri argument')); }
426+
427+
return callback(null, '2YotnFZFEjr1zCsicMWpAA', 'tGzv3JOkF0XG5Qx2TlKWIA', { token_type: 'example' });
428+
}
429+
430+
431+
var request
432+
, err;
433+
434+
before(function(done) {
435+
chai.passport.use(strategy)
436+
.error(function(e) {
437+
err = e;
438+
done();
439+
})
440+
.req(function(req) {
441+
req.query = {};
442+
req.query.code = 'SplxlOBeZQQYbYS6WxSbIA';
443+
})
444+
.authenticate();
445+
});
446+
447+
it('should error', function() {
448+
expect(err).to.be.an.instanceof(Error)
449+
expect(err.message).to.equal('something went wrong');
450+
});
451+
}); // error due to skipUserProfile asynchronously returning error
452+
403453
}); // that overrides userProfile
404454

405455
});

0 commit comments

Comments
 (0)