Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
chai-passport-strategy
Advanced tools
Helpers for testing Passport strategies with the Chai assertion library.
Helpers for testing Passport strategies with the Chai assertion library.
$ npm install chai-passport-strategy
Use this plugin as you would all other Chai plugins:
var chai = require('chai');
chai.use(require('chai-passport-strategy'));
Once used, the chai.passport.use
helper function will be available to set up
a test case which places a Passport strategy under test.
The helper returns a wrapper on which callbacks are registered to be executed
when the strategy invokes its final action function. The callbacks correspond
to Passport's strategy API: success()
, fail()
, redirect()
, pass()
, and
error()
. If the strategy invokes an action that doesn't have a registered
callback, the test helper will automatically throw an exception.
For example, a Mocha test case that tests a strategy which implements bearer token authentication:
it('should authenticate request with token in header', function(done) {
chai.passport.use(new Strategy(function(token, cb) {
expect(token).to.equal('mF_9.B5f-4.1JqM');
return cb(null, { id: '248289761001' }, { scope: [ 'profile', 'email' ] });
}))
.request(function(req) {
req.headers['authorization'] = 'Bearer mF_9.B5f-4.1JqM';
})
.success(function(user, info) {
expect(user).to.deep.equal({ id: '248289761001' });
expect(info).to.deep.equal({ scope: [ 'profile', 'email' ] });
done();
})
.authenticate();
});
Copyright (c) 2013-2021 Jared Hanson <https://www.jaredhanson.me/>
FAQs
Helpers for testing Passport strategies with the Chai assertion library.
We found that chai-passport-strategy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.