From d53ff7df95a11e7241e35dcf7d139a03fc74d5d5 Mon Sep 17 00:00:00 2001 From: Iyanu-Tomiwa Date: Fri, 14 Sep 2018 20:57:35 +0100 Subject: [PATCH] Added eslint configuration, and fixed a pletora of lint errors --- .eslintignore | 3 + .eslintrc.js | 24 + lib/authenticator.js | 148 +- lib/errors/authenticationerror.js | 3 + lib/framework/connect.js | 32 +- lib/http/request.js | 50 +- lib/index.js | 10 +- lib/middleware/authenticate.js | 185 +- lib/middleware/initialize.js | 3 +- lib/sessionmanager.js | 20 +- lib/strategies/session.js | 24 +- package-lock.json | 1554 ++++++++++++++++- package.json | 8 +- test/authenticator.framework.test.js | 64 +- test/authenticator.middleware.test.js | 247 +-- test/authenticator.test.js | 1078 ++++++------ test/bootstrap/node.js | 2 +- test/http/request.test.js | 505 +++--- .../authenticate.error.callback.test.js | 86 +- test/middleware/authenticate.error.test.js | 40 +- .../authenticate.fail.callback.test.js | 314 ++-- .../authenticate.fail.flash.test.js | 954 +++++----- .../authenticate.fail.message.test.js | 170 +- .../authenticate.fail.multi.test.js | 317 ++-- test/middleware/authenticate.fail.test.js | 412 +++-- test/middleware/authenticate.pass.test.js | 41 +- test/middleware/authenticate.redirect.test.js | 122 +- .../authenticate.success.callback.test.js | 107 +- .../authenticate.success.flash.test.js | 1014 ++++++----- .../authenticate.success.info.test.js | 175 +- .../authenticate.success.message.test.js | 192 +- .../authenticate.success.multi.test.js | 86 +- test/middleware/authenticate.success.test.js | 305 ++-- test/middleware/authenticate.test.js | 49 +- test/middleware/initialize.test.js | 146 +- test/package.test.js | 16 +- test/strategies/session.test.js | 252 +-- 37 files changed, 5391 insertions(+), 3367 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..1fda7392 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +.git +coverage/ +node_modules/ \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..b69e83d6 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,24 @@ +module.exports = { + env: { + // jest: true, + mocha: true, + node: true, + }, + extends: [ + 'airbnb-base', + ], + plugins: [ + // 'jest' + ], + rules: { + "comma-dangle": 0, + "no-underscore-dangle": 0, + "no-param-reassign": 0, + "prefer-destructuring": 0, + // 'jest/no-disabled-tests': [2], + // 'jest/no-focused-tests': [2], + // 'jest/no-identical-title': [2], + // 'jest/prefer-to-have-length': [2], + // 'jest/valid-expect': [2], + } + }; \ No newline at end of file diff --git a/lib/authenticator.js b/lib/authenticator.js index e6326faa..c0a400ca 100644 --- a/lib/authenticator.js +++ b/lib/authenticator.js @@ -1,8 +1,12 @@ /** * Module dependencies. */ -var SessionStrategy = require('./strategies/session') - , SessionManager = require('./sessionmanager'); + +/* eslint-disable no-underscore-dangle, camelcase, no-proto, no-shadow */ + +const SessionStrategy = require('./strategies/session'); +const SessionManager = require('./sessionmanager'); +const connect = require('./framework/connect'); /** @@ -18,7 +22,7 @@ function Authenticator() { this._infoTransformers = []; this._framework = null; this._userProperty = 'user'; - + this.init(); } @@ -27,8 +31,8 @@ function Authenticator() { * * @api protected */ -Authenticator.prototype.init = function() { - this.framework(require('./framework/connect')()); +Authenticator.prototype.init = function init() { + this.framework(connect()); this.use(new SessionStrategy(this.deserializeUser.bind(this))); this._sm = new SessionManager({ key: this._key }, this.serializeUser.bind(this)); }; @@ -48,13 +52,13 @@ Authenticator.prototype.init = function() { * @return {Authenticator} for chaining * @api public */ -Authenticator.prototype.use = function(name, strategy) { +Authenticator.prototype.use = function use(name, strategy) { if (!strategy) { strategy = name; name = strategy.name; } if (!name) { throw new Error('Authentication strategies must have a name'); } - + this._strategies[name] = strategy; return this; }; @@ -78,7 +82,7 @@ Authenticator.prototype.use = function(name, strategy) { * @return {Authenticator} for chaining * @api public */ -Authenticator.prototype.unuse = function(name) { +Authenticator.prototype.unuse = function unuse(name) { delete this._strategies[name]; return this; }; @@ -102,7 +106,7 @@ Authenticator.prototype.unuse = function(name) { * @return {Authenticator} for chaining * @api public */ -Authenticator.prototype.framework = function(fw) { +Authenticator.prototype.framework = function framework(fw) { this._framework = fw; return this; }; @@ -126,10 +130,10 @@ Authenticator.prototype.framework = function(fw) { * @return {Function} middleware * @api public */ -Authenticator.prototype.initialize = function(options) { +Authenticator.prototype.initialize = function initialize(options) { options = options || {}; this._userProperty = options.userProperty || 'user'; - + return this._framework.initialize(this, options); }; @@ -139,7 +143,10 @@ Authenticator.prototype.initialize = function(options) { * * Examples: * - * passport.authenticate('local', { successRedirect: '/', failureRedirect: '/login' })(req, res); + * passport.authenticate('local', { + * successRedirect: '/', + * failureRedirect: '/login' + * })(req, res); * * passport.authenticate('local', function(err, user) { * if (!user) { return res.redirect('/login'); } @@ -161,7 +168,7 @@ Authenticator.prototype.initialize = function(options) { * @return {Function} middleware * @api public */ -Authenticator.prototype.authenticate = function(strategy, options, callback) { +Authenticator.prototype.authenticate = function authenticate(strategy, options, callback) { return this._framework.authenticate(this, strategy, options, callback); }; @@ -185,11 +192,11 @@ Authenticator.prototype.authenticate = function(strategy, options, callback) { * @return {Function} middleware * @api public */ -Authenticator.prototype.authorize = function(strategy, options, callback) { +Authenticator.prototype.authorize = function authorize(strategy, options, callback) { options = options || {}; options.assignProperty = 'account'; - - var fn = this._framework.authorize || this._framework.authenticate; + + const fn = this._framework.authorize || this._framework.authenticate; return fn(this, strategy, options, callback); }; @@ -222,7 +229,7 @@ Authenticator.prototype.authorize = function(strategy, options, callback) { * @return {Function} middleware * @api public */ -Authenticator.prototype.session = function(options) { +Authenticator.prototype.session = function session(options) { return this.authenticate('session', options); }; @@ -245,51 +252,54 @@ Authenticator.prototype.sessionManager = function(mgr) { * * @api public */ -Authenticator.prototype.serializeUser = function(fn, req, done) { + +// eslint-disable-next-line consistent-return +Authenticator.prototype.serializeUser = function serializeUser(fn, req, done) { if (typeof fn === 'function') { return this._serializers.push(fn); } - + // private implementation that traverses the chain of serializers, attempting // to serialize a user - var user = fn; + const user = fn; // For backwards compatibility if (typeof req === 'function') { done = req; req = undefined; } - - var stack = this._serializers; + + const stack = this._serializers; + // eslint-disable-next-line consistent-return (function pass(i, err, obj) { // serializers use 'pass' as an error to skip processing - if ('pass' === err) { + if (err === 'pass') { err = undefined; } // an error or serialized object was obtained, done if (err || obj || obj === 0) { return done(err, obj); } - - var layer = stack[i]; + + const layer = stack[i]; if (!layer) { return done(new Error('Failed to serialize user into session')); } - - + + function serialized(e, o) { pass(i + 1, e, o); } - + try { - var arity = layer.length; - if (arity == 3) { + const arity = layer.length; + if (arity === 3) { layer(req, user, serialized); } else { layer(user, serialized); } - } catch(e) { + } catch (e) { return done(e); } - })(0); + }(0)); }; /** @@ -305,25 +315,28 @@ Authenticator.prototype.serializeUser = function(fn, req, done) { * * @api public */ -Authenticator.prototype.deserializeUser = function(fn, req, done) { + +// eslint-disable-next-line consistent-return +Authenticator.prototype.deserializeUser = function deserializeUser(fn, req, done) { if (typeof fn === 'function') { return this._deserializers.push(fn); } - + // private implementation that traverses the chain of deserializers, // attempting to deserialize a user - var obj = fn; + const obj = fn; // For backwards compatibility if (typeof req === 'function') { done = req; req = undefined; } - - var stack = this._deserializers; + + const stack = this._deserializers; + // eslint-disable-next-line consistent-return (function pass(i, err, user) { // deserializers use 'pass' as an error to skip processing - if ('pass' === err) { + if (err === 'pass') { err = undefined; } // an error or deserialized user was obtained, done @@ -331,28 +344,28 @@ Authenticator.prototype.deserializeUser = function(fn, req, done) { // a valid user existed when establishing the session, but that user has // since been removed if (user === null || user === false) { return done(null, false); } - - var layer = stack[i]; + + const layer = stack[i]; if (!layer) { return done(new Error('Failed to deserialize user out of session')); } - - + + function deserialized(e, u) { pass(i + 1, e, u); } - + try { - var arity = layer.length; - if (arity == 3) { + const arity = layer.length; + if (arity === 3) { layer(req, obj, deserialized); } else { layer(obj, deserialized); } - } catch(e) { + } catch (e) { return done(e); } - })(0); + }(0)); }; /** @@ -393,67 +406,70 @@ Authenticator.prototype.deserializeUser = function(fn, req, done) { * * @api public */ -Authenticator.prototype.transformAuthInfo = function(fn, req, done) { + +// eslint-disable-next-line consistent-return +Authenticator.prototype.transformAuthInfo = function transformAuthInfo(fn, req, done) { if (typeof fn === 'function') { return this._infoTransformers.push(fn); } - + // private implementation that traverses the chain of transformers, // attempting to transform auth info - var info = fn; + const info = fn; // For backwards compatibility if (typeof req === 'function') { done = req; req = undefined; } - - var stack = this._infoTransformers; + + const stack = this._infoTransformers; + // eslint-disable-next-line consistent-return (function pass(i, err, tinfo) { // transformers use 'pass' as an error to skip processing - if ('pass' === err) { + if (err === 'pass') { err = undefined; } // an error or transformed info was obtained, done if (err || tinfo) { return done(err, tinfo); } - - var layer = stack[i]; + + const layer = stack[i]; if (!layer) { // if no transformers are registered (or they all pass), the default // behavior is to use the un-transformed info as-is return done(null, info); } - - + + function transformed(e, t) { pass(i + 1, e, t); } - + try { - var arity = layer.length; - if (arity == 1) { + const arity = layer.length; + if (arity === 1) { // sync - var t = layer(info); + const t = layer(info); transformed(null, t); - } else if (arity == 3) { + } else if (arity === 3) { layer(req, info, transformed); } else { layer(info, transformed); } - } catch(e) { + } catch (e) { return done(e); } - })(0); + }(0)); }; /** - * Return strategy with given `name`. + * Return strategy with given `name`. * * @param {String} name * @return {Strategy} * @api private */ -Authenticator.prototype._strategy = function(name) { +Authenticator.prototype._strategy = function _strategy(name) { return this._strategies[name]; }; diff --git a/lib/errors/authenticationerror.js b/lib/errors/authenticationerror.js index 2b1da147..68cf923e 100644 --- a/lib/errors/authenticationerror.js +++ b/lib/errors/authenticationerror.js @@ -4,6 +4,9 @@ * @constructor * @api private */ + +/* eslint-disable no-proto, no-proto, no-caller, no-restricted-properties */ + function AuthenticationError(message, status) { Error.call(this); Error.captureStackTrace(this, arguments.callee); diff --git a/lib/framework/connect.js b/lib/framework/connect.js index 5c5beb09..77f587cf 100644 --- a/lib/framework/connect.js +++ b/lib/framework/connect.js @@ -1,9 +1,13 @@ /** * Module dependencies. */ -var initialize = require('../middleware/initialize') - , authenticate = require('../middleware/authenticate'); - +/* eslint-disable camelcase, no-proto, no-shadow */ + +const http = require('http'); +const initialize = require('../middleware/initialize'); +const authenticate = require('../middleware/authenticate'); +const IncomingMessageExt = require('../http/request'); + /** * Framework support for Connect/Express. * @@ -15,25 +19,25 @@ var initialize = require('../middleware/initialize') * @return {Object} * @api protected */ -exports = module.exports = function() { - + +// eslint-disable-next-line no-multi-assign, func-names +exports = module.exports = function () { // HTTP extensions. exports.__monkeypatchNode(); - + return { - initialize: initialize, - authenticate: authenticate + initialize, + authenticate, }; }; -exports.__monkeypatchNode = function() { - var http = require('http'); - var IncomingMessageExt = require('../http/request'); - - http.IncomingMessage.prototype.login = +exports.__monkeypatchNode = function __monkeypatchNode() { http.IncomingMessage.prototype.logIn = IncomingMessageExt.logIn; - http.IncomingMessage.prototype.logout = + http.IncomingMessage.prototype.login = http.IncomingMessage.prototype.logIn; + http.IncomingMessage.prototype.logOut = IncomingMessageExt.logOut; + http.IncomingMessage.prototype.logout = http.IncomingMessage.prototype.logOut; + http.IncomingMessage.prototype.isAuthenticated = IncomingMessageExt.isAuthenticated; http.IncomingMessage.prototype.isUnauthenticated = IncomingMessageExt.isUnauthenticated; }; diff --git a/lib/http/request.js b/lib/http/request.js index 0206abb8..ccd46eef 100644 --- a/lib/http/request.js +++ b/lib/http/request.js @@ -1,11 +1,13 @@ /** * Module dependencies. */ -//var http = require('http') + +// var http = require('http') // , req = http.IncomingMessage.prototype; +/* eslint-disable no-multi-assign, camelcase, no-proto, no-shadow */ -var req = exports = module.exports = {}; +const req = exports = module.exports = {}; /** * Initiate a login session for `user`. @@ -27,66 +29,70 @@ var req = exports = module.exports = {}; * @param {Function} done * @api public */ -req.login = -req.logIn = function(user, options, done) { - if (typeof options == 'function') { +req.logIn = function logIn(user, options, done) { + if (typeof options === 'function') { done = options; options = {}; } options = options || {}; - - var property = 'user'; + + let property = 'user'; if (this._passport && this._passport.instance) { property = this._passport.instance._userProperty || 'user'; } - var session = (options.session === undefined) ? true : options.session; - + const session = (options.session === undefined) ? true : options.session; + this[property] = user; if (session) { if (!this._passport) { throw new Error('passport.initialize() middleware not in use'); } - if (typeof done != 'function') { throw new Error('req#login requires a callback function'); } - - var self = this; - this._passport.instance._sm.logIn(this, user, function(err) { + if (typeof done !== 'function') { throw new Error('req#login requires a callback function'); } + + const self = this; + // eslint-disable-next-line consistent-return + this._passport.instance._sm.logIn(this, user, (err) => { if (err) { self[property] = null; return done(err); } done(); }); } else { + // eslint-disable-next-line no-unused-expressions done && done(); } }; +req.login = req.logIn; + /** * Terminate an existing login session. * * @api public */ -req.logout = -req.logOut = function() { - var property = 'user'; +req.logOut = function logOut() { + let property = 'user'; if (this._passport && this._passport.instance) { property = this._passport.instance._userProperty || 'user'; } - + this[property] = null; if (this._passport) { this._passport.instance._sm.logOut(this); } }; +req.logout = req.logOut; + /** * Test if request is authenticated. * * @return {Boolean} * @api public */ -req.isAuthenticated = function() { - var property = 'user'; +req.isAuthenticated = function isAuthenticated() { + let property = 'user'; if (this._passport && this._passport.instance) { property = this._passport.instance._userProperty || 'user'; } - - return (this[property]) ? true : false; + + return !!(this[property]); }; /** @@ -95,6 +101,6 @@ req.isAuthenticated = function() { * @return {Boolean} * @api public */ -req.isUnauthenticated = function() { +req.isUnauthenticated = function isUnauthenticated() { return !this.isAuthenticated(); }; diff --git a/lib/index.js b/lib/index.js index d1c8fddb..a4a11e39 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,8 +1,11 @@ /** * Module dependencies. */ -var Passport = require('./authenticator') - , SessionStrategy = require('./strategies/session'); + +/* eslint-disable no-multi-assign */ + +const Passport = require('./authenticator'); +const SessionStrategy = require('./strategies/session'); /** @@ -15,8 +18,7 @@ exports = module.exports = new Passport(); /** * Expose constructors. */ -exports.Passport = -exports.Authenticator = Passport; +exports.Passport = exports.Authenticator = Passport; exports.Strategy = require('@passport-next/passport-strategy'); /** diff --git a/lib/middleware/authenticate.js b/lib/middleware/authenticate.js index e53aec23..0357b3a0 100644 --- a/lib/middleware/authenticate.js +++ b/lib/middleware/authenticate.js @@ -1,9 +1,13 @@ /** * Module dependencies. */ -var http = require('http') - , IncomingMessageExt = require('../http/request') - , AuthenticationError = require('../errors/authenticationerror'); + +/* eslint-disable camelcase, no-proto, no-shadow */ + +const http = require('http'); +const IncomingMessageExt = require('../http/request'); +const AuthenticationError = require('../errors/authenticationerror'); +const connect = require('../framework/connect'); /** @@ -68,14 +72,14 @@ var http = require('http') * @api public */ module.exports = function authenticate(passport, name, options, callback) { - if (typeof options == 'function') { + if (typeof options === 'function') { callback = options; options = {}; } options = options || {}; - - var multi = true; - + + let multi = true; + // Cast `name` to an array, allowing authentication to pass through a chain of // strategies. The first strategy to succeed, redirect, or error will halt // the chain. Authentication failures will proceed through each strategy in @@ -87,65 +91,63 @@ module.exports = function authenticate(passport, name, options, callback) { // redirection (for example both Facebook and Twitter), since the first one to // redirect will halt the chain. if (!Array.isArray(name)) { - name = [ name ]; + name = [name]; multi = false; } - + return function authenticate(req, res, next) { if (http.IncomingMessage.prototype.logIn && http.IncomingMessage.prototype.logIn !== IncomingMessageExt.logIn) { - require('../framework/connect').__monkeypatchNode(); + connect.__monkeypatchNode(); } - - + + // accumulator for failures from each strategy in the chain - var failures = []; - + const failures = []; + function redirect(url) { - if (req.session && req.session.save && typeof req.session.save == 'function') { - return req.session.save(function() { - return res.redirect(url); - }); + if (req.session && req.session.save && typeof req.session.save === 'function') { + return req.session.save(() => res.redirect(url)); } return res.redirect(url); } - + + // eslint-disable-next-line consistent-return function allFailed() { if (callback) { if (!multi) { return callback(null, false, failures[0].challenge, failures[0].status); - } else { - var challenges = failures.map(function(f) { return f.challenge; }); - var statuses = failures.map(function(f) { return f.status; }); - return callback(null, false, challenges, statuses); } + const challenges = failures.map(f => f.challenge); + const statuses = failures.map(f => f.status); + return callback(null, false, challenges, statuses); } - + // Strategies are ordered by priority. For the purpose of flashing a // message, the first failure will be displayed. - var failure = failures[0] || {} - , challenge = failure.challenge || {} - , msg; - + let failure = failures[0] || {}; + let challenge = failure.challenge || {}; + let msg; + if (options.failureFlash) { - var flash = options.failureFlash; - if (typeof flash == 'string') { + let flash = options.failureFlash; + if (typeof flash === 'string') { flash = { type: 'error', message: flash }; } flash.type = flash.type || 'error'; - - var type = flash.type || challenge.type || 'error'; + + const type = flash.type || challenge.type || 'error'; msg = flash.message || challenge.message || challenge; - if (typeof msg == 'string') { + if (typeof msg === 'string') { req.flash(type, msg); } } if (options.failureMessage) { msg = options.failureMessage; - if (typeof msg == 'boolean') { + if (typeof msg === 'boolean') { msg = challenge.message || challenge; } - if (typeof msg == 'string') { + if (typeof msg === 'string') { req.session.messages = req.session.messages || []; req.session.messages.push(msg); } @@ -153,28 +155,29 @@ module.exports = function authenticate(passport, name, options, callback) { if (options.failureRedirect) { return redirect(options.failureRedirect); } - + // When failure handling is not delegated to the application, the default // is to respond with 401 Unauthorized. Note that the WWW-Authenticate // header will be set according to the strategies in use (see // actions#fail). If multiple strategies failed, each of their challenges // will be included in the response. - var rchallenge = [] - , rstatus, status; - - for (var j = 0, len = failures.length; j < len; j++) { + const rchallenge = []; + let rstatus; + let status; + // eslint-disable-next-line no-plusplus + for (let j = 0, len = failures.length; j < len; j++) { failure = failures[j]; challenge = failure.challenge; status = failure.status; - + rstatus = rstatus || status; - if (typeof challenge == 'string') { + if (typeof challenge === 'string') { rchallenge.push(challenge); } } - + res.statusCode = rstatus || 401; - if (res.statusCode == 401 && rchallenge.length) { + if (res.statusCode === 401 && rchallenge.length) { res.setHeader('WWW-Authenticate', rchallenge); } if (options.failWithError) { @@ -182,28 +185,29 @@ module.exports = function authenticate(passport, name, options, callback) { } res.end(http.STATUS_CODES[res.statusCode]); } - + + // eslint-disable-next-line consistent-return (function attempt(i) { - var layer = name[i]; + const layer = name[i]; // If no more strategies exist in the chain, authentication has failed. if (!layer) { return allFailed(); } - + // Get the strategy, which will be used as prototype from which to create // a new instance. Action functions will then be bound to the strategy // within the context of the HTTP request/response pair. - var prototype = passport._strategy(layer); - if (!prototype) { return next(new Error('Unknown authentication strategy "' + layer + '"')); } - - var strategy = Object.create(prototype); - - + const prototype = passport._strategy(layer); + if (!prototype) { return next(new Error(`Unknown authentication strategy "${layer}"`)); } + + const strategy = Object.create(prototype); + + // ----- BEGIN STRATEGY AUGMENTATION ----- // Augment the new strategy instance with action functions. These action // functions are bound via closure the the request/response pair. The end // goal of the strategy is to invoke *one* of these action methods, in // order to indicate successful or failed authentication, redirect to a // third-party identity provider, etc. - + /** * Authenticate `user`, with optional `info`. * @@ -218,33 +222,35 @@ module.exports = function authenticate(passport, name, options, callback) { * @param {Object} info * @api public */ - strategy.success = function(user, info) { + + // eslint-disable-next-line consistent-return + strategy.success = function success(user, info) { if (callback) { return callback(null, user, info); } - + info = info || {}; - var msg; - + let msg; + if (options.successFlash) { - var flash = options.successFlash; - if (typeof flash == 'string') { + let flash = options.successFlash; + if (typeof flash === 'string') { flash = { type: 'success', message: flash }; } flash.type = flash.type || 'success'; - - var type = flash.type || info.type || 'success'; + + const type = flash.type || info.type || 'success'; msg = flash.message || info.message || info; - if (typeof msg == 'string') { + if (typeof msg === 'string') { req.flash(type, msg); } } if (options.successMessage) { msg = options.successMessage; - if (typeof msg == 'boolean') { + if (typeof msg === 'boolean') { msg = info.message || info; } - if (typeof msg == 'string') { + if (typeof msg === 'string') { req.session.messages = req.session.messages || []; req.session.messages.push(msg); } @@ -253,13 +259,15 @@ module.exports = function authenticate(passport, name, options, callback) { req[options.assignProperty] = user; return next(); } - - req.logIn(user, options, function(err) { + + // eslint-disable-next-line consistent-return + req.logIn(user, options, (err) => { if (err) { return next(err); } - + + // eslint-disable-next-line consistent-return function complete() { if (options.successReturnToOrRedirect) { - var url = options.successReturnToOrRedirect; + let url = options.successReturnToOrRedirect; if (req.session && req.session.returnTo) { url = req.session.returnTo; delete req.session.returnTo; @@ -271,9 +279,10 @@ module.exports = function authenticate(passport, name, options, callback) { } next(); } - + if (options.authInfo !== false) { - passport.transformAuthInfo(info, req, function(err, tinfo) { + // eslint-disable-next-line consistent-return + passport.transformAuthInfo(info, req, (err, tinfo) => { if (err) { return next(err); } req.authInfo = tinfo; complete(); @@ -283,7 +292,7 @@ module.exports = function authenticate(passport, name, options, callback) { } }); }; - + /** * Fail authentication, with optional `challenge` and `status`, defaulting * to 401. @@ -294,18 +303,18 @@ module.exports = function authenticate(passport, name, options, callback) { * @param {Number} status * @api public */ - strategy.fail = function(challenge, status) { - if (typeof challenge == 'number') { + strategy.fail = function fail(challenge, status) { + if (typeof challenge === 'number') { status = challenge; challenge = undefined; } - + // push this failure into the accumulator and attempt authentication // using the next strategy - failures.push({ challenge: challenge, status: status }); + failures.push({ challenge, status }); attempt(i + 1); }; - + /** * Redirect to `url` with optional `status`, defaulting to 302. * @@ -316,7 +325,7 @@ module.exports = function authenticate(passport, name, options, callback) { * @param {Number} status * @api public */ - strategy.redirect = function(url, status) { + strategy.redirect = function redirect(url, status) { // NOTE: Do not use `res.redirect` from Express, because it can't decide // what it wants. // @@ -327,13 +336,13 @@ module.exports = function authenticate(passport, name, options, callback) { // Express 4.x: res.redirect(status, url) // - all versions (as of 4.8.7) continue to accept res.redirect(url, status) // but issue deprecated versions - + res.statusCode = status || 302; res.setHeader('Location', url); res.setHeader('Content-Length', '0'); res.end(); }; - + /** * Pass without making a success or fail decision. * @@ -343,10 +352,10 @@ module.exports = function authenticate(passport, name, options, callback) { * * @api public */ - strategy.pass = function() { + strategy.pass = function pass() { next(); }; - + /** * Internal error while performing authentication. * @@ -357,17 +366,19 @@ module.exports = function authenticate(passport, name, options, callback) { * @param {Error} err * @api public */ - strategy.error = function(err) { + + // eslint-disable-next-line consistent-return + strategy.error = function error(err) { if (callback) { return callback(err); } - + next(err); }; - + // ----- END STRATEGY AUGMENTATION ----- - + strategy.authenticate(req, options); - })(0); // attempt + }(0)); // attempt }; }; diff --git a/lib/middleware/initialize.js b/lib/middleware/initialize.js index 53ce3d86..1de02a62 100644 --- a/lib/middleware/initialize.js +++ b/lib/middleware/initialize.js @@ -39,8 +39,9 @@ * @return {Function} * @api public */ + +/* eslint-disable no-proto, no-shadow */ module.exports = function initialize(passport) { - return function initialize(req, res, next) { req._passport = {}; req._passport.instance = passport; diff --git a/lib/sessionmanager.js b/lib/sessionmanager.js index 0fdbd8bd..e7cbea66 100644 --- a/lib/sessionmanager.js +++ b/lib/sessionmanager.js @@ -1,17 +1,20 @@ +/* eslint-disable camelcase, no-proto, no-shadow */ + function SessionManager(options, serializeUser) { - if (typeof options == 'function') { + if (typeof options === 'function') { serializeUser = options; options = undefined; } options = options || {}; - + this._key = options.key || 'passport'; this._serializeUser = serializeUser; } -SessionManager.prototype.logIn = function(req, user, cb) { - var self = this; - this._serializeUser(user, req, function(err, obj) { +SessionManager.prototype.logIn = function logIn(req, user, cb) { + const self = this; + // eslint-disable-next-line consistent-return + this._serializeUser(user, req, (err, obj) => { if (err) { return cb(err); } @@ -25,14 +28,15 @@ SessionManager.prototype.logIn = function(req, user, cb) { req.session[self._key] = req._passport.session; cb(); }); -} +}; -SessionManager.prototype.logOut = function(req, cb) { +SessionManager.prototype.logOut = function logOut(req, cb) { if (req._passport && req._passport.session) { delete req._passport.session.user; } + // eslint-disable-next-line no-unused-expressions cb && cb(); -} +}; module.exports = SessionManager; diff --git a/lib/strategies/session.js b/lib/strategies/session.js index ffb0bb24..9d16b472 100644 --- a/lib/strategies/session.js +++ b/lib/strategies/session.js @@ -1,8 +1,11 @@ /** * Module dependencies. */ -var util = require('util') - , Strategy = require('@passport-next/passport-strategy'); + +/* eslint-disable camelcase, no-proto, no-shadow */ + +const util = require('util'); +const Strategy = require('@passport-next/passport-strategy'); /** @@ -11,12 +14,12 @@ var util = require('util') * @api public */ function SessionStrategy(options, deserializeUser) { - if (typeof options == 'function') { + if (typeof options === 'function') { deserializeUser = options; options = undefined; } options = options || {}; - + Strategy.call(this); this.name = 'session'; this._deserializeUser = deserializeUser; @@ -40,25 +43,28 @@ util.inherits(SessionStrategy, Strategy); * @param {Object} options * @api protected */ -SessionStrategy.prototype.authenticate = function(req, options) { + +// eslint-disable-next-line consistent-return, no-unused-vars +SessionStrategy.prototype.authenticate = function authenticate(req, options) { if (!req._passport) { return this.error(new Error('passport.initialize() middleware not in use')); } options = options || {}; - var self = this, - su; + const self = this; + let su; if (req._passport.session) { su = req._passport.session.user; } if (su || su === 0) { - this._deserializeUser(su, req, function(err, user) { + // eslint-disable-next-line consistent-return + this._deserializeUser(su, req, (err, user) => { if (err) { return self.error(err); } if (!user) { delete req._passport.session.user; } else { // TODO: Remove instance access - var property = req._passport.instance._userProperty || 'user'; + const property = req._passport.instance._userProperty || 'user'; req[property] = user; } self.pass(); diff --git a/package-lock.json b/package-lock.json index a7f43d12..3898a730 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@passport-next/passport", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -15,12 +15,142 @@ "resolved": "https://registry.npmjs.org/@passport-next/passport-strategy/-/passport-strategy-1.1.0.tgz", "integrity": "sha512-2KhFjtPueJG6xVj2HnqXt9BlANOfYCVLyu+pXYjPGBDT8yk+vQwc/6tsceIj+mayKcoxMau2JimggXRPHgoc8w==" }, + "acorn": { + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", + "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", + "dev": true + }, + "acorn-jsx": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz", + "integrity": "sha1-r9+UiPsezvyDSPb7IvRk4ypYs2s=", + "dev": true, + "requires": { + "acorn": "3.3.0" + }, + "dependencies": { + "acorn": { + "version": "3.3.0", + "resolved": "http://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", + "integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=", + "dev": true + } + } + }, + "ajv": { + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", + "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", + "dev": true, + "requires": { + "co": "4.6.0", + "fast-deep-equal": "1.1.0", + "fast-json-stable-stringify": "2.0.0", + "json-schema-traverse": "0.3.1" + } + }, + "ajv-keywords": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-2.1.1.tgz", + "integrity": "sha1-YXmX/F9gV2iUxDX5QNgZ4TW4B2I=", + "dev": true + }, + "ansi-escapes": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz", + "integrity": "sha512-UgAb8H9D41AQnu/PbWlCofQVcnV4Gs2bBJi9eZPxfU/hgglFh3SMDMENRIqdr7H6XFnXdoknctFByVsCOotTVw==", + "dev": true + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "requires": { + "sprintf-js": "1.0.3" + } + }, + "array-union": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", + "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=", + "dev": true, + "requires": { + "array-uniq": "1.0.3" + } + }, + "array-uniq": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz", + "integrity": "sha1-r2rId6Jcx/dOBYiUdThY39sk/bY=", + "dev": true + }, + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true + }, "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, + "babel-code-frame": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", + "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", + "dev": true, + "requires": { + "chalk": "1.1.3", + "esutils": "2.0.2", + "js-tokens": "3.0.2" + }, + "dependencies": { + "chalk": { + "version": "1.1.3", + "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "ansi-styles": "2.2.1", + "escape-string-regexp": "1.0.5", + "has-ansi": "2.0.0", + "strip-ansi": "3.0.1", + "supports-color": "2.0.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "2.1.1" + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true + } + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -33,7 +163,7 @@ "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "requires": { - "balanced-match": "^1.0.0", + "balanced-match": "1.0.0", "concat-map": "0.0.1" } }, @@ -43,18 +173,45 @@ "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, + "buffer-from": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "dev": true + }, + "builtin-modules": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", + "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", + "dev": true + }, + "caller-path": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz", + "integrity": "sha1-lAhe9jWB7NPaqSREqP6U6CV3dR8=", + "dev": true, + "requires": { + "callsites": "0.2.0" + } + }, + "callsites": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-0.2.0.tgz", + "integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=", + "dev": true + }, "chai": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz", "integrity": "sha1-D2RYS6ZC8PKs4oBiefTwbKI61zw=", "dev": true, "requires": { - "assertion-error": "^1.0.1", - "check-error": "^1.0.1", - "deep-eql": "^3.0.0", - "get-func-name": "^2.0.0", - "pathval": "^1.0.0", - "type-detect": "^4.0.0" + "assertion-error": "1.1.0", + "check-error": "1.0.2", + "deep-eql": "3.0.1", + "get-func-name": "2.0.0", + "pathval": "1.1.0", + "type-detect": "4.0.8" } }, "chai-connect-middleware": { @@ -63,12 +220,82 @@ "integrity": "sha1-6qGF6ZKhAtAyvW4ngAEqjmQ1hqg=", "dev": true }, + "chalk": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", + "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", + "dev": true, + "requires": { + "ansi-styles": "3.2.1", + "escape-string-regexp": "1.0.5", + "supports-color": "5.4.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "1.9.3" + } + } + } + }, + "chardet": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz", + "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=", + "dev": true + }, "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", "dev": true }, + "circular-json": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", + "integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==", + "dev": true + }, + "cli-cursor": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", + "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", + "dev": true, + "requires": { + "restore-cursor": "2.0.0" + } + }, + "cli-width": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", + "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", + "dev": true + }, + "co": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", + "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", + "dev": true + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, "commander": { "version": "2.15.1", "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", @@ -81,6 +308,41 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "dev": true, + "requires": { + "buffer-from": "1.1.1", + "inherits": "2.0.3", + "readable-stream": "2.3.6", + "typedarray": "0.0.6" + } + }, + "contains-path": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/contains-path/-/contains-path-0.1.0.tgz", + "integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=", + "dev": true + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true + }, + "cross-spawn": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", + "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", + "dev": true, + "requires": { + "lru-cache": "4.1.3", + "shebang-command": "1.2.0", + "which": "1.3.1" + } + }, "debug": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", @@ -96,7 +358,37 @@ "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", "dev": true, "requires": { - "type-detect": "^4.0.0" + "type-detect": "4.0.8" + } + }, + "deep-is": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", + "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", + "dev": true + }, + "define-properties": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", + "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "dev": true, + "requires": { + "object-keys": "1.0.12" + } + }, + "del": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/del/-/del-2.2.2.tgz", + "integrity": "sha1-wSyYHQZ4RshLyvhiz/kw2Qf/0ag=", + "dev": true, + "requires": { + "globby": "5.0.0", + "is-path-cwd": "1.0.0", + "is-path-in-cwd": "1.0.1", + "object-assign": "4.1.1", + "pify": "2.3.0", + "pinkie-promise": "2.0.1", + "rimraf": "2.6.2" } }, "diff": { @@ -105,18 +397,348 @@ "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", "dev": true }, + "doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "dev": true, + "requires": { + "esutils": "2.0.2" + } + }, + "error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dev": true, + "requires": { + "is-arrayish": "0.2.1" + } + }, + "es-abstract": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.12.0.tgz", + "integrity": "sha512-C8Fx/0jFmV5IPoMOFPA9P9G5NtqW+4cOPit3MIuvR2t7Ag2K15EJTpxnHAYTzL+aYQJIESYeXZmDBfOBE1HcpA==", + "dev": true, + "requires": { + "es-to-primitive": "1.1.1", + "function-bind": "1.1.1", + "has": "1.0.3", + "is-callable": "1.1.4", + "is-regex": "1.0.4" + } + }, + "es-to-primitive": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.1.1.tgz", + "integrity": "sha1-RTVSSKiJeQNLZ5Lhm7gfK3l13Q0=", + "dev": true, + "requires": { + "is-callable": "1.1.4", + "is-date-object": "1.0.1", + "is-symbol": "1.0.1" + } + }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "eslint": { + "version": "4.19.1", + "resolved": "http://registry.npmjs.org/eslint/-/eslint-4.19.1.tgz", + "integrity": "sha512-bT3/1x1EbZB7phzYu7vCr1v3ONuzDtX8WjuM9c0iYxe+cq+pwcKEoQjl7zd3RpC6YOLgnSy3cTN58M2jcoPDIQ==", + "dev": true, + "requires": { + "ajv": "5.5.2", + "babel-code-frame": "6.26.0", + "chalk": "2.4.1", + "concat-stream": "1.6.2", + "cross-spawn": "5.1.0", + "debug": "3.1.0", + "doctrine": "2.1.0", + "eslint-scope": "3.7.3", + "eslint-visitor-keys": "1.0.0", + "espree": "3.5.4", + "esquery": "1.0.1", + "esutils": "2.0.2", + "file-entry-cache": "2.0.0", + "functional-red-black-tree": "1.0.1", + "glob": "7.1.2", + "globals": "11.7.0", + "ignore": "3.3.10", + "imurmurhash": "0.1.4", + "inquirer": "3.3.0", + "is-resolvable": "1.1.0", + "js-yaml": "3.12.0", + "json-stable-stringify-without-jsonify": "1.0.1", + "levn": "0.3.0", + "lodash": "4.17.11", + "minimatch": "3.0.4", + "mkdirp": "0.5.1", + "natural-compare": "1.4.0", + "optionator": "0.8.2", + "path-is-inside": "1.0.2", + "pluralize": "7.0.0", + "progress": "2.0.0", + "regexpp": "1.1.0", + "require-uncached": "1.0.3", + "semver": "5.5.1", + "strip-ansi": "4.0.0", + "strip-json-comments": "2.0.1", + "table": "4.0.2", + "text-table": "0.2.0" + } + }, + "eslint-config-airbnb-base": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-13.0.0.tgz", + "integrity": "sha512-hUFXRlE6AY84z0qYh4wKdtSF4EqDnyT8sxrvTpcXCV4ENSLF8li5yNA1yDM26iinH8Ierbpc4lv8Rp62uX6VSQ==", + "dev": true, + "requires": { + "eslint-restricted-globals": "0.1.1", + "object.assign": "4.1.0", + "object.entries": "1.0.4" + } + }, + "eslint-import-resolver-node": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz", + "integrity": "sha512-sfmTqJfPSizWu4aymbPr4Iidp5yKm8yDkHp+Ir3YiTHiiDfxh69mOUsmiqW6RZ9zRXFaF64GtYmN7e+8GHBv6Q==", + "dev": true, + "requires": { + "debug": "2.6.9", + "resolve": "1.8.1" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + } + } + }, + "eslint-module-utils": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.2.0.tgz", + "integrity": "sha1-snA2LNiLGkitMIl2zn+lTphBF0Y=", + "dev": true, + "requires": { + "debug": "2.6.9", + "pkg-dir": "1.0.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + } + } + }, + "eslint-plugin-import": { + "version": "2.12.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.12.0.tgz", + "integrity": "sha1-2tMXgSktZmSyUxf9BJ0uKy8CIF0=", + "dev": true, + "requires": { + "contains-path": "0.1.0", + "debug": "2.6.9", + "doctrine": "1.5.0", + "eslint-import-resolver-node": "0.3.2", + "eslint-module-utils": "2.2.0", + "has": "1.0.3", + "lodash": "4.17.11", + "minimatch": "3.0.4", + "read-pkg-up": "2.0.0", + "resolve": "1.8.1" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "doctrine": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", + "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", + "dev": true, + "requires": { + "esutils": "2.0.2", + "isarray": "1.0.0" + } + } + } + }, + "eslint-restricted-globals": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/eslint-restricted-globals/-/eslint-restricted-globals-0.1.1.tgz", + "integrity": "sha1-NfDVy8ZMLj7WLpO0saevBbp+1Nc=", + "dev": true + }, + "eslint-scope": { + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.3.tgz", + "integrity": "sha512-W+B0SvF4gamyCTmUc+uITPY0989iXVfKvhwtmJocTaYoc/3khEHmEmvfY/Gn9HA9VV75jrQECsHizkNw1b68FA==", + "dev": true, + "requires": { + "esrecurse": "4.2.1", + "estraverse": "4.2.0" + } + }, + "eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", + "dev": true + }, + "espree": { + "version": "3.5.4", + "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", + "integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==", + "dev": true, + "requires": { + "acorn": "5.7.3", + "acorn-jsx": "3.0.1" + } + }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true + }, + "esquery": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz", + "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==", + "dev": true, + "requires": { + "estraverse": "4.2.0" + } + }, + "esrecurse": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", + "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", + "dev": true, + "requires": { + "estraverse": "4.2.0" + } + }, + "estraverse": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", + "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", + "dev": true + }, + "esutils": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", + "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", + "dev": true + }, + "external-editor": { + "version": "2.2.0", + "resolved": "http://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", + "integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==", + "dev": true, + "requires": { + "chardet": "0.4.2", + "iconv-lite": "0.4.24", + "tmp": "0.0.33" + } + }, + "fast-deep-equal": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", + "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", + "dev": true + }, + "fast-json-stable-stringify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", + "dev": true + }, + "fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", + "dev": true + }, + "figures": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", + "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", + "dev": true, + "requires": { + "escape-string-regexp": "1.0.5" + } + }, + "file-entry-cache": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-2.0.0.tgz", + "integrity": "sha1-w5KZDD5oR4PYOLjISkXYoEhFg2E=", + "dev": true, + "requires": { + "flat-cache": "1.3.0", + "object-assign": "4.1.1" + } + }, + "find-up": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz", + "integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=", + "dev": true, + "requires": { + "path-exists": "2.1.0", + "pinkie-promise": "2.0.1" + } + }, + "flat-cache": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-1.3.0.tgz", + "integrity": "sha1-0wMLMrOBVPTjt+nHCfSQ9++XxIE=", + "dev": true, + "requires": { + "circular-json": "0.3.3", + "del": "2.2.2", + "graceful-fs": "4.1.11", + "write": "0.2.1" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true + }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", + "dev": true + }, "get-func-name": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", @@ -129,40 +751,117 @@ "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", "dev": true, "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "globals": { + "version": "11.7.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.7.0.tgz", + "integrity": "sha512-K8BNSPySfeShBQXsahYB/AbbWruVOTyVpgoIDnl8odPpeSfP2J5QO2oLFFdl2j7GfDCtZj2bMKar2T49itTPCg==", + "dev": true + }, + "globby": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-5.0.0.tgz", + "integrity": "sha1-69hGZ8oNuzMLmbz8aOrCvFQ3Dg0=", + "dev": true, + "requires": { + "array-union": "1.0.2", + "arrify": "1.0.1", + "glob": "7.1.2", + "object-assign": "4.1.1", + "pify": "2.3.0", + "pinkie-promise": "2.0.1" } }, + "graceful-fs": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", + "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", + "dev": true + }, "growl": { "version": "1.10.5", "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", "dev": true }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "1.1.1" + } + }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "dev": true, + "requires": { + "ansi-regex": "2.1.1" + } + }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "dev": true }, + "has-symbols": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz", + "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=", + "dev": true + }, "he": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", "dev": true }, + "hosted-git-info": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz", + "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", + "dev": true + }, + "iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dev": true, + "requires": { + "safer-buffer": "2.1.2" + } + }, + "ignore": { + "version": "3.3.10", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", + "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==", + "dev": true + }, + "imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "dev": true + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "dev": true, "requires": { - "once": "^1.3.0", - "wrappy": "1" + "once": "1.4.0", + "wrappy": "1.0.2" } }, "inherits": { @@ -171,39 +870,247 @@ "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true }, - "make-node": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/make-node/-/make-node-0.3.5.tgz", - "integrity": "sha1-LTVN240+zfWg1btMrbuqRGHK3jo=", - "dev": true - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "inquirer": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.3.0.tgz", + "integrity": "sha512-h+xtnyk4EwKvFWHrUYsWErEVR+igKtLdchu+o0Z1RL7VU/jVMFbYir2bp6bAj8efFNxWqHX0dIss6fJQ+/+qeQ==", "dev": true, "requires": { - "brace-expansion": "^1.1.7" + "ansi-escapes": "3.1.0", + "chalk": "2.4.1", + "cli-cursor": "2.1.0", + "cli-width": "2.2.0", + "external-editor": "2.2.0", + "figures": "2.0.0", + "lodash": "4.17.11", + "mute-stream": "0.0.7", + "run-async": "2.3.0", + "rx-lite": "4.0.8", + "rx-lite-aggregates": "4.0.8", + "string-width": "2.1.1", + "strip-ansi": "4.0.0", + "through": "2.3.8" } }, - "minimist": { - "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", "dev": true }, - "mkdirp": { - "version": "0.5.1", - "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "is-builtin-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz", + "integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=", "dev": true, "requires": { - "minimist": "0.0.8" + "builtin-modules": "1.1.1" } }, - "mocha": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", + "is-callable": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", + "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", + "dev": true + }, + "is-date-object": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", + "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + }, + "is-path-cwd": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-1.0.0.tgz", + "integrity": "sha1-0iXsIxMuie3Tj9p2dHLmLmXxEG0=", + "dev": true + }, + "is-path-in-cwd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-path-in-cwd/-/is-path-in-cwd-1.0.1.tgz", + "integrity": "sha512-FjV1RTW48E7CWM7eE/J2NJvAEEVektecDBVBE5Hh3nM1Jd0kvhHtX68Pr3xsDf857xt3Y4AkwVULK1Vku62aaQ==", + "dev": true, + "requires": { + "is-path-inside": "1.0.1" + } + }, + "is-path-inside": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-1.0.1.tgz", + "integrity": "sha1-jvW33lBDej/cprToZe96pVy0gDY=", + "dev": true, + "requires": { + "path-is-inside": "1.0.2" + } + }, + "is-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", + "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", + "dev": true + }, + "is-regex": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", + "integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=", + "dev": true, + "requires": { + "has": "1.0.3" + } + }, + "is-resolvable": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.1.0.tgz", + "integrity": "sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg==", + "dev": true + }, + "is-symbol": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.1.tgz", + "integrity": "sha1-PMWfAAJRlLarLjjbrmaJJWtmBXI=", + "dev": true + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true + }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true + }, + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", + "dev": true + }, + "js-yaml": { + "version": "3.12.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz", + "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==", + "dev": true, + "requires": { + "argparse": "1.0.10", + "esprima": "4.0.1" + } + }, + "json-schema-traverse": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", + "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=", + "dev": true + }, + "json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", + "dev": true + }, + "levn": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", + "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", + "dev": true, + "requires": { + "prelude-ls": "1.1.2", + "type-check": "0.3.2" + } + }, + "load-json-file": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", + "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=", + "dev": true, + "requires": { + "graceful-fs": "4.1.11", + "parse-json": "2.2.0", + "pify": "2.3.0", + "strip-bom": "3.0.0" + } + }, + "locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", + "dev": true, + "requires": { + "p-locate": "2.0.0", + "path-exists": "3.0.0" + }, + "dependencies": { + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "dev": true + } + } + }, + "lodash": { + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "dev": true + }, + "lru-cache": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz", + "integrity": "sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==", + "dev": true, + "requires": { + "pseudomap": "1.0.2", + "yallist": "2.1.2" + } + }, + "make-node": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/make-node/-/make-node-0.3.5.tgz", + "integrity": "sha1-LTVN240+zfWg1btMrbuqRGHK3jo=", + "dev": true + }, + "mimic-fn": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", + "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", + "dev": true + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "1.1.11" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "mocha": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", "dev": true, "requires": { @@ -226,13 +1133,144 @@ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "dev": true }, + "mute-stream": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", + "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", + "dev": true + }, + "natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", + "dev": true + }, + "normalize-package-data": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", + "integrity": "sha512-9jjUFbTPfEy3R/ad/2oNbKtW9Hgovl5O1FvFWKkKblNXoN/Oou6+9+KKohPK13Yc3/TyunyWhJp6gvRNR/PPAw==", + "dev": true, + "requires": { + "hosted-git-info": "2.7.1", + "is-builtin-module": "1.0.0", + "semver": "5.5.1", + "validate-npm-package-license": "3.0.4" + } + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true + }, + "object-keys": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.12.tgz", + "integrity": "sha512-FTMyFUm2wBcGHnH2eXmz7tC6IwlqQZ6mVZ+6dm6vZ4IQIHjs6FdNsQBuKGPuUUUY6NfJw2PshC08Tn6LzLDOag==", + "dev": true + }, + "object.assign": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", + "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", + "dev": true, + "requires": { + "define-properties": "1.1.3", + "function-bind": "1.1.1", + "has-symbols": "1.0.0", + "object-keys": "1.0.12" + } + }, + "object.entries": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.0.4.tgz", + "integrity": "sha1-G/mk3SKI9bM/Opk9JXZh8F0WGl8=", + "dev": true, + "requires": { + "define-properties": "1.1.3", + "es-abstract": "1.12.0", + "function-bind": "1.1.1", + "has": "1.0.3" + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "requires": { - "wrappy": "1" + "wrappy": "1.0.2" + } + }, + "onetime": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", + "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", + "dev": true, + "requires": { + "mimic-fn": "1.2.0" + } + }, + "optionator": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", + "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", + "dev": true, + "requires": { + "deep-is": "0.1.3", + "fast-levenshtein": "2.0.6", + "levn": "0.3.0", + "prelude-ls": "1.1.2", + "type-check": "0.3.2", + "wordwrap": "1.0.0" + } + }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "dev": true + }, + "p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "requires": { + "p-try": "1.0.0" + } + }, + "p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", + "dev": true, + "requires": { + "p-limit": "1.3.0" + } + }, + "p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", + "dev": true + }, + "parse-json": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", + "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", + "dev": true, + "requires": { + "error-ex": "1.3.2" + } + }, + "path-exists": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz", + "integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=", + "dev": true, + "requires": { + "pinkie-promise": "2.0.1" } }, "path-is-absolute": { @@ -241,19 +1279,399 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, + "path-is-inside": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", + "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", + "dev": true + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, + "path-type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz", + "integrity": "sha1-8BLMuEFbcJb8LaoQVMPXI4lZTHM=", + "dev": true, + "requires": { + "pify": "2.3.0" + } + }, "pathval": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", "dev": true }, + "pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true + }, + "pinkie": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", + "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=", + "dev": true + }, + "pinkie-promise": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", + "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", + "dev": true, + "requires": { + "pinkie": "2.0.4" + } + }, + "pkg-dir": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-1.0.0.tgz", + "integrity": "sha1-ektQio1bstYp1EcFb/TpyTFM89Q=", + "dev": true, + "requires": { + "find-up": "1.1.2" + } + }, + "pluralize": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz", + "integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==", + "dev": true + }, + "prelude-ls": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", + "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", + "dev": true + }, + "process-nextick-args": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", + "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", + "dev": true + }, + "progress": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz", + "integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8=", + "dev": true + }, + "pseudomap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", + "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", + "dev": true + }, + "read-pkg": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", + "integrity": "sha1-jvHAYjxqbbDcZxPEv6xGMysjaPg=", + "dev": true, + "requires": { + "load-json-file": "2.0.0", + "normalize-package-data": "2.4.0", + "path-type": "2.0.0" + } + }, + "read-pkg-up": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-2.0.0.tgz", + "integrity": "sha1-a3KoBImE4MQeeVEP1en6mbO1Sb4=", + "dev": true, + "requires": { + "find-up": "2.1.0", + "read-pkg": "2.0.0" + }, + "dependencies": { + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "dev": true, + "requires": { + "locate-path": "2.0.0" + } + } + } + }, + "readable-stream": { + "version": "2.3.6", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "dev": true, + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "2.0.0", + "safe-buffer": "5.1.2", + "string_decoder": "1.1.1", + "util-deprecate": "1.0.2" + } + }, + "regexpp": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-1.1.0.tgz", + "integrity": "sha512-LOPw8FpgdQF9etWMaAfG/WRthIdXJGYp4mJ2Jgn/2lpkbod9jPn0t9UqN7AxBOKNfzRbYyVfgc7Vk4t/MpnXgw==", + "dev": true + }, + "require-uncached": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", + "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=", + "dev": true, + "requires": { + "caller-path": "0.1.0", + "resolve-from": "1.0.1" + } + }, + "resolve": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", + "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", + "dev": true, + "requires": { + "path-parse": "1.0.6" + } + }, + "resolve-from": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-1.0.1.tgz", + "integrity": "sha1-Jsv+k10a7uq7Kbw/5a6wHpPUQiY=", + "dev": true + }, + "restore-cursor": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", + "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", + "dev": true, + "requires": { + "onetime": "2.0.1", + "signal-exit": "3.0.2" + } + }, + "rimraf": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", + "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", + "dev": true, + "requires": { + "glob": "7.1.2" + } + }, + "run-async": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", + "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", + "dev": true, + "requires": { + "is-promise": "2.1.0" + } + }, + "rx-lite": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz", + "integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=", + "dev": true + }, + "rx-lite-aggregates": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz", + "integrity": "sha1-dTuHqJoRyVRnxKwWJsTvxOBcZ74=", + "dev": true, + "requires": { + "rx-lite": "4.0.8" + } + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true + }, + "semver": { + "version": "5.5.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz", + "integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==", + "dev": true + }, + "shebang-command": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", + "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "dev": true, + "requires": { + "shebang-regex": "1.0.0" + } + }, + "shebang-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", + "dev": true + }, + "signal-exit": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "dev": true + }, + "slice-ansi": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz", + "integrity": "sha512-POqxBK6Lb3q6s047D/XsDVNPnF9Dl8JSaqe9h9lURl0OdNqy/ujDrOiIHtsqXMGbWWTIomRzAMaTyawAU//Reg==", + "dev": true, + "requires": { + "is-fullwidth-code-point": "2.0.0" + } + }, + "spdx-correct": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.0.tgz", + "integrity": "sha512-N19o9z5cEyc8yQQPukRCZ9EUmb4HUpnrmaL/fxS2pBo2jbfcFRVuFZ/oFC+vZz0MNNk0h80iMn5/S6qGZOL5+g==", + "dev": true, + "requires": { + "spdx-expression-parse": "3.0.0", + "spdx-license-ids": "3.0.1" + } + }, + "spdx-exceptions": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.1.0.tgz", + "integrity": "sha512-4K1NsmrlCU1JJgUrtgEeTVyfx8VaYea9J9LvARxhbHtVtohPs/gFGG5yy49beySjlIMhhXZ4QqujIZEfS4l6Cg==", + "dev": true + }, + "spdx-expression-parse": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", + "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", + "dev": true, + "requires": { + "spdx-exceptions": "2.1.0", + "spdx-license-ids": "3.0.1" + } + }, + "spdx-license-ids": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.1.tgz", + "integrity": "sha512-TfOfPcYGBB5sDuPn3deByxPhmfegAhpDYKSOXZQN81Oyrrif8ZCodOLzK3AesELnCx03kikhyDwh0pfvvQvF8w==", + "dev": true + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "dev": true + }, + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "dev": true, + "requires": { + "is-fullwidth-code-point": "2.0.0", + "strip-ansi": "4.0.0" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "5.1.2" + } + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, + "requires": { + "ansi-regex": "3.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + } + } + }, + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", + "dev": true + }, + "strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "dev": true + }, "supports-color": { "version": "5.4.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", "dev": true, "requires": { - "has-flag": "^3.0.0" + "has-flag": "3.0.0" + } + }, + "table": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/table/-/table-4.0.2.tgz", + "integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==", + "dev": true, + "requires": { + "ajv": "5.5.2", + "ajv-keywords": "2.1.1", + "chalk": "2.4.1", + "lodash": "4.17.11", + "slice-ansi": "1.0.0", + "string-width": "2.1.1" + } + }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "dev": true + }, + "through": { + "version": "2.3.8", + "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", + "dev": true + }, + "tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "dev": true, + "requires": { + "os-tmpdir": "1.0.2" + } + }, + "type-check": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", + "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", + "dev": true, + "requires": { + "prelude-ls": "1.1.2" } }, "type-detect": { @@ -262,11 +1680,63 @@ "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", "dev": true }, + "typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "dev": true + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "dev": true + }, + "validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dev": true, + "requires": { + "spdx-correct": "3.0.0", + "spdx-expression-parse": "3.0.0" + } + }, + "which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "dev": true, + "requires": { + "isexe": "2.0.0" + } + }, + "wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", + "dev": true + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true + }, + "write": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/write/-/write-0.2.1.tgz", + "integrity": "sha1-X8A4KOJkzqP+kUVUdvejxWbLB1c=", + "dev": true, + "requires": { + "mkdirp": "0.5.1" + } + }, + "yallist": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", + "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", + "dev": true } } } diff --git a/package.json b/package.json index 8fa13a8b..49b83b3f 100644 --- a/package.json +++ b/package.json @@ -36,12 +36,18 @@ "mocha": "5.2.x", "chai": "4.1.x", "chai-connect-middleware": "0.3.x", + "eslint-config-airbnb-base": "13.0.0", + "eslint-plugin-import": "2.12.0", + "eslint": "4.19.1", "@passport-next/chai-passport-strategy": "1.x.x" }, "engines": { "node": ">=6.0.0" }, "scripts": { - "test": "node_modules/.bin/mocha --reporter spec --require test/bootstrap/node test/*.test.js test/**/*.test.js" + "spec": "node_modules/.bin/mocha --reporter spec --require test/bootstrap/node test/*.test.js test/**/*.test.js", + "lint": "eslint --ext .js . --max-warnings 0", + "lintfix": "eslint --ext .js . --fix", + "test": "npm run lint && npm run spec" } } diff --git a/test/authenticator.framework.test.js b/test/authenticator.framework.test.js index 4daf98d4..afb05aaa 100644 --- a/test/authenticator.framework.test.js +++ b/test/authenticator.framework.test.js @@ -1,55 +1,53 @@ /* global describe, it, expect */ -var Authenticator = require('../lib/authenticator'); +/* eslint-disable camelcase, no-proto, no-shadow */ +const Authenticator = require('../lib/authenticator'); -describe('Authenticator', function() { - - describe('#framework', function() { - - describe('with an authenticate function used for authorization', function() { - var passport = new Authenticator(); + +describe('Authenticator', () => { + describe('#framework', () => { + describe('with an authenticate function used for authorization', () => { + const passport = new Authenticator(); passport.framework({ - initialize: function() { - return function() {}; + initialize() { + return function initialize() {}; }, - authenticate: function(passport, name, options) { - return function() { - return 'authenticate(): ' + name + ' ' + options.assignProperty; + authenticate(passport, name, options) { + return function authenticate() { + return `authenticate(): ${name} ${options.assignProperty}`; }; - } + }, }); - - var rv = passport.authorize('foo')(); - it('should call authenticate', function() { + + const rv = passport.authorize('foo')(); + it('should call authenticate', () => { expect(rv).to.equal('authenticate(): foo account'); }); }); - - describe('with an authorize function used for authorization', function() { - var passport = new Authenticator(); + + describe('with an authorize function used for authorization', () => { + const passport = new Authenticator(); passport.framework({ - initialize: function() { - return function() {}; + initialize() { + return function initialize() {}; }, - authenticate: function(passport, name, options) { - return function() { - return 'authenticate(): ' + name + ' ' + options.assignProperty; + authenticate(passport, name, options) { + return function authenticate() { + return `authenticate(): ${name} ${options.assignProperty}`; }; }, - authorize: function(passport, name, options) { - return function() { - return 'authorize(): ' + name + ' ' + options.assignProperty; + authorize(passport, name, options) { + return function authorize() { + return `authorize(): ${name} ${options.assignProperty}`; }; - } + }, }); - - var rv = passport.authorize('foo')(); - it('should call authorize', function() { + + const rv = passport.authorize('foo')(); + it('should call authorize', () => { expect(rv).to.equal('authorize(): foo account'); }); }); - }); - }); diff --git a/test/authenticator.middleware.test.js b/test/authenticator.middleware.test.js index 26452662..ef23b9e2 100644 --- a/test/authenticator.middleware.test.js +++ b/test/authenticator.middleware.test.js @@ -1,263 +1,270 @@ /* global describe, it, expect, before */ /* jshint expr: true */ +/* eslint-disable no-underscore-dangle, camelcase, no-proto, no-shadow */ -var chai = require('chai') - , Authenticator = require('../lib/authenticator'); +const chai = require('chai'); +const Authenticator = require('../lib/authenticator'); -describe('Authenticator', function() { - - describe('#initialize', function() { - - it('should have correct arity', function() { - var passport = new Authenticator(); +describe('Authenticator', () => { + describe('#initialize', () => { + it('should have correct arity', () => { + const passport = new Authenticator(); expect(passport.initialize).to.have.length(1); }); - - describe('handling a request', function() { - var passport = new Authenticator(); - var request, error; - before(function(done) { + describe('handling a request', () => { + const passport = new Authenticator(); + let request; + let error; + + before((done) => { chai.connect.use(passport.initialize()) - .req(function(req) { + .req((req) => { request = req; req.session = {}; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should set user property on authenticator', function() { + + it('should set user property on authenticator', () => { expect(passport._userProperty).to.equal('user'); }); - - it('should not initialize namespace within session', function() { + + it('should not initialize namespace within session', () => { + // eslint-disable-next-line no-unused-expressions expect(request.session.passport).to.be.undefined; }); - - it('should expose authenticator on internal request property', function() { + + it('should expose authenticator on internal request property', () => { expect(request._passport).to.be.an('object'); expect(request._passport.instance).to.be.an.instanceOf(Authenticator); expect(request._passport.instance).to.equal(passport); }); - - it('should not expose session storage on internal request property', function() { + + it('should not expose session storage on internal request property', () => { + // eslint-disable-next-line no-unused-expressions expect(request._passport.session).to.be.undefined; }); }); - - describe('handling a request with custom user property', function() { - var passport = new Authenticator(); - var request, error; - before(function(done) { + describe('handling a request with custom user property', () => { + const passport = new Authenticator(); + let request; + let error; + + before((done) => { chai.connect.use(passport.initialize({ userProperty: 'currentUser' })) - .req(function(req) { + .req((req) => { request = req; req.session = {}; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should set user property on authenticator', function() { + + it('should set user property on authenticator', () => { expect(passport._userProperty).to.equal('currentUser'); }); - - it('should not initialize namespace within session', function() { + + it('should not initialize namespace within session', () => { + // eslint-disable-next-line no-unused-expressions expect(request.session.passport).to.be.undefined; }); - - it('should expose authenticator on internal request property', function() { + + it('should expose authenticator on internal request property', () => { expect(request._passport).to.be.an('object'); expect(request._passport.instance).to.be.an.instanceOf(Authenticator); expect(request._passport.instance).to.equal(passport); }); - - it('should not expose session storage on internal request property', function() { + + it('should not expose session storage on internal request property', () => { + // eslint-disable-next-line no-unused-expressions expect(request._passport.session).to.be.undefined; }); }); - }); - - - describe('#authenticate', function() { - - it('should have correct arity', function() { - var passport = new Authenticator(); + + + describe('#authenticate', () => { + it('should have correct arity', () => { + const passport = new Authenticator(); expect(passport.authenticate).to.have.length(3); }); - - describe('handling a request', function() { + + describe('handling a request', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Authenticator(); + + const passport = new Authenticator(); passport.use('success', new Strategy()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(passport.authenticate('success')) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should set authInfo', function() { + + it('should set authInfo', () => { expect(request.authInfo).to.be.an('object'); expect(Object.keys(request.authInfo)).to.have.length(0); }); }); - }); - - - describe('#authorize', function() { - - it('should have correct arity', function() { - var passport = new Authenticator(); + + + describe('#authorize', () => { + it('should have correct arity', () => { + const passport = new Authenticator(); expect(passport.authorize).to.have.length(3); }); - - describe('handling a request', function() { + + describe('handling a request', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Authenticator(); + + const passport = new Authenticator(); passport.use('success', new Strategy()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(passport.authorize('success')) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should set account', function() { + + it('should set account', () => { expect(request.account).to.be.an('object'); expect(request.account.id).to.equal('1'); expect(request.account.username).to.equal('jaredhanson'); }); - - it('should not set authInfo', function() { + + it('should not set authInfo', () => { + // eslint-disable-next-line no-unused-expressions expect(request.authInfo).to.be.undefined; }); }); - }); - - describe('#session', function() { - - it('should have correct arity', function() { - var passport = new Authenticator(); + + describe('#session', () => { + it('should have correct arity', () => { + const passport = new Authenticator(); expect(passport.session).to.have.length(1); }); - - describe('handling a request', function() { - var passport = new Authenticator(); - passport.deserializeUser(function(user, done) { + + describe('handling a request', () => { + const passport = new Authenticator(); + passport.deserializeUser((user, done) => { done(null, { id: user }); }); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(passport.session()) - .req(function(req) { + .req((req) => { request = req; - + req._passport = {}; req._passport.instance = {}; req._passport.session = {}; req._passport.session.user = '123456'; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('123456'); }); - - it('should maintain session', function() { + + it('should maintain session', () => { expect(request._passport.session).to.be.an('object'); expect(request._passport.session.user).to.equal('123456'); }); }); - }); - }); diff --git a/test/authenticator.test.js b/test/authenticator.test.js index fb7a1394..1dd229ba 100644 --- a/test/authenticator.test.js +++ b/test/authenticator.test.js @@ -1,983 +1,1043 @@ /* global describe, it, expect, before */ /* jshint expr: true, sub: true */ -var Authenticator = require('../lib/authenticator'); +/* eslint-disable camelcase, no-proto, no-shadow */ +const Authenticator = require('../lib/authenticator'); -describe('Authenticator', function() { - - describe('#use', function() { - - describe('with instance name', function() { + +describe('Authenticator', () => { + describe('#use', () => { + describe('with instance name', () => { function Strategy() { this.name = 'default'; } - Strategy.prototype.authenticate = function(req) { - }; - - var authenticator = new Authenticator(); + Strategy.prototype.authenticate = function authenticate() {}; + + const authenticator = new Authenticator(); authenticator.use(new Strategy()); - - it('should register strategy', function() { - expect(authenticator._strategies['default']).to.be.an('object'); + + it('should register strategy', () => { + expect(authenticator._strategies.default).to.be.an('object'); }); }); - - describe('with registered name', function() { + + describe('with registered name', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - }; - - var authenticator = new Authenticator(); + Strategy.prototype.authenticate = function authenticate() {}; + + const authenticator = new Authenticator(); authenticator.use('foo', new Strategy()); - - it('should register strategy', function() { - expect(authenticator._strategies['foo']).to.be.an('object'); + + it('should register strategy', () => { + expect(authenticator._strategies.foo).to.be.an('object'); }); }); - - describe('with registered name overridding instance name', function() { + + describe('with registered name overridding instance name', () => { function Strategy() { this.name = 'default'; } - Strategy.prototype.authenticate = function(req) { - }; - - var authenticator = new Authenticator(); + Strategy.prototype.authenticate = function authenticate() {}; + + const authenticator = new Authenticator(); authenticator.use('bar', new Strategy()); - - it('should register strategy', function() { - expect(authenticator._strategies['bar']).to.be.an('object'); - expect(authenticator._strategies['default']).to.be.undefined; + + it('should register strategy', () => { + expect(authenticator._strategies.bar).to.be.an('object'); + // eslint-disable-next-line no-unused-expressions + expect(authenticator._strategies.default).to.be.undefined; }); }); - - it('should throw if lacking a name', function() { + + it('should throw if lacking a name', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - }; - - expect(function() { - var authenticator = new Authenticator(); + Strategy.prototype.authenticate = function authenticate() {}; + + expect(() => { + const authenticator = new Authenticator(); authenticator.use(new Strategy()); }).to.throw(Error, 'Authentication strategies must have a name'); }); }); - - - describe('#unuse', function() { + + + describe('#unuse', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - }; - - var authenticator = new Authenticator(); + Strategy.prototype.authenticate = function authenticate() {}; + + const authenticator = new Authenticator(); authenticator.use('one', new Strategy()); authenticator.use('two', new Strategy()); - - expect(authenticator._strategies['one']).to.be.an('object'); - expect(authenticator._strategies['two']).to.be.an('object'); - + + expect(authenticator._strategies.one).to.be.an('object'); + expect(authenticator._strategies.two).to.be.an('object'); + authenticator.unuse('one'); - - it('should unregister strategy', function() { - expect(authenticator._strategies['one']).to.be.undefined; - expect(authenticator._strategies['two']).to.be.an('object'); + + it('should unregister strategy', () => { + // eslint-disable-next-line no-unused-expressions + expect(authenticator._strategies.one).to.be.undefined; + expect(authenticator._strategies.two).to.be.an('object'); }); }); - - - describe('#serializeUser', function() { - - describe('without serializers', function() { - var authenticator = new Authenticator(); - var error, obj; - - before(function(done) { - authenticator.serializeUser({ id: '1', username: 'jared' }, function(err, o) { + + + describe('#serializeUser', () => { + describe('without serializers', () => { + const authenticator = new Authenticator(); + let error; + let obj; + + before((done) => { + authenticator.serializeUser({ id: '1', username: 'jared' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('Failed to serialize user into session'); }); - - it('should not serialize user', function() { + + it('should not serialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(obj).to.be.undefined; }); }); - - describe('with one serializer', function() { - var authenticator = new Authenticator(); - authenticator.serializeUser(function(user, done) { + + describe('with one serializer', () => { + const authenticator = new Authenticator(); + authenticator.serializeUser((user, done) => { done(null, user.id); }); - - var error, obj; - - before(function(done) { - authenticator.serializeUser({ id: '1', username: 'jared' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.serializeUser({ id: '1', username: 'jared' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should serialize user', function() { + + it('should serialize user', () => { expect(obj).to.equal('1'); }); }); - - describe('with one serializer that serializes to 0', function() { - var authenticator = new Authenticator(); - authenticator.serializeUser(function(user, done) { + + describe('with one serializer that serializes to 0', () => { + const authenticator = new Authenticator(); + authenticator.serializeUser((user, done) => { done(null, 0); }); - - var error, obj; - - before(function(done) { - authenticator.serializeUser({ id: '1', username: 'jared' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.serializeUser({ id: '1', username: 'jared' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should serialize user', function() { + + it('should serialize user', () => { expect(obj).to.equal(0); }); }); - - describe('with one serializer that serializes to false', function() { - var authenticator = new Authenticator(); - authenticator.serializeUser(function(user, done) { + + describe('with one serializer that serializes to false', () => { + const authenticator = new Authenticator(); + authenticator.serializeUser((user, done) => { done(null, false); }); - - var error, obj; - - before(function(done) { - authenticator.serializeUser({ id: '1', username: 'jared' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.serializeUser({ id: '1', username: 'jared' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('Failed to serialize user into session'); }); - - it('should not serialize user', function() { + + it('should not serialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(obj).to.be.undefined; }); }); - - describe('with one serializer that serializes to null', function() { - var authenticator = new Authenticator(); - authenticator.serializeUser(function(user, done) { + + describe('with one serializer that serializes to null', () => { + const authenticator = new Authenticator(); + authenticator.serializeUser((user, done) => { done(null, null); }); - - var error, obj; - - before(function(done) { - authenticator.serializeUser({ id: '1', username: 'jared' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.serializeUser({ id: '1', username: 'jared' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('Failed to serialize user into session'); }); - - it('should not serialize user', function() { + + it('should not serialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(obj).to.be.undefined; }); }); - - describe('with one serializer that serializes to undefined', function() { - var authenticator = new Authenticator(); - authenticator.serializeUser(function(user, done) { + + describe('with one serializer that serializes to undefined', () => { + const authenticator = new Authenticator(); + authenticator.serializeUser((user, done) => { done(null, undefined); }); - - var error, obj; - - before(function(done) { - authenticator.serializeUser({ id: '1', username: 'jared' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.serializeUser({ id: '1', username: 'jared' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('Failed to serialize user into session'); }); - - it('should not serialize user', function() { + + it('should not serialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(obj).to.be.undefined; }); }); - - describe('with one serializer that encounters an error', function() { - var authenticator = new Authenticator(); - authenticator.serializeUser(function(user, done) { + + describe('with one serializer that encounters an error', () => { + const authenticator = new Authenticator(); + authenticator.serializeUser((user, done) => { done(new Error('something went wrong')); }); - - var error, obj; - - before(function(done) { - authenticator.serializeUser({ id: '1', username: 'jared' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.serializeUser({ id: '1', username: 'jared' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something went wrong'); }); - - it('should not serialize user', function() { + + it('should not serialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(obj).to.be.undefined; }); }); - - describe('with one serializer that throws an exception', function() { - var authenticator = new Authenticator(); - authenticator.serializeUser(function(user, done) { + + describe('with one serializer that throws an exception', () => { + const authenticator = new Authenticator(); + authenticator.serializeUser(() => { throw new Error('something went horribly wrong'); }); - - var error, obj; - - before(function(done) { - authenticator.serializeUser({ id: '1', username: 'jared' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.serializeUser({ id: '1', username: 'jared' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something went horribly wrong'); }); - - it('should not serialize user', function() { + + it('should not serialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(obj).to.be.undefined; }); }); - - describe('with three serializers, the first of which passes and the second of which serializes', function() { - var authenticator = new Authenticator(); - authenticator.serializeUser(function(user, done) { + + describe('with three serializers, the first of which passes and the second of which serializes', () => { + const authenticator = new Authenticator(); + authenticator.serializeUser((user, done) => { done('pass'); }); - authenticator.serializeUser(function(user, done) { + authenticator.serializeUser((user, done) => { done(null, 'two'); }); - authenticator.serializeUser(function(user, done) { + authenticator.serializeUser((user, done) => { done(null, 'three'); }); - - var error, obj; - - before(function(done) { - authenticator.serializeUser({ id: '1', username: 'jared' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.serializeUser({ id: '1', username: 'jared' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should serialize user', function() { + + it('should serialize user', () => { expect(obj).to.equal('two'); }); }); - - describe('with three serializers, the first of which passes and the second of which does not serialize by no argument', function() { - var authenticator = new Authenticator(); - authenticator.serializeUser(function(user, done) { + + describe('with three serializers, the first of which passes and the second of which does not serialize by no argument', () => { + const authenticator = new Authenticator(); + authenticator.serializeUser((user, done) => { done('pass'); }); - authenticator.serializeUser(function(user, done) { + authenticator.serializeUser((user, done) => { done(null); }); - authenticator.serializeUser(function(user, done) { + authenticator.serializeUser((user, done) => { done(null, 'three'); }); - - var error, obj; - - before(function(done) { - authenticator.serializeUser({ id: '1', username: 'jared' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.serializeUser({ id: '1', username: 'jared' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should serialize user', function() { + + it('should serialize user', () => { expect(obj).to.equal('three'); }); }); - - describe('with three serializers, the first of which passes and the second of which does not serialize by undefined', function() { - var authenticator = new Authenticator(); - authenticator.serializeUser(function(user, done) { + + describe('with three serializers, the first of which passes and the second of which does not serialize by undefined', () => { + const authenticator = new Authenticator(); + authenticator.serializeUser((user, done) => { done('pass'); }); - authenticator.serializeUser(function(user, done) { + authenticator.serializeUser((user, done) => { done(null, undefined); }); - authenticator.serializeUser(function(user, done) { + authenticator.serializeUser((user, done) => { done(null, 'three'); }); - - var error, obj; - - before(function(done) { - authenticator.serializeUser({ id: '1', username: 'jared' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.serializeUser({ id: '1', username: 'jared' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should serialize user', function() { + + it('should serialize user', () => { expect(obj).to.equal('three'); }); }); - - describe('with one serializer that takes request as argument', function() { - var authenticator = new Authenticator(); - authenticator.serializeUser(function(req, user, done) { + + describe('with one serializer that takes request as argument', () => { + const authenticator = new Authenticator(); + authenticator.serializeUser((req, user, done) => { if (req.url !== '/foo') { return done(new Error('incorrect req argument')); } - done(null, user.id); + return done(null, user.id); }); - - var error, obj; - - before(function(done) { - var req = { url: '/foo' }; - - authenticator.serializeUser({ id: '1', username: 'jared' }, req, function(err, o) { + + let error; + let obj; + + before((done) => { + const req = { url: '/foo' }; + + authenticator.serializeUser({ id: '1', username: 'jared' }, req, (err, o) => { error = err; obj = o; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should serialize user', function() { + + it('should serialize user', () => { expect(obj).to.equal('1'); }); }); - }); - - - describe('#deserializeUser', function() { - - describe('without deserializers', function() { - var authenticator = new Authenticator(); - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + + describe('#deserializeUser', () => { + describe('without deserializers', () => { + const authenticator = new Authenticator(); + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('Failed to deserialize user out of session'); }); - - it('should not deserialize user', function() { + + it('should not deserialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(user).to.be.undefined; }); }); - - describe('with one deserializer', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(obj, done) { + + describe('with one deserializer', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser((obj, done) => { done(null, obj.username); }); - - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should deserialize user', function() { + + it('should deserialize user', () => { expect(user).to.equal('jared'); }); }); - - describe('with one deserializer that deserializes to false', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(obj, done) { + + describe('with one deserializer that deserializes to false', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser((obj, done) => { done(null, false); }); - - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should invalidate session', function() { + + it('should invalidate session', () => { + // eslint-disable-next-line no-unused-expressions expect(user).to.be.false; }); }); - - describe('with one deserializer that deserializes to null', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(obj, done) { + + describe('with one deserializer that deserializes to null', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser((obj, done) => { done(null, null); }); - - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should invalidate session', function() { + + it('should invalidate session', () => { + // eslint-disable-next-line no-unused-expressions expect(user).to.be.false; }); }); - - describe('with one deserializer that deserializes to undefined', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(obj, done) { + + describe('with one deserializer that deserializes to undefined', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser((obj, done) => { done(null, undefined); }); - - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('Failed to deserialize user out of session'); }); - - it('should not deserialize user', function() { + + it('should not deserialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(user).to.be.undefined; }); }); - - describe('with one deserializer that encounters an error', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(obj, done) { + + describe('with one deserializer that encounters an error', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser((obj, done) => { done(new Error('something went wrong')); }); - - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something went wrong'); }); - - it('should invalidate session', function() { + + it('should invalidate session', () => { + // eslint-disable-next-line no-unused-expressions expect(user).to.be.undefined; }); }); - - describe('with one deserializer that throws an exception', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(obj, done) { + + describe('with one deserializer that throws an exception', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser(() => { throw new Error('something went horribly wrong'); }); - - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something went horribly wrong'); }); - - it('should invalidate session', function() { + + it('should invalidate session', () => { + // eslint-disable-next-line no-unused-expressions expect(user).to.be.undefined; }); }); - - describe('with three deserializers, the first of which passes and the second of which deserializes', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(obj, done) { + + describe('with three deserializers, the first of which passes and the second of which deserializes', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser((obj, done) => { done('pass'); }); - authenticator.deserializeUser(function(obj, done) { + authenticator.deserializeUser((obj, done) => { done(null, 'two'); }); - authenticator.deserializeUser(function(obj, done) { + authenticator.deserializeUser((obj, done) => { done(null, 'three'); }); - - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should deserialize user', function() { + + it('should deserialize user', () => { expect(user).to.equal('two'); }); }); - - describe('with three deserializers, the first of which passes and the second of which does not deserialize by no argument', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(obj, done) { + + describe('with three deserializers, the first of which passes and the second of which does not deserialize by no argument', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser((obj, done) => { done('pass'); }); - authenticator.deserializeUser(function(obj, done) { + authenticator.deserializeUser((obj, done) => { done(null); }); - authenticator.deserializeUser(function(obj, done) { + authenticator.deserializeUser((obj, done) => { done(null, 'three'); }); - - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should deserialize user', function() { + + it('should deserialize user', () => { expect(user).to.equal('three'); }); }); - - describe('with three deserializers, the first of which passes and the second of which does not deserialize by undefined', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(obj, done) { + + describe('with three deserializers, the first of which passes and the second of which does not deserialize by undefined', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser((obj, done) => { done('pass'); }); - authenticator.deserializeUser(function(obj, done) { + authenticator.deserializeUser((obj, done) => { done(null, undefined); }); - authenticator.deserializeUser(function(obj, done) { + authenticator.deserializeUser((obj, done) => { done(null, 'three'); }); - - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should deserialize user', function() { + + it('should deserialize user', () => { expect(user).to.equal('three'); }); }); - - describe('with three deserializers, the first of which passes and the second of which invalidates session by false', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(obj, done) { + + describe('with three deserializers, the first of which passes and the second of which invalidates session by false', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser((obj, done) => { done('pass'); }); - authenticator.deserializeUser(function(obj, done) { + authenticator.deserializeUser((obj, done) => { done(null, false); }); - authenticator.deserializeUser(function(obj, done) { + authenticator.deserializeUser((obj, done) => { done(null, 'three'); }); - - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should invalidate session', function() { + + it('should invalidate session', () => { + // eslint-disable-next-line no-unused-expressions expect(user).to.be.false; }); }); - - describe('with three deserializers, the first of which passes and the second of which invalidates session by null', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(obj, done) { + + describe('with three deserializers, the first of which passes and the second of which invalidates session by null', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser((obj, done) => { done('pass'); }); - authenticator.deserializeUser(function(obj, done) { + authenticator.deserializeUser((obj, done) => { done(null, null); }); - authenticator.deserializeUser(function(obj, done) { + authenticator.deserializeUser((obj, done) => { done(null, 'three'); }); - - var error, user; - - before(function(done) { - authenticator.deserializeUser({ id: '1', username: 'jared' }, function(err, u) { + + let error; + let user; + + before((done) => { + authenticator.deserializeUser({ id: '1', username: 'jared' }, (err, u) => { error = err; user = u; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should invalidate session', function() { + + it('should invalidate session', () => { + // eslint-disable-next-line no-unused-expressions expect(user).to.be.false; }); }); - - describe('with one deserializer that takes request as argument', function() { - var authenticator = new Authenticator(); - authenticator.deserializeUser(function(req, obj, done) { + + describe('with one deserializer that takes request as argument', () => { + const authenticator = new Authenticator(); + authenticator.deserializeUser((req, obj, done) => { if (req.url !== '/foo') { return done(new Error('incorrect req argument')); } - done(null, obj.username); + return done(null, obj.username); }); - - var error, user; - - before(function(done) { - var req = { url: '/foo' }; - - authenticator.deserializeUser({ id: '1', username: 'jared' }, req, function(err, u) { + + let error; + let user; + + before((done) => { + const req = { url: '/foo' }; + + authenticator.deserializeUser({ id: '1', username: 'jared' }, req, (err, u) => { error = err; user = u; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should deserialize user', function() { + + it('should deserialize user', () => { expect(user).to.equal('jared'); }); }); - }); - - - describe('#transformAuthInfo', function() { - - describe('without transforms', function() { - var authenticator = new Authenticator(); - var error, obj; - - before(function(done) { - authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, function(err, o) { + + + describe('#transformAuthInfo', () => { + describe('without transforms', () => { + const authenticator = new Authenticator(); + let error; + let obj; + + before((done) => { + authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should not transform info', function() { + + it('should not transform info', () => { expect(Object.keys(obj)).to.have.length(2); expect(obj.clientId).to.equal('1'); expect(obj.scope).to.equal('write'); }); }); - - describe('with one transform', function() { - var authenticator = new Authenticator(); - authenticator.transformAuthInfo(function(info, done) { - done(null, { clientId: info.clientId, client: { name: 'Foo' }}); + + describe('with one transform', () => { + const authenticator = new Authenticator(); + authenticator.transformAuthInfo((info, done) => { + done(null, { clientId: info.clientId, client: { name: 'Foo' } }); }); - - var error, obj; - - before(function(done) { - authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should not transform info', function() { + + it('should not transform info', () => { expect(Object.keys(obj)).to.have.length(2); expect(obj.clientId).to.equal('1'); expect(obj.client.name).to.equal('Foo'); + // eslint-disable-next-line no-unused-expressions expect(obj.scope).to.be.undefined; }); }); - - describe('with one transform that encounters an error', function() { - var authenticator = new Authenticator(); - authenticator.transformAuthInfo(function(info, done) { + + describe('with one transform that encounters an error', () => { + const authenticator = new Authenticator(); + authenticator.transformAuthInfo((info, done) => { done(new Error('something went wrong')); }); - - var error, obj; - - before(function(done) { - authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something went wrong'); }); - - it('should not transform info', function() { + + it('should not transform info', () => { + // eslint-disable-next-line no-unused-expressions expect(obj).to.be.undefined; }); }); - - describe('with one transform that throws an exception', function() { - var authenticator = new Authenticator(); - authenticator.transformAuthInfo(function(info, done) { + + describe('with one transform that throws an exception', () => { + const authenticator = new Authenticator(); + authenticator.transformAuthInfo(() => { throw new Error('something went horribly wrong'); }); - - var error, obj; - - before(function(done) { - authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something went horribly wrong'); }); - - it('should not transform info', function() { + + it('should not transform info', () => { + // eslint-disable-next-line no-unused-expressions expect(obj).to.be.undefined; }); }); - - describe('with one sync transform', function() { - var authenticator = new Authenticator(); - authenticator.transformAuthInfo(function(info) { - return { clientId: info.clientId, client: { name: 'Foo' }}; - }); - - var error, obj; - - before(function(done) { - authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, function(err, o) { + + describe('with one sync transform', () => { + const authenticator = new Authenticator(); + authenticator.transformAuthInfo(info => ({ clientId: info.clientId, client: { name: 'Foo' } })); + + let error; + let obj; + + before((done) => { + authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should not transform info', function() { + + it('should not transform info', () => { expect(Object.keys(obj)).to.have.length(2); expect(obj.clientId).to.equal('1'); expect(obj.client.name).to.equal('Foo'); + // eslint-disable-next-line no-unused-expressions expect(obj.scope).to.be.undefined; }); }); - - describe('with three transform, the first of which passes and the second of which transforms', function() { - var authenticator = new Authenticator(); - authenticator.transformAuthInfo(function(info, done) { + + describe('with three transform, the first of which passes and the second of which transforms', () => { + const authenticator = new Authenticator(); + authenticator.transformAuthInfo((info, done) => { done('pass'); }); - authenticator.transformAuthInfo(function(info, done) { - done(null, { clientId: info.clientId, client: { name: 'Two' }}); + authenticator.transformAuthInfo((info, done) => { + done(null, { clientId: info.clientId, client: { name: 'Two' } }); }); - authenticator.transformAuthInfo(function(info, done) { - done(null, { clientId: info.clientId, client: { name: 'Three' }}); + authenticator.transformAuthInfo((info, done) => { + done(null, { clientId: info.clientId, client: { name: 'Three' } }); }); - - var error, obj; - - before(function(done) { - authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, function(err, o) { + + let error; + let obj; + + before((done) => { + authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, (err, o) => { error = err; obj = o; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should not transform info', function() { + + it('should not transform info', () => { expect(Object.keys(obj)).to.have.length(2); expect(obj.clientId).to.equal('1'); expect(obj.client.name).to.equal('Two'); + // eslint-disable-next-line no-unused-expressions expect(obj.scope).to.be.undefined; }); }); - - describe('with one transform that takes request as argument', function() { - var authenticator = new Authenticator(); - authenticator.transformAuthInfo(function(req, info, done) { + + describe('with one transform that takes request as argument', () => { + const authenticator = new Authenticator(); + authenticator.transformAuthInfo((req, info, done) => { if (req.url !== '/foo') { return done(new Error('incorrect req argument')); } - done(null, { clientId: info.clientId, client: { name: 'Foo' }}); + return done(null, { clientId: info.clientId, client: { name: 'Foo' } }); }); - - var error, obj; - - before(function(done) { - var req = { url: '/foo' }; - - authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, req, function(err, o) { + + let error; + let obj; + + before((done) => { + const req = { url: '/foo' }; + + authenticator.transformAuthInfo({ clientId: '1', scope: 'write' }, req, (err, o) => { error = err; obj = o; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should not transform info', function() { + + it('should not transform info', () => { expect(Object.keys(obj)).to.have.length(2); expect(obj.clientId).to.equal('1'); expect(obj.client.name).to.equal('Foo'); + // eslint-disable-next-line no-unused-expressions expect(obj.scope).to.be.undefined; }); }); - }); - }); diff --git a/test/bootstrap/node.js b/test/bootstrap/node.js index b7dc941d..7ea8dd1c 100644 --- a/test/bootstrap/node.js +++ b/test/bootstrap/node.js @@ -1,4 +1,4 @@ -var chai = require('chai'); +const chai = require('chai'); chai.use(require('chai-connect-middleware')); chai.use(require('@passport-next/chai-passport-strategy')); diff --git a/test/http/request.test.js b/test/http/request.test.js index f268ee5e..1d14ee14 100644 --- a/test/http/request.test.js +++ b/test/http/request.test.js @@ -1,460 +1,499 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var http = require('http') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ + +const http = require('http'); +const Passport = require('../..').Passport; require('../../lib/framework/connect').__monkeypatchNode(); -describe('http.ServerRequest', function() { - - describe('prototoype', function() { - var req = new http.IncomingMessage(); - - it('should be extended with login', function() { +describe('http.ServerRequest', () => { + describe('prototoype', () => { + const req = new http.IncomingMessage(); + + it('should be extended with login', () => { expect(req.login).to.be.an('function'); expect(req.login).to.equal(req.logIn); }); - - it('should be extended with logout', function() { + + it('should be extended with logout', () => { expect(req.logout).to.be.an('function'); expect(req.logout).to.equal(req.logOut); }); - - it('should be extended with isAuthenticated', function() { + + it('should be extended with isAuthenticated', () => { expect(req.isAuthenticated).to.be.an('function'); }); - - it('should be extended with isUnauthenticated', function() { + + it('should be extended with isUnauthenticated', () => { expect(req.isUnauthenticated).to.be.an('function'); }); }); - - describe('#login', function() { - - describe('not establishing a session', function() { - var passport = new Passport(); - - var req = new http.IncomingMessage(); + + describe('#login', () => { + describe('not establishing a session', () => { + const passport = new Passport(); + + const req = new http.IncomingMessage(); req._passport = {}; req._passport.instance = passport; req._passport.session = {}; - - var error; - - before(function(done) { - var user = { id: '1', username: 'root' }; - - req.login(user, { session: false }, function(err) { + + let error; + + before((done) => { + const user = { id: '1', username: 'root' }; + + req.login(user, { session: false }, (err) => { error = err; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should be authenticated', function() { + + it('should be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.true; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.false; }); - - it('should set user', function() { + + it('should set user', () => { expect(req.user).to.be.an('object'); expect(req.user.id).to.equal('1'); expect(req.user.username).to.equal('root'); }); - - it('should not serialize user', function() { + + it('should not serialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(req._passport.session.user).to.be.undefined; }); }); - - describe('not establishing a session and setting custom user property', function() { - var passport = new Passport(); + + describe('not establishing a session and setting custom user property', () => { + const passport = new Passport(); passport._userProperty = 'currentUser'; - - var req = new http.IncomingMessage(); + + const req = new http.IncomingMessage(); req._passport = {}; req._passport.instance = passport; req._passport.session = {}; - - var error; - - before(function(done) { - var user = { id: '1', username: 'root' }; - - req.login(user, { session: false }, function(err) { + + let error; + + before((done) => { + const user = { id: '1', username: 'root' }; + + req.login(user, { session: false }, (err) => { error = err; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should be authenticated', function() { + + it('should be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.true; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.false; }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(req.user).to.be.undefined; }); - - it('should set custom user', function() { + + it('should set custom user', () => { expect(req.currentUser).to.be.an('object'); expect(req.currentUser.id).to.equal('1'); expect(req.currentUser.username).to.equal('root'); }); - - it('should not serialize user', function() { + + it('should not serialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(req._passport.session.user).to.be.undefined; }); }); - - describe('not establishing a session and invoked without a callback', function() { - var passport = new Passport(); - - var req = new http.IncomingMessage(); + + describe('not establishing a session and invoked without a callback', () => { + const passport = new Passport(); + + const req = new http.IncomingMessage(); req._passport = {}; req._passport.instance = passport; req._passport.session = {}; - - var user = { id: '1', username: 'root' }; + + const user = { id: '1', username: 'root' }; req.login(user, { session: false }); - - it('should be authenticated', function() { + + it('should be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.true; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.false; }); - - it('should set user', function() { + + it('should set user', () => { expect(req.user).to.be.an('object'); expect(req.user.id).to.equal('1'); expect(req.user.username).to.equal('root'); }); - - it('should not serialize user', function() { + + it('should not serialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(req._passport.session.user).to.be.undefined; }); }); - - describe('not establishing a session, without passport.initialize() middleware', function() { - var req = new http.IncomingMessage(); - - var error; - - before(function(done) { - var user = { id: '1', username: 'root' }; - - req.login(user, { session: false }, function(err) { + + describe('not establishing a session, without passport.initialize() middleware', () => { + const req = new http.IncomingMessage(); + + let error; + + before((done) => { + const user = { id: '1', username: 'root' }; + + req.login(user, { session: false }, (err) => { error = err; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should be authenticated', function() { + + it('should be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.true; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.false; }); - - it('should set user', function() { + + it('should set user', () => { expect(req.user).to.be.an('object'); expect(req.user.id).to.equal('1'); expect(req.user.username).to.equal('root'); }); }); - - describe('establishing a session', function() { - var passport = new Passport(); - passport.serializeUser(function(user, done) { + + describe('establishing a session', () => { + const passport = new Passport(); + passport.serializeUser((user, done) => { done(null, user.id); }); - - var req = new http.IncomingMessage(); + + const req = new http.IncomingMessage(); req._passport = {}; req._passport.instance = passport; req._passport.session = {}; - - var error; - - before(function(done) { - var user = { id: '1', username: 'root' }; - - req.login(user, function(err) { + + let error; + + before((done) => { + const user = { id: '1', username: 'root' }; + + req.login(user, (err) => { error = err; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should be authenticated', function() { + + it('should be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.true; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.false; }); - - it('should set user', function() { + + it('should set user', () => { expect(req.user).to.be.an('object'); expect(req.user.id).to.equal('1'); expect(req.user.username).to.equal('root'); }); - - it('should serialize user', function() { + + it('should serialize user', () => { expect(req._passport.session.user).to.equal('1'); }); }); - - describe('establishing a session and setting custom user property', function() { - var passport = new Passport(); - passport.serializeUser(function(user, done) { + + describe('establishing a session and setting custom user property', () => { + const passport = new Passport(); + passport.serializeUser((user, done) => { done(null, user.id); }); passport._userProperty = 'currentUser'; - - var req = new http.IncomingMessage(); + + const req = new http.IncomingMessage(); req._passport = {}; req._passport.instance = passport; req._passport.session = {}; - - var error; - - before(function(done) { - var user = { id: '1', username: 'root' }; - - req.login(user, function(err) { + + let error; + + before((done) => { + const user = { id: '1', username: 'root' }; + + req.login(user, (err) => { error = err; done(); }); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should be authenticated', function() { + + it('should be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.true; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.false; }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(req.user).to.be.undefined; }); - - it('should set custom user', function() { + + it('should set custom user', () => { expect(req.currentUser).to.be.an('object'); expect(req.currentUser.id).to.equal('1'); expect(req.currentUser.username).to.equal('root'); }); - - it('should serialize user', function() { + + it('should serialize user', () => { expect(req._passport.session.user).to.equal('1'); }); }); - - describe('encountering an error when serializing to session', function() { - var passport = new Passport(); - passport.serializeUser(function(user, done) { + + describe('encountering an error when serializing to session', () => { + const passport = new Passport(); + passport.serializeUser((user, done) => { done(new Error('something went wrong')); }); - - var req = new http.IncomingMessage(); + + const req = new http.IncomingMessage(); req._passport = {}; req._passport.instance = passport; req._passport.session = {}; - - var error; - - before(function(done) { - var user = { id: '1', username: 'root' }; - - req.login(user, function(err) { + + let error; + + before((done) => { + const user = { id: '1', username: 'root' }; + + req.login(user, (err) => { error = err; done(); }); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something went wrong'); }); - - it('should not be authenticated', function() { + + it('should not be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.false; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.true; }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(req.user).to.be.null; }); - - it('should not serialize user', function() { + + it('should not serialize user', () => { + // eslint-disable-next-line no-unused-expressions expect(req._passport.session.user).to.be.undefined; }); }); - - describe('establishing a session, without passport.initialize() middleware', function() { - var req = new http.IncomingMessage(); - var user = { id: '1', username: 'root' }; - - it('should throw an exception', function() { - expect(function() { - req.login(user, function(err) {}); + + describe('establishing a session, without passport.initialize() middleware', () => { + const req = new http.IncomingMessage(); + const user = { id: '1', username: 'root' }; + + it('should throw an exception', () => { + expect(() => { + req.login(user, () => {}); }).to.throw(Error, 'passport.initialize() middleware not in use'); }); }); - - describe('establishing a session, but not passing a callback argument', function() { - var passport = new Passport(); - passport.serializeUser(function(user, done) { + + describe('establishing a session, but not passing a callback argument', () => { + const passport = new Passport(); + passport.serializeUser((user, done) => { done(null, user.id); }); - - var req = new http.IncomingMessage(); + + const req = new http.IncomingMessage(); req._passport = {}; req._passport.instance = passport; req._passport.session = {}; - - var user = { id: '1', username: 'root' }; - - it('should throw an exception', function() { - expect(function() { + + const user = { id: '1', username: 'root' }; + + it('should throw an exception', () => { + expect(() => { req.login(user); }).to.throw(Error, 'req#login requires a callback function'); }); }); - }); - - - describe('#logout', function() { - - describe('existing session', function() { - var passport = new Passport(); - - var req = new http.IncomingMessage(); + + + describe('#logout', () => { + describe('existing session', () => { + const passport = new Passport(); + + const req = new http.IncomingMessage(); req.user = { id: '1', username: 'root' }; req._passport = {}; req._passport.instance = passport; req._passport.session = {}; req._passport.session.user = '1'; - + req.logout(); - - it('should not be authenticated', function() { + + it('should not be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.false; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.true; }); - - it('should clear user', function() { + + it('should clear user', () => { + // eslint-disable-next-line no-unused-expressions expect(req.user).to.be.null; }); - - it('should clear serialized user', function() { + + it('should clear serialized user', () => { + // eslint-disable-next-line no-unused-expressions expect(req._passport.session.user).to.be.undefined; }); }); - - describe('existing session and clearing custom user property', function() { - var passport = new Passport(); - - var req = new http.IncomingMessage(); + + describe('existing session and clearing custom user property', () => { + const passport = new Passport(); + + const req = new http.IncomingMessage(); req.currentUser = { id: '1', username: 'root' }; req._passport = {}; req._passport.instance = passport; req._passport.instance._userProperty = 'currentUser'; req._passport.session = {}; req._passport.session.user = '1'; - + req.logout(); - - it('should not be authenticated', function() { + + it('should not be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.false; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.true; }); - - it('should clear user', function() { + + it('should clear user', () => { + // eslint-disable-next-line no-unused-expressions expect(req.currentUser).to.be.null; }); - - it('should clear serialized user', function() { + + it('should clear serialized user', () => { + // eslint-disable-next-line no-unused-expressions expect(req._passport.session.user).to.be.undefined; }); }); - - describe('existing session, without passport.initialize() middleware', function() { - var req = new http.IncomingMessage(); + + describe('existing session, without passport.initialize() middleware', () => { + const req = new http.IncomingMessage(); req.user = { id: '1', username: 'root' }; - + req.logout(); - - it('should not be authenticated', function() { + + it('should not be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.false; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.true; }); - - it('should clear user', function() { + + it('should clear user', () => { + // eslint-disable-next-line no-unused-expressions expect(req.user).to.be.null; }); }); - }); - - - describe('#isAuthenticated', function() { - - describe('with a user', function() { - var req = new http.IncomingMessage(); + + + describe('#isAuthenticated', () => { + describe('with a user', () => { + const req = new http.IncomingMessage(); req.user = { id: '1', username: 'root' }; - - it('should be authenticated', function() { + + it('should be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.true; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.false; }); }); - - describe('with a user set on custom property', function() { - var req = new http.IncomingMessage(); + + describe('with a user set on custom property', () => { + const req = new http.IncomingMessage(); req.currentUser = { id: '1', username: 'root' }; req._passport = {}; req._passport.instance = {}; req._passport.instance._userProperty = 'currentUser'; - - it('should be authenticated', function() { + + it('should be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.true; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.false; }); }); - - describe('without a user', function() { - var req = new http.IncomingMessage(); - - it('should not be authenticated', function() { + + describe('without a user', () => { + const req = new http.IncomingMessage(); + + it('should not be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.false; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.true; }); }); - - describe('with a null user', function() { - var req = new http.IncomingMessage(); + + describe('with a null user', () => { + const req = new http.IncomingMessage(); req.user = null; - - it('should not be authenticated', function() { + + it('should not be authenticated', () => { + // eslint-disable-next-line no-unused-expressions expect(req.isAuthenticated()).to.be.false; + // eslint-disable-next-line no-unused-expressions expect(req.isUnauthenticated()).to.be.true; }); }); - }); - }); diff --git a/test/middleware/authenticate.error.callback.test.js b/test/middleware/authenticate.error.callback.test.js index 45a02fcd..3295e554 100644 --- a/test/middleware/authenticate.error.callback.test.js +++ b/test/middleware/authenticate.error.callback.test.js @@ -1,91 +1,95 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ -describe('middleware/authenticate', function() { - - describe('error with callback', function() { +const chai = require('chai'); +const Passport = require('../..').Passport; +const authenticate = require('../../lib/middleware/authenticate'); + +describe('middleware/authenticate', () => { + describe('error with callback', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.error(new Error('something is wrong')); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('error', new Strategy()); - - var request, error, user; - before(function(done) { - function callback(e, u) { + let request; + let error; + + before((done) => { + function callback(e) { error = e; - user = u; done(); } - + chai.connect.use(authenticate(passport, 'error', callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should pass error to callback', function() { + + it('should pass error to callback', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something is wrong'); }); - - it('should pass user as undefined to callback', function() { + + it('should pass user as undefined to callback', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - - describe('error with callback and options passed to middleware', function() { + + describe('error with callback and options passed to middleware', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.error(new Error('something is wrong')); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('error', new Strategy()); - - var request, error, user; - before(function(done) { - function callback(e, u) { + let request; + let error; + + before((done) => { + function callback(e) { error = e; - user = u; done(); } - + chai.connect.use(authenticate(passport, 'error', { foo: 'bar' }, callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should pass error to callback', function() { + + it('should pass error to callback', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something is wrong'); }); - - it('should pass user as undefined to callback', function() { + + it('should pass user as undefined to callback', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - }); diff --git a/test/middleware/authenticate.error.test.js b/test/middleware/authenticate.error.test.js index 5ec8ce0b..c201d660 100644 --- a/test/middleware/authenticate.error.test.js +++ b/test/middleware/authenticate.error.test.js @@ -1,45 +1,47 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - describe('error', function() { + +describe('middleware/authenticate', () => { + describe('error', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.error(new Error('something is wrong')); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('error', new Strategy()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, 'error')) - .req(function(req) { + .req((req) => { request = req; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something is wrong'); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - }); diff --git a/test/middleware/authenticate.fail.callback.test.js b/test/middleware/authenticate.fail.callback.test.js index 49720eba..73bba9d4 100644 --- a/test/middleware/authenticate.fail.callback.test.js +++ b/test/middleware/authenticate.fail.callback.test.js @@ -1,65 +1,73 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - describe('fail with callback', function() { +describe('middleware/authenticate', () => { + describe('fail with callback', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, error, user; - before(function(done) { + let request; + let error; + let user; + + before((done) => { function callback(e, u) { error = e; user = u; done(); } - + chai.connect.use(authenticate(passport, 'fail', callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass false to callback', function() { + + it('should pass false to callback', () => { expect(user).to.equal(false); }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - - describe('fail with callback, passing info', function() { + + describe('fail with callback, passing info', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid password' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, error, user, info, status; - before(function(done) { + let request; + let error; + let user; + let info; + let status; + + before((done) => { function callback(e, u, i, s) { error = e; user = u; @@ -67,49 +75,56 @@ describe('middleware/authenticate', function() { status = s; done(); } - + chai.connect.use(authenticate(passport, 'fail', callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass false to callback', function() { + + it('should pass false to callback', () => { expect(user).to.equal(false); }); - - it('should pass info to callback', function() { + + it('should pass info to callback', () => { expect(info).to.be.an('object'); expect(info.message).to.equal('Invalid password'); }); - - it('should pass status to callback', function() { + + it('should pass status to callback', () => { + // eslint-disable-next-line no-unused-expressions expect(status).to.be.undefined; }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - - describe('fail with callback, passing info and status', function() { + + describe('fail with callback, passing info and status', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid password' }, 403); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, error, user, info, status; - before(function(done) { + let request; + let error; + let user; + let info; + let status; + + before((done) => { function callback(e, u, i, s) { error = e; user = u; @@ -117,49 +132,55 @@ describe('middleware/authenticate', function() { status = s; done(); } - + chai.connect.use(authenticate(passport, 'fail', callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass false to callback', function() { + + it('should pass false to callback', () => { expect(user).to.equal(false); }); - - it('should pass info to callback', function() { + + it('should pass info to callback', () => { expect(info).to.be.an('object'); expect(info.message).to.equal('Invalid password'); }); - - it('should pass status to callback', function() { + + it('should pass status to callback', () => { expect(status).to.equal(403); }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - - describe('fail with callback, passing challenge', function() { + + describe('fail with callback, passing challenge', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail('Bearer challenge'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, error, user, challenge, status; - before(function(done) { + let request; + let error; + let user; + let challenge; + let status; + + before((done) => { function callback(e, u, c, s) { error = e; user = u; @@ -167,48 +188,55 @@ describe('middleware/authenticate', function() { status = s; done(); } - + chai.connect.use(authenticate(passport, 'fail', callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass false to callback', function() { + + it('should pass false to callback', () => { expect(user).to.equal(false); }); - - it('should pass challenge to callback', function() { + + it('should pass challenge to callback', () => { expect(challenge).to.equal('Bearer challenge'); }); - - it('should pass status to callback', function() { + + it('should pass status to callback', () => { + // eslint-disable-next-line no-unused-expressions expect(status).to.be.undefined; }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - - describe('fail with callback, passing challenge and status', function() { + + describe('fail with callback, passing challenge and status', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail('Bearer challenge', 403); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, error, user, challenge, status; - before(function(done) { + let request; + let error; + let user; + let challenge; + let status; + + before((done) => { function callback(e, u, c, s) { error = e; user = u; @@ -216,48 +244,54 @@ describe('middleware/authenticate', function() { status = s; done(); } - + chai.connect.use(authenticate(passport, 'fail', callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass false to callback', function() { + + it('should pass false to callback', () => { expect(user).to.equal(false); }); - - it('should pass challenge to callback', function() { + + it('should pass challenge to callback', () => { expect(challenge).to.equal('Bearer challenge'); }); - - it('should pass status to callback', function() { + + it('should pass status to callback', () => { expect(status).to.equal(403); }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - - describe('fail with callback, passing status', function() { + + describe('fail with callback, passing status', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(402); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, error, user, challenge, status; - before(function(done) { + let request; + let error; + let user; + let challenge; + let status; + + before((done) => { function callback(e, u, c, s) { error = e; user = u; @@ -265,72 +299,78 @@ describe('middleware/authenticate', function() { status = s; done(); } - + chai.connect.use(authenticate(passport, 'fail', callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass false to callback', function() { + + it('should pass false to callback', () => { expect(user).to.equal(false); }); - - it('should pass challenge to callback', function() { + + it('should pass challenge to callback', () => { + // eslint-disable-next-line no-unused-expressions expect(challenge).to.be.undefined; }); - - it('should pass status to callback', function() { + + it('should pass status to callback', () => { expect(status).to.equal(402); }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - - describe('fail with callback and options passed to middleware', function() { + + describe('fail with callback and options passed to middleware', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, error, user; - before(function(done) { + let request; + let error; + let user; + + before((done) => { function callback(e, u) { error = e; user = u; done(); } - + chai.connect.use(authenticate(passport, 'fail', { foo: 'bar' }, callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass false to callback', function() { + + it('should pass false to callback', () => { expect(user).to.equal(false); }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - }); diff --git a/test/middleware/authenticate.fail.flash.test.js b/test/middleware/authenticate.fail.flash.test.js index c508631d..8d5398e3 100644 --- a/test/middleware/authenticate.fail.flash.test.js +++ b/test/middleware/authenticate.fail.flash.test.js @@ -1,928 +1,1002 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - describe('using strategy that specifies message', function() { - - describe('fail with flash message', function() { + +describe('middleware/authenticate', () => { + describe('using strategy that specifies message', () => { + describe('fail with flash message', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid password' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: true, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: true, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('error'); expect(request.message.msg).to.equal('Invalid password'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message using type set by route', function() { + + describe('fail with flash message using type set by route', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid password' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { type: 'info' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { type: 'info' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('info'); expect(request.message.msg).to.equal('Invalid password'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message overridden by route as string', function() { + + describe('fail with flash message overridden by route as string', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid password' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: 'Wrong credentials', - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: 'Wrong credentials', + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('error'); expect(request.message.msg).to.equal('Wrong credentials'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message overridden by route using options', function() { + + describe('fail with flash message overridden by route using options', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid password' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { message: 'Try again' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { message: 'Try again' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('error'); expect(request.message.msg).to.equal('Try again'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message overridden by route using options with type', function() { + + describe('fail with flash message overridden by route using options with type', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid password' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { type: 'notice', message: 'Try again' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { type: 'notice', message: 'Try again' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('notice'); expect(request.message.msg).to.equal('Try again'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - }); - - - describe('using strategy that specifies message and type', function() { - - describe('fail with flash message', function() { + + + describe('using strategy that specifies message and type', () => { + describe('fail with flash message', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ type: 'notice', message: 'Invite required' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: true, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: true, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('notice'); expect(request.message.msg).to.equal('Invite required'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message using type set by route', function() { + + describe('fail with flash message using type set by route', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ type: 'notice', message: 'Invite required' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { type: 'info' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { type: 'info' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('info'); expect(request.message.msg).to.equal('Invite required'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message overridden by route as string', function() { + + describe('fail with flash message overridden by route as string', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ type: 'notice', message: 'Invite required' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: 'Wrong credentials', - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: 'Wrong credentials', + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('error'); expect(request.message.msg).to.equal('Wrong credentials'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message overridden by route using options', function() { + + describe('fail with flash message overridden by route using options', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ type: 'notice', message: 'Invite required' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { message: 'Try again' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { message: 'Try again' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('error'); expect(request.message.msg).to.equal('Try again'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message overridden by route using options with type', function() { + + describe('fail with flash message overridden by route using options with type', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ type: 'notice', message: 'Invite required' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { type: 'info', message: 'Try again' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { type: 'info', message: 'Try again' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('info'); expect(request.message.msg).to.equal('Try again'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - }); - - - describe('using strategy that specifies message as string', function() { - - describe('fail with flash message', function() { + + + describe('using strategy that specifies message as string', () => { + describe('fail with flash message', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail('Access denied'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: true, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: true, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('error'); expect(request.message.msg).to.equal('Access denied'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message using type set by route', function() { + + describe('fail with flash message using type set by route', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail('Access denied'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { type: 'info' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { type: 'info' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('info'); expect(request.message.msg).to.equal('Access denied'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message overridden by route as string', function() { + + describe('fail with flash message overridden by route as string', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail('Access denied'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: 'Wrong credentials', - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: 'Wrong credentials', + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('error'); expect(request.message.msg).to.equal('Wrong credentials'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message overridden by route using options', function() { + + describe('fail with flash message overridden by route using options', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail('Access denied'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { message: 'Try again' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { message: 'Try again' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('error'); expect(request.message.msg).to.equal('Try again'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message overridden by route using options with type', function() { + + describe('fail with flash message overridden by route using options with type', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail('Access denied'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { type: 'notice', message: 'Try again' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { type: 'notice', message: 'Try again' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('notice'); expect(request.message.msg).to.equal('Try again'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - }); - - - describe('using strategy that does not specify message', function() { - - describe('fail with flash message left up to strategy', function() { + + + describe('using strategy that does not specify message', () => { + describe('fail with flash message left up to strategy', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: true, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: true, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not flash message', function() { + + it('should not flash message', () => { + // eslint-disable-next-line no-unused-expressions expect(request.message).to.be.undefined; }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message left up to strategy using type set by route', function() { + + describe('fail with flash message left up to strategy using type set by route', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { type: 'info' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { type: 'info' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not flash message', function() { + + it('should not flash message', () => { + // eslint-disable-next-line no-unused-expressions expect(request.message).to.be.undefined; }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message specified by route as string', function() { + + describe('fail with flash message specified by route as string', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: 'Wrong credentials', - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: 'Wrong credentials', + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('error'); expect(request.message.msg).to.equal('Wrong credentials'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message specified by route using options', function() { + + describe('fail with flash message specified by route using options', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { message: 'Try again' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { message: 'Try again' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('error'); expect(request.message.msg).to.equal('Try again'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with flash message specified by route using options with type', function() { + + describe('fail with flash message specified by route using options with type', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureFlash: { type: 'notice', message: 'Try again' }, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureFlash: { type: 'notice', message: 'Try again' }, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('notice'); expect(request.message.msg).to.equal('Try again'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - }); - }); diff --git a/test/middleware/authenticate.fail.message.test.js b/test/middleware/authenticate.fail.message.test.js index 87c456f7..17c74831 100644 --- a/test/middleware/authenticate.fail.message.test.js +++ b/test/middleware/authenticate.fail.message.test.js @@ -1,177 +1,193 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - describe('fail with message set by route', function() { +describe('middleware/authenticate', () => { + describe('fail with message set by route', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid password' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureMessage: 'Wrong credentials', - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureMessage: 'Wrong credentials', + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should add message to session', function() { + + it('should add message to session', () => { expect(request.session.messages).to.have.length(1); expect(request.session.messages[0]).to.equal('Wrong credentials'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with message set by route that is added to messages', function() { + + describe('fail with message set by route that is added to messages', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid password' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureMessage: 'Wrong credentials', - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureMessage: 'Wrong credentials', + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; - req.session.messages = [ 'I exist!' ]; + req.session.messages = ['I exist!']; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should add message to session', function() { + + it('should add message to session', () => { expect(request.session.messages).to.have.length(2); expect(request.session.messages[0]).to.equal('I exist!'); expect(request.session.messages[1]).to.equal('Wrong credentials'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with message set by strategy', function() { + + describe('fail with message set by strategy', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid password' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureMessage: true, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureMessage: true, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should add message to session', function() { + + it('should add message to session', () => { expect(request.session.messages).to.have.length(1); expect(request.session.messages[0]).to.equal('Invalid password'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with message set by strategy with extra info', function() { + + describe('fail with message set by strategy with extra info', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid password', scope: 'read' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'fail', { failureMessage: true, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'fail', { + failureMessage: true, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; req.session = {}; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should add message to session', function() { + + it('should add message to session', () => { expect(request.session.messages).to.have.length(1); expect(request.session.messages[0]).to.equal('Invalid password'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - }); diff --git a/test/middleware/authenticate.fail.multi.test.js b/test/middleware/authenticate.fail.multi.test.js index 46cdccb1..60deb858 100644 --- a/test/middleware/authenticate.fail.multi.test.js +++ b/test/middleware/authenticate.fail.multi.test.js @@ -1,205 +1,219 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - describe('with multiple strategies, all of which fail, and responding with unauthorized status', function() { + +describe('middleware/authenticate', () => { + describe('with multiple strategies, all of which fail, and responding with unauthorized status', () => { function BasicStrategy() { } - BasicStrategy.prototype.authenticate = function(req) { + BasicStrategy.prototype.authenticate = function authenticate() { this.fail('BASIC challenge'); }; - + function DigestStrategy() { } - DigestStrategy.prototype.authenticate = function(req) { + DigestStrategy.prototype.authenticate = function authenticate() { this.fail('DIGEST challenge'); }; - + function NoChallengeStrategy() { } - NoChallengeStrategy.prototype.authenticate = function(req) { + NoChallengeStrategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('basic', new BasicStrategy()); passport.use('digest', new DigestStrategy()); passport.use('no-challenge', new NoChallengeStrategy()); - - var request, response; - before(function(done) { + let request; + let response; + + before((done) => { chai.connect.use(authenticate(passport, ['basic', 'no-challenge', 'digest'])) - .req(function(req) { + .req((req) => { request = req; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should respond', function() { + + it('should respond', () => { expect(response.statusCode).to.equal(401); expect(response.body).to.equal('Unauthorized'); }); - - it('should set authenticate header on response', function() { - var val = response.getHeader('WWW-Authenticate'); + + it('should set authenticate header on response', () => { + const val = response.getHeader('WWW-Authenticate'); expect(val).to.be.an('array'); expect(val).to.have.length(2); - + expect(val[0]).to.equal('BASIC challenge'); expect(val[1]).to.equal('DIGEST challenge'); }); }); - - describe('with multiple strategies, all of which fail, and responding with specified status', function() { + + describe('with multiple strategies, all of which fail, and responding with specified status', () => { function BasicStrategy() { } - BasicStrategy.prototype.authenticate = function(req) { + BasicStrategy.prototype.authenticate = function authenticate() { this.fail('BASIC challenge', 400); }; - + function BearerStrategy() { } - BearerStrategy.prototype.authenticate = function(req) { + BearerStrategy.prototype.authenticate = function authenticate() { this.fail('BEARER challenge', 403); }; - + function NoChallengeStrategy() { } - NoChallengeStrategy.prototype.authenticate = function(req) { + NoChallengeStrategy.prototype.authenticate = function authenticate() { this.fail(402); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('basic', new BasicStrategy()); passport.use('bearer', new BearerStrategy()); passport.use('no-challenge', new NoChallengeStrategy()); - - var request, response; - before(function(done) { + let request; + let response; + + before((done) => { chai.connect.use(authenticate(passport, ['basic', 'no-challenge', 'bearer'])) - .req(function(req) { + .req((req) => { request = req; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should respond', function() { + + it('should respond', () => { expect(response.statusCode).to.equal(400); + // eslint-disable-next-line no-unused-expressions expect(response.getHeader('WWW-Authenticate')).to.be.undefined; expect(response.body).to.equal('Bad Request'); }); }); - - describe('with multiple strategies, all of which fail, and flashing message', function() { + + describe('with multiple strategies, all of which fail, and flashing message', () => { function StrategyA() { } - StrategyA.prototype.authenticate = function(req) { + StrategyA.prototype.authenticate = function authenticate() { this.fail('A message'); }; - + function StrategyB() { } - StrategyB.prototype.authenticate = function(req) { + StrategyB.prototype.authenticate = function authenticate() { this.fail('B message'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('a', new StrategyA()); passport.use('b', new StrategyB()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, ['a', 'b'], { failureFlash: true, - failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, ['a', 'b'], { + failureFlash: true, + failureRedirect: 'http://www.example.com/login', + })) + .req((req) => { request = req; - - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('error'); expect(request.message.msg).to.equal('A message'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('with multiple strategies, all of which fail with unauthorized status, and invoking callback', function() { + + describe('with multiple strategies, all of which fail with unauthorized status, and invoking callback', () => { function BasicStrategy() { } - BasicStrategy.prototype.authenticate = function(req) { + BasicStrategy.prototype.authenticate = function authenticate() { this.fail('BASIC challenge'); }; - + function DigestStrategy() { } - DigestStrategy.prototype.authenticate = function(req) { + DigestStrategy.prototype.authenticate = function authenticate() { this.fail('DIGEST challenge'); }; - + function NoChallengeStrategy() { } - NoChallengeStrategy.prototype.authenticate = function(req) { + NoChallengeStrategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('basic', new BasicStrategy()); passport.use('digest', new DigestStrategy()); passport.use('no-challenge', new NoChallengeStrategy()); - - var request, error, user, challenge, status; - before(function(done) { + let request; + let error; + let user; + let challenge; + let status; + + before((done) => { function callback(e, u, c, s) { error = e; user = u; @@ -207,70 +221,80 @@ describe('middleware/authenticate', function() { status = s; done(); } - + chai.connect.use(authenticate(passport, ['basic', 'no-challenge', 'digest'], callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass false to callback', function() { + + it('should pass false to callback', () => { expect(user).to.equal(false); }); - - it('should pass challenges to callback', function() { + + it('should pass challenges to callback', () => { expect(challenge).to.be.an('array'); expect(challenge).to.have.length(3); expect(challenge[0]).to.equal('BASIC challenge'); + // eslint-disable-next-line no-unused-expressions expect(challenge[1]).to.be.undefined; expect(challenge[2]).to.equal('DIGEST challenge'); }); - - it('should pass statuses to callback', function() { + + it('should pass statuses to callback', () => { expect(status).to.be.an('array'); expect(status).to.have.length(3); + // eslint-disable-next-line no-unused-expressions expect(status[0]).to.be.undefined; + // eslint-disable-next-line no-unused-expressions expect(status[1]).to.be.undefined; + // eslint-disable-next-line no-unused-expressions expect(status[2]).to.be.undefined; }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - - describe('with multiple strategies, all of which fail with specific status, and invoking callback', function() { + + describe('with multiple strategies, all of which fail with specific status, and invoking callback', () => { function BasicStrategy() { } - BasicStrategy.prototype.authenticate = function(req) { + BasicStrategy.prototype.authenticate = function authenticate() { this.fail('BASIC challenge', 400); }; - + function BearerStrategy() { } - BearerStrategy.prototype.authenticate = function(req) { + BearerStrategy.prototype.authenticate = function authenticate() { this.fail('BEARER challenge', 403); }; - + function NoChallengeStrategy() { } - NoChallengeStrategy.prototype.authenticate = function(req) { + NoChallengeStrategy.prototype.authenticate = function authenticate() { this.fail(402); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('basic', new BasicStrategy()); passport.use('bearer', new BearerStrategy()); passport.use('no-challenge', new NoChallengeStrategy()); - - var request, error, user, challenge, status; - before(function(done) { + let request; + let error; + let user; + let challenge; + let status; + + before((done) => { function callback(e, u, c, s) { error = e; user = u; @@ -278,56 +302,63 @@ describe('middleware/authenticate', function() { status = s; done(); } - + chai.connect.use(authenticate(passport, ['basic', 'no-challenge', 'bearer'], callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass false to callback', function() { + + it('should pass false to callback', () => { expect(user).to.equal(false); }); - - it('should pass challenges to callback', function() { + + it('should pass challenges to callback', () => { expect(challenge).to.be.an('array'); expect(challenge).to.have.length(3); expect(challenge[0]).to.equal('BASIC challenge'); + // eslint-disable-next-line no-unused-expressions expect(challenge[1]).to.be.undefined; expect(challenge[2]).to.equal('BEARER challenge'); }); - - it('should pass statuses to callback', function() { + + it('should pass statuses to callback', () => { expect(status).to.be.an('array'); expect(status).to.have.length(3); expect(status[0]).to.equal(400); expect(status[1]).to.equal(402); expect(status[2]).to.equal(403); }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - - describe('with single strategy in list, which fails with unauthorized status, and invoking callback', function() { + + describe('with single strategy in list, which fails with unauthorized status, and invoking callback', () => { function BasicStrategy() { } - BasicStrategy.prototype.authenticate = function(req) { + BasicStrategy.prototype.authenticate = function authenticate() { this.fail('BASIC challenge'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('basic', new BasicStrategy()); - - var request, error, user, challenge, status; - before(function(done) { + let request; + let error; + let user; + let challenge; + let status; + + before((done) => { function callback(e, u, c, s) { error = e; user = u; @@ -335,37 +366,39 @@ describe('middleware/authenticate', function() { status = s; done(); } - + chai.connect.use(authenticate(passport, ['basic'], callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass false to callback', function() { + + it('should pass false to callback', () => { expect(user).to.equal(false); }); - - it('should pass challenges to callback', function() { + + it('should pass challenges to callback', () => { expect(challenge).to.be.an('array'); expect(challenge).to.have.length(1); expect(challenge[0]).to.equal('BASIC challenge'); }); - - it('should pass statuses to callback', function() { + + it('should pass statuses to callback', () => { expect(status).to.be.an('array'); expect(status).to.have.length(1); + // eslint-disable-next-line no-unused-expressions expect(status[0]).to.be.undefined; }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - }); diff --git a/test/middleware/authenticate.fail.test.js b/test/middleware/authenticate.fail.test.js index 977f7d34..ac45b55b 100644 --- a/test/middleware/authenticate.fail.test.js +++ b/test/middleware/authenticate.fail.test.js @@ -1,469 +1,511 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - describe('fail', function() { + +describe('middleware/authenticate', () => { + describe('fail', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { + let request; + let response; + + before((done) => { chai.connect.use(authenticate(passport, 'fail')) - .req(function(req) { + .req((req) => { request = req; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should respond', function() { + + it('should respond', () => { expect(response.statusCode).to.equal(401); + // eslint-disable-next-line no-unused-expressions expect(response.getHeader('WWW-Authenticate')).to.be.undefined; expect(response.body).to.equal('Unauthorized'); }); }); - - describe('fail with redirect', function() { + + describe('fail with redirect', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { + let request; + let response; + + before((done) => { chai.connect.use('express', authenticate(passport, 'fail', { failureRedirect: 'http://www.example.com/login' })) - .req(function(req) { + .req((req) => { request = req; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/login'); }); }); - - describe('fail with challenge', function() { + + describe('fail with challenge', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail('MOCK challenge'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { + let request; + let response; + + before((done) => { chai.connect.use(authenticate(passport, 'fail')) - .req(function(req) { + .req((req) => { request = req; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should respond', function() { + + it('should respond', () => { expect(response.statusCode).to.equal(401); expect(response.body).to.equal('Unauthorized'); }); - - it('should set authenticate header on response', function() { - var val = response.getHeader('WWW-Authenticate'); + + it('should set authenticate header on response', () => { + const val = response.getHeader('WWW-Authenticate'); expect(val).to.be.an('array'); expect(val).to.have.length(1); - + expect(val[0]).to.equal('MOCK challenge'); }); }); - - describe('fail with challenge and status', function() { + + describe('fail with challenge and status', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail('MOCK challenge', 403); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { + let request; + let response; + + before((done) => { chai.connect.use(authenticate(passport, 'fail')) - .req(function(req) { + .req((req) => { request = req; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should respond', function() { + + it('should respond', () => { expect(response.statusCode).to.equal(403); + // eslint-disable-next-line no-unused-expressions expect(response.getHeader('WWW-Authenticate')).to.be.undefined; expect(response.body).to.equal('Forbidden'); }); }); - - describe('fail with status', function() { + + describe('fail with status', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(400); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response; - before(function(done) { + let request; + let response; + + before((done) => { chai.connect.use(authenticate(passport, 'fail')) - .req(function(req) { + .req((req) => { request = req; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should respond', function() { + + it('should respond', () => { expect(response.statusCode).to.equal(400); + // eslint-disable-next-line no-unused-expressions expect(response.getHeader('WWW-Authenticate')).to.be.undefined; expect(response.body).to.equal('Bad Request'); }); }); - - describe('fail with error', function() { + + describe('fail with error', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response, error; - before(function(done) { + let request; + let response; + let error; + + before((done) => { chai.connect.use('express', authenticate(passport, 'fail', { failWithError: true })) - .req(function(req) { + .req((req) => { request = req; }) - .res(function(res) { + .res((res) => { response = res; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.constructor.name).to.equal('AuthenticationError'); expect(error.message).to.equal('Unauthorized'); expect(error.status).to.equal(401); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set body of response', function() { + + it('should not set body of response', () => { expect(response.statusCode).to.equal(401); + // eslint-disable-next-line no-unused-expressions expect(response.getHeader('WWW-Authenticate')).to.be.undefined; + // eslint-disable-next-line no-unused-expressions expect(response.body).to.be.undefined; }); }); - - describe('fail with error, passing info to fail', function() { + + describe('fail with error, passing info to fail', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Invalid credentials' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response, error; - before(function(done) { + let request; + let response; + let error; + + before((done) => { chai.connect.use('express', authenticate(passport, 'fail', { failWithError: true })) - .req(function(req) { + .req((req) => { request = req; }) - .res(function(res) { + .res((res) => { response = res; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.constructor.name).to.equal('AuthenticationError'); expect(error.message).to.equal('Unauthorized'); expect(error.status).to.equal(401); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set body of response', function() { + + it('should not set body of response', () => { expect(response.statusCode).to.equal(401); + // eslint-disable-next-line no-unused-expressions expect(response.getHeader('WWW-Authenticate')).to.be.undefined; + // eslint-disable-next-line no-unused-expressions expect(response.body).to.be.undefined; }); }); - - describe('fail with error, passing info and status to fail', function() { + + describe('fail with error, passing info and status to fail', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail({ message: 'Multiple credentials' }, 400); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response, error; - before(function(done) { + let request; + let response; + let error; + + before((done) => { chai.connect.use('express', authenticate(passport, 'fail', { failWithError: true })) - .req(function(req) { + .req((req) => { request = req; }) - .res(function(res) { + .res((res) => { response = res; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.constructor.name).to.equal('AuthenticationError'); expect(error.message).to.equal('Bad Request'); expect(error.status).to.equal(400); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set body of response', function() { + + it('should not set body of response', () => { expect(response.statusCode).to.equal(400); + // eslint-disable-next-line no-unused-expressions expect(response.getHeader('WWW-Authenticate')).to.be.undefined; + // eslint-disable-next-line no-unused-expressions expect(response.body).to.be.undefined; }); }); - - describe('fail with error, passing challenge to fail', function() { + + describe('fail with error, passing challenge to fail', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail('Bearer challenge'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response, error; - before(function(done) { + let request; + let response; + let error; + + before((done) => { chai.connect.use('express', authenticate(passport, 'fail', { failWithError: true })) - .req(function(req) { + .req((req) => { request = req; }) - .res(function(res) { + .res((res) => { response = res; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.constructor.name).to.equal('AuthenticationError'); expect(error.message).to.equal('Unauthorized'); expect(error.status).to.equal(401); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set body of response', function() { + + it('should not set body of response', () => { expect(response.statusCode).to.equal(401); + // eslint-disable-next-line no-unused-expressions expect(response.body).to.be.undefined; }); - - it('should set authenticate header on response', function() { - var val = response.getHeader('WWW-Authenticate'); + + it('should set authenticate header on response', () => { + const val = response.getHeader('WWW-Authenticate'); expect(val).to.be.an('array'); expect(val).to.have.length(1); - + expect(val[0]).to.equal('Bearer challenge'); }); }); - - describe('fail with error, passing challenge and status to fail', function() { + + describe('fail with error, passing challenge and status to fail', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail('Bearer challenge', 403); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response, error; - before(function(done) { + let request; + let response; + let error; + + before((done) => { chai.connect.use('express', authenticate(passport, 'fail', { failWithError: true })) - .req(function(req) { + .req((req) => { request = req; }) - .res(function(res) { + .res((res) => { response = res; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.constructor.name).to.equal('AuthenticationError'); expect(error.message).to.equal('Forbidden'); expect(error.status).to.equal(403); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set body of response', function() { + + it('should not set body of response', () => { expect(response.statusCode).to.equal(403); + // eslint-disable-next-line no-unused-expressions expect(response.getHeader('WWW-Authenticate')).to.be.undefined; + // eslint-disable-next-line no-unused-expressions expect(response.body).to.be.undefined; }); }); - - describe('fail with error, passing status to fail', function() { + + describe('fail with error, passing status to fail', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.fail(402); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('fail', new Strategy()); - - var request, response, error; - before(function(done) { + let request; + let response; + let error; + + before((done) => { chai.connect.use('express', authenticate(passport, 'fail', { failWithError: true })) - .req(function(req) { + .req((req) => { request = req; }) - .res(function(res) { + .res((res) => { response = res; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.constructor.name).to.equal('AuthenticationError'); expect(error.message).to.equal('Payment Required'); expect(error.status).to.equal(402); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set body of response', function() { + + it('should not set body of response', () => { expect(response.statusCode).to.equal(402); + // eslint-disable-next-line no-unused-expressions expect(response.getHeader('WWW-Authenticate')).to.be.undefined; + // eslint-disable-next-line no-unused-expressions expect(response.body).to.be.undefined; }); }); - }); diff --git a/test/middleware/authenticate.pass.test.js b/test/middleware/authenticate.pass.test.js index 2f79fdf4..49a35bf2 100644 --- a/test/middleware/authenticate.pass.test.js +++ b/test/middleware/authenticate.pass.test.js @@ -1,44 +1,47 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - describe('pass', function() { + +describe('middleware/authenticate', () => { + describe('pass', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.pass(); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('pass', new Strategy()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, 'pass')) - .req(function(req) { + .req((req) => { request = req; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - }); diff --git a/test/middleware/authenticate.redirect.test.js b/test/middleware/authenticate.redirect.test.js index 0ade9899..b7195f2a 100644 --- a/test/middleware/authenticate.redirect.test.js +++ b/test/middleware/authenticate.redirect.test.js @@ -1,197 +1,207 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - describe('redirect', function() { +describe('middleware/authenticate', () => { + describe('redirect', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.redirect('http://www.example.com/idp'); }; - var passport = new Passport(); + const passport = new Passport(); passport.use('redirect', new Strategy()); - var request, response; + let request; + let response; - before(function(done) { + before((done) => { chai.connect.use(authenticate(passport, 'redirect')) - .req(function(req) { + .req((req) => { request = req; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - it('should not set user', function() { + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - it('should redirect', function() { + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/idp'); expect(response.getHeader('Content-Length')).to.equal('0'); }); }); - describe('redirect with session', function() { + describe('redirect with session', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { + Strategy.prototype.authenticate = function authenticate() { const user = { id: '1', username: 'idurotola' }; this.success(user); }; - var passport = new Passport(); + const passport = new Passport(); passport.use('success', new Strategy()); - var request, response; - var authenticator = authenticate(passport, 'success', { - successRedirect: 'http://www.example.com/idp' - }) + let request; + let response; + const authenticator = authenticate(passport, 'success', { + successRedirect: 'http://www.example.com/idp', + }); - before(function(done) { + before((done) => { chai.connect.use('express', authenticator) - .req(function(req) { + .req((req) => { request = req; req.session = {}; - req.session.save = function(done) { + req.session.save = function save(done) { done(); - } + }; - req.logIn = function(user, options, done) { + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - it('should set user', function() { + it('should set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.not.be.undefined; }); - it('should redirect', function() { + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/idp'); }); }); - describe('redirect with status', function() { + describe('redirect with status', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.redirect('http://www.example.com/idp', 303); }; - var passport = new Passport(); + const passport = new Passport(); passport.use('redirect', new Strategy()); - var request, response; + let request; + let response; - before(function(done) { + before((done) => { chai.connect.use(authenticate(passport, 'redirect')) - .req(function(req) { + .req((req) => { request = req; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - it('should not set user', function() { + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - it('should redirect', function() { + it('should redirect', () => { expect(response.statusCode).to.equal(303); expect(response.getHeader('Location')).to.equal('http://www.example.com/idp'); expect(response.getHeader('Content-Length')).to.equal('0'); }); }); - describe('redirect using framework function', function() { + describe('redirect using framework function', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.redirect('http://www.example.com/idp'); }; - var passport = new Passport(); + const passport = new Passport(); passport.use('redirect', new Strategy()); - var request, response; + let request; + let response; - before(function(done) { + before((done) => { chai.connect.use('express', authenticate(passport, 'redirect')) - .req(function(req) { + .req((req) => { request = req; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - it('should not set user', function() { + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - it('should redirect', function() { + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/idp'); }); }); - describe('redirect with status using framework function', function() { + describe('redirect with status using framework function', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { + Strategy.prototype.authenticate = function authenticate() { this.redirect('http://www.example.com/idp', 303); }; - var passport = new Passport(); + const passport = new Passport(); passport.use('redirect', new Strategy()); - var request, response; + let request; + let response; - before(function(done) { + before((done) => { chai.connect.use('express', authenticate(passport, 'redirect')) - .req(function(req) { + .req((req) => { request = req; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - it('should not set user', function() { + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - it('should redirect', function() { + it('should redirect', () => { expect(response.statusCode).to.equal(303); expect(response.getHeader('Location')).to.equal('http://www.example.com/idp'); }); }); - }); diff --git a/test/middleware/authenticate.success.callback.test.js b/test/middleware/authenticate.success.callback.test.js index 9c094556..97cd161f 100644 --- a/test/middleware/authenticate.success.callback.test.js +++ b/test/middleware/authenticate.success.callback.test.js @@ -1,115 +1,128 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - describe('success with callback', function() { + +describe('middleware/authenticate', () => { + describe('success with callback', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { message: 'Hello' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, error, user, info; - before(function(done) { + let request; + let error; + let user; + let info; + + before((done) => { function callback(e, u, i) { error = e; user = u; info = i; done(); } - + chai.connect.use(authenticate(passport, 'success', callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass user to callback', function() { + + it('should pass user to callback', () => { expect(user).to.be.an('object'); expect(user.id).to.equal('1'); expect(user.username).to.equal('jaredhanson'); }); - - it('should pass info to callback', function() { + + it('should pass info to callback', () => { expect(info).to.be.an('object'); expect(info.message).to.equal('Hello'); }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set authInfo on request', function() { + + it('should not set authInfo on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.authInfo).to.be.undefined; }); }); - - describe('success with callback and options passed to middleware', function() { + + describe('success with callback and options passed to middleware', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - var user = { id: '1', username: 'jaredhanson' }; + // eslint-disable-next-line consistent-return + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { message: 'Hello' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, error, user, info; - before(function(done) { + let request; + let error; + let user; + let info; + + before((done) => { function callback(e, u, i) { error = e; user = u; info = i; done(); } - + chai.connect.use(authenticate(passport, 'success', { foo: 'bar' }, callback)) - .req(function(req) { + .req((req) => { request = req; }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.null; }); - - it('should pass user to callback', function() { + + it('should pass user to callback', () => { expect(user).to.be.an('object'); expect(user.id).to.equal('1'); expect(user.username).to.equal('jaredhanson'); }); - - it('should pass info to callback', function() { + + it('should pass info to callback', () => { expect(info).to.be.an('object'); expect(info.message).to.equal('Hello'); }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set authInfo on request', function() { + + it('should not set authInfo on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.authInfo).to.be.undefined; }); }); - }); diff --git a/test/middleware/authenticate.success.flash.test.js b/test/middleware/authenticate.success.flash.test.js index f4a63154..6adab984 100644 --- a/test/middleware/authenticate.success.flash.test.js +++ b/test/middleware/authenticate.success.flash.test.js @@ -1,1068 +1,1122 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - describe('using strategy that specifies message', function() { - - describe('success with flash message', function() { + +describe('middleware/authenticate', () => { + describe('using strategy that specifies message', () => { + describe('success with flash message', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { message: 'Welcome!' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: true, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: true, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('success'); expect(request.message.msg).to.equal('Welcome!'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message using type set by route', function() { + + describe('success with flash message using type set by route', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { message: 'Welcome!' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { type: 'info' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { type: 'info' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('info'); expect(request.message.msg).to.equal('Welcome!'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message overridden by route as string', function() { + + describe('success with flash message overridden by route as string', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { message: 'Welcome!' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: 'Login complete', - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: 'Login complete', + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('success'); expect(request.message.msg).to.equal('Login complete'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message overridden by route using options', function() { + + describe('success with flash message overridden by route using options', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { message: 'Welcome!' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { message: 'OK' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { message: 'OK' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('success'); expect(request.message.msg).to.equal('OK'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message overridden by route using options with type', function() { + + describe('success with flash message overridden by route using options with type', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { message: 'Welcome!' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { type: 'notice', message: 'Last login was yesterday' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { type: 'notice', message: 'Last login was yesterday' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('notice'); expect(request.message.msg).to.equal('Last login was yesterday'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - }); - - - describe('using strategy that specifies message and type', function() { - - describe('success with flash message', function() { + + + describe('using strategy that specifies message and type', () => { + describe('success with flash message', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { type: 'info', message: 'Hello' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: true, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: true, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('info'); expect(request.message.msg).to.equal('Hello'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message using type set by route', function() { + + describe('success with flash message using type set by route', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { type: 'info', message: 'Hello' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { type: 'ok' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { type: 'ok' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('ok'); expect(request.message.msg).to.equal('Hello'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message overridden by route as string', function() { + + describe('success with flash message overridden by route as string', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { type: 'info', message: 'Hello' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: 'Success!', - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: 'Success!', + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('success'); expect(request.message.msg).to.equal('Success!'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message overridden by route using options', function() { + + describe('success with flash message overridden by route using options', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { type: 'info', message: 'Hello' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { message: 'Okay' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { message: 'Okay' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('success'); expect(request.message.msg).to.equal('Okay'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message overridden by route using options with type', function() { + + describe('success with flash message overridden by route using options with type', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { type: 'info', message: 'Hello' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { type: 'warn', message: 'Last login from far away place' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { type: 'warn', message: 'Last login from far away place' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('warn'); expect(request.message.msg).to.equal('Last login from far away place'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - }); - - - describe('using strategy that specifies message as string', function() { - - describe('success with flash message', function() { + + + describe('using strategy that specifies message as string', () => { + describe('success with flash message', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, 'Greetings'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: true, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: true, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('success'); expect(request.message.msg).to.equal('Greetings'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message using type set by route', function() { + + describe('success with flash message using type set by route', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, 'Greetings'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { type: 'info' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { type: 'info' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('info'); expect(request.message.msg).to.equal('Greetings'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message overridden by route as string', function() { + + describe('success with flash message overridden by route as string', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, 'Greetings'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: 'Login complete', - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: 'Login complete', + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('success'); expect(request.message.msg).to.equal('Login complete'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message overridden by route using options', function() { + + describe('success with flash message overridden by route using options', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, 'Greetings'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { message: 'OK' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { message: 'OK' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('success'); expect(request.message.msg).to.equal('OK'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message overridden by route using options with type', function() { + + describe('success with flash message overridden by route using options with type', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, 'Greetings'); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { type: 'notice', message: 'Last login was yesterday' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { type: 'notice', message: 'Last login was yesterday' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('notice'); expect(request.message.msg).to.equal('Last login was yesterday'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - }); - - - describe('using strategy that does not specify message', function() { - - describe('success with flash message left up to strategy', function() { + + + describe('using strategy that does not specify message', () => { + describe('success with flash message left up to strategy', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: true, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: true, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should not flash message', function() { + + it('should not flash message', () => { + // eslint-disable-next-line no-unused-expressions expect(request.message).to.be.undefined; }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message left up to strategy using type set by route', function() { + + describe('success with flash message left up to strategy using type set by route', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { type: 'info' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { type: 'info' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should not flash message', function() { + + it('should not flash message', () => { + // eslint-disable-next-line no-unused-expressions expect(request.message).to.be.undefined; }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message specified by route as string', function() { + + describe('success with flash message specified by route as string', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: 'Login complete', - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: 'Login complete', + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('success'); expect(request.message.msg).to.equal('Login complete'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message specified by route using options', function() { + + describe('success with flash message specified by route using options', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { message: 'OK' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { message: 'OK' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('success'); expect(request.message.msg).to.equal('OK'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with flash message specified by route using options with type', function() { + + describe('success with flash message specified by route using options with type', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successFlash: { type: 'notice', message: 'Last login was yesterday' }, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successFlash: { type: 'notice', message: 'Last login was yesterday' }, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; - req.flash = function(type, msg) { - this.message = { type: type, msg: msg }; + req.flash = function flash(type, msg) { + this.message = { type, msg }; }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should flash message', function() { + + it('should flash message', () => { expect(request.message.type).to.equal('notice'); expect(request.message.msg).to.equal('Last login was yesterday'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - }); - }); diff --git a/test/middleware/authenticate.success.info.test.js b/test/middleware/authenticate.success.info.test.js index 9653e4dc..bf8d8fb7 100644 --- a/test/middleware/authenticate.success.info.test.js +++ b/test/middleware/authenticate.success.info.test.js @@ -1,105 +1,110 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - describe('success with info', function() { + +describe('middleware/authenticate', () => { + describe('success with info', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { clientId: '123', scope: 'read' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, 'success')) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should set authInfo', function() { + + it('should set authInfo', () => { expect(request.authInfo).to.be.an('object'); expect(Object.keys(request.authInfo)).to.have.length(2); expect(request.authInfo.clientId).to.equal('123'); expect(request.authInfo.scope).to.equal('read'); }); }); - - describe('success with info that is transformed', function() { + + describe('success with info that is transformed', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { clientId: '123', scope: 'read' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - passport.transformAuthInfo(function(info, done) { + passport.transformAuthInfo((info, done) => { done(null, { clientId: info.clientId, client: { name: 'Foo' }, scope: info.scope }); }); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, 'success')) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should set authInfo', function() { + + it('should set authInfo', () => { expect(request.authInfo).to.be.an('object'); expect(Object.keys(request.authInfo)).to.have.length(3); expect(request.authInfo.clientId).to.equal('123'); @@ -107,99 +112,103 @@ describe('middleware/authenticate', function() { expect(request.authInfo.scope).to.equal('read'); }); }); - - describe('success with info, but transform that encounters an error', function() { + + describe('success with info, but transform that encounters an error', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { clientId: '123', scope: 'read' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - passport.transformAuthInfo(function(info, done) { + passport.transformAuthInfo((info, done) => { done(new Error('something went wrong')); }); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, 'success')) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something went wrong'); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should not set authInfo', function() { + + it('should not set authInfo', () => { + // eslint-disable-next-line no-unused-expressions expect(request.authInfo).to.be.undefined; }); }); - - describe('success with info, but option that disables info', function() { + + describe('success with info, but option that disables info', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { clientId: '123', scope: 'read' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, 'success', { authInfo: false })) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should not set authInfo', function() { + + it('should not set authInfo', () => { + // eslint-disable-next-line no-unused-expressions expect(request.authInfo).to.be.undefined; }); }); - }); diff --git a/test/middleware/authenticate.success.message.test.js b/test/middleware/authenticate.success.message.test.js index b65e2a52..d9d84258 100644 --- a/test/middleware/authenticate.success.message.test.js +++ b/test/middleware/authenticate.success.message.test.js @@ -1,208 +1,220 @@ /* global describe, it, expect, before */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - describe('success with message set by route', function() { + +describe('middleware/authenticate', () => { + describe('success with message set by route', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { message: 'Welcome!' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successMessage: 'Login complete', - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successMessage: 'Login complete', + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should add message to session', function() { + + it('should add message to session', () => { expect(request.session.messages).to.have.length(1); expect(request.session.messages[0]).to.equal('Login complete'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with message set by route that is added to messages', function() { + + describe('success with message set by route that is added to messages', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { message: 'Welcome!' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successMessage: 'Login complete', - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successMessage: 'Login complete', + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - req.session.messages = [ 'I exist!' ]; - - req.logIn = function(user, options, done) { + req.session.messages = ['I exist!']; + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should add message to session', function() { + + it('should add message to session', () => { expect(request.session.messages).to.have.length(2); expect(request.session.messages[0]).to.equal('I exist!'); expect(request.session.messages[1]).to.equal('Login complete'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with message set by strategy', function() { + + describe('success with message set by strategy', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { message: 'Welcome!' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successMessage: true, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successMessage: true, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should add message to session', function() { + + it('should add message to session', () => { expect(request.session.messages).to.have.length(1); expect(request.session.messages[0]).to.equal('Welcome!'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with message set by strategy with extra info', function() { + + describe('success with message set by strategy with extra info', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user, { message: 'Welcome!', scope: 'read' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { - chai.connect.use('express', authenticate(passport, 'success', { successMessage: true, - successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + let request; + let response; + + before((done) => { + chai.connect.use('express', authenticate(passport, 'success', { + successMessage: true, + successRedirect: 'http://www.example.com/account', + })) + .req((req) => { request = req; req.session = {}; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should add message to session', function() { + + it('should add message to session', () => { expect(request.session.messages).to.have.length(1); expect(request.session.messages[0]).to.equal('Welcome!'); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - }); diff --git a/test/middleware/authenticate.success.multi.test.js b/test/middleware/authenticate.success.multi.test.js index 630c188e..5811f602 100644 --- a/test/middleware/authenticate.success.multi.test.js +++ b/test/middleware/authenticate.success.multi.test.js @@ -1,103 +1,107 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - describe('with multiple strategies, the first of which succeeds', function() { + +describe('middleware/authenticate', () => { + describe('with multiple strategies, the first of which succeeds', () => { function StrategyA() { } - StrategyA.prototype.authenticate = function(req) { + StrategyA.prototype.authenticate = function authenticate() { this.success({ username: 'bob-a' }); }; - + function StrategyB() { } - StrategyB.prototype.authenticate = function(req) { + StrategyB.prototype.authenticate = function authenticate() { this.success({ username: 'bob-b' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('a', new StrategyA()); passport.use('b', new StrategyB()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, ['a', 'b'])) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.username).to.equal('bob-a'); }); }); - - describe('with multiple strategies, the second of which succeeds', function() { + + describe('with multiple strategies, the second of which succeeds', () => { function StrategyA() { } - StrategyA.prototype.authenticate = function(req) { + StrategyA.prototype.authenticate = function authenticate() { this.fail('A challenge'); }; - + function StrategyB() { } - StrategyB.prototype.authenticate = function(req) { + StrategyB.prototype.authenticate = function authenticate() { this.success({ username: 'bob-b' }); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('a', new StrategyA()); passport.use('b', new StrategyB()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, ['a', 'b'])) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.username).to.equal('bob-b'); }); }); - }); diff --git a/test/middleware/authenticate.success.test.js b/test/middleware/authenticate.success.test.js index 3216b678..d86a66df 100644 --- a/test/middleware/authenticate.success.test.js +++ b/test/middleware/authenticate.success.test.js @@ -1,346 +1,363 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ -describe('middleware/authenticate', function() { - - describe('success', function() { +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; + + +describe('middleware/authenticate', () => { + describe('success', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, 'success')) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should set authInfo', function() { + + it('should set authInfo', () => { expect(request.authInfo).to.be.an('object'); expect(Object.keys(request.authInfo)).to.have.length(0); }); }); - - describe('success that assigns a specific property', function() { + + describe('success that assigns a specific property', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, 'success', { assignProperty: 'account' })) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should set account', function() { + + it('should set account', () => { expect(request.account).to.be.an('object'); expect(request.account.id).to.equal('1'); expect(request.account.username).to.equal('jaredhanson'); }); - - it('should not set authInfo', function() { + + it('should not set authInfo', () => { + // eslint-disable-next-line no-unused-expressions expect(request.authInfo).to.be.undefined; }); }); - - describe('success with strategy-specific options', function() { + + describe('success with strategy-specific options', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; - if (options.scope == 'email') { + Strategy.prototype.authenticate = function authenticate(req, options) { + const user = { id: '1', username: 'jaredhanson' }; + if (options.scope === 'email') { user.email = 'jaredhanson@example.com'; } this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, 'success', { scope: 'email' })) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { - if (options.scope != 'email') { return done(new Error('invalid options')); } + + // eslint-disable-next-line consistent-return + req.logIn = function logIn(user, options, done) { + if (options.scope !== 'email') { return done(new Error('invalid options')); } this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); expect(request.user.email).to.equal('jaredhanson@example.com'); }); - - it('should set authInfo', function() { + + it('should set authInfo', () => { expect(request.authInfo).to.be.an('object'); expect(Object.keys(request.authInfo)).to.have.length(0); }); }); - - describe('success with redirect', function() { + + describe('success with redirect', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { + let request; + let response; + + before((done) => { chai.connect.use('express', authenticate(passport, 'success', { successRedirect: 'http://www.example.com/account' })) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should set authInfo', function() { + + it('should set authInfo', () => { expect(request.authInfo).to.be.an('object'); expect(Object.keys(request.authInfo)).to.have.length(0); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/account'); }); }); - - describe('success with return to previous location', function() { + + describe('success with return to previous location', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { + let request; + let response; + + before((done) => { chai.connect.use('express', authenticate(passport, 'success', { successReturnToOrRedirect: 'http://www.example.com/default' })) - .req(function(req) { + .req((req) => { request = req; req.session = { returnTo: 'http://www.example.com/return' }; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should set authInfo', function() { + + it('should set authInfo', () => { expect(request.authInfo).to.be.an('object'); expect(Object.keys(request.authInfo)).to.have.length(0); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/return'); }); - - it('should move return to from session', function() { + + it('should move return to from session', () => { + // eslint-disable-next-line no-unused-expressions expect(request.session.returnTo).to.be.undefined; }); }); - - describe('success with return to default location', function() { + + describe('success with return to default location', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req, options) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, response; - before(function(done) { + let request; + let response; + + before((done) => { chai.connect.use('express', authenticate(passport, 'success', { successReturnToOrRedirect: 'http://www.example.com/default' })) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .end(function(res) { + .end((res) => { response = res; done(); }) .dispatch(); }); - - it('should set user', function() { + + it('should set user', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('1'); expect(request.user.username).to.equal('jaredhanson'); }); - - it('should set authInfo', function() { + + it('should set authInfo', () => { expect(request.authInfo).to.be.an('object'); expect(Object.keys(request.authInfo)).to.have.length(0); }); - - it('should redirect', function() { + + it('should redirect', () => { expect(response.statusCode).to.equal(302); expect(response.getHeader('Location')).to.equal('http://www.example.com/default'); }); }); - - describe('success, but login that encounters an error', function() { + + describe('success, but login that encounters an error', () => { function Strategy() { } - Strategy.prototype.authenticate = function(req) { - var user = { id: '1', username: 'jaredhanson' }; + Strategy.prototype.authenticate = function authenticate() { + const user = { id: '1', username: 'jaredhanson' }; this.success(user); }; - - var passport = new Passport(); + + const passport = new Passport(); passport.use('success', new Strategy()); - - var request, error; - before(function(done) { + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, 'success')) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { done(new Error('something went wrong')); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something went wrong'); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set authInfo', function() { + + it('should not set authInfo', () => { + // eslint-disable-next-line no-unused-expressions expect(request.authInfo).to.be.undefined; }); }); - }); diff --git a/test/middleware/authenticate.test.js b/test/middleware/authenticate.test.js index 702bab6b..8b393adf 100644 --- a/test/middleware/authenticate.test.js +++ b/test/middleware/authenticate.test.js @@ -1,51 +1,54 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , authenticate = require('../../lib/middleware/authenticate') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const authenticate = require('../../lib/middleware/authenticate'); +const Passport = require('../..').Passport; -describe('middleware/authenticate', function() { - - it('should be named authenticate', function() { + +describe('middleware/authenticate', () => { + it('should be named authenticate', () => { expect(authenticate().name).to.equal('authenticate'); }); - - describe('with unknown strategy', function() { - var passport = new Passport(); - - var request, error; - before(function(done) { + describe('with unknown strategy', () => { + const passport = new Passport(); + + let request; + let error; + + before((done) => { chai.connect.use(authenticate(passport, 'foo')) - .req(function(req) { + .req((req) => { request = req; - - req.logIn = function(user, options, done) { + + req.logIn = function logIn(user, options, done) { this.user = user; done(); }; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('Unknown authentication strategy "foo"'); }); - - it('should not set user', function() { + + it('should not set user', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should not set authInfo', function() { + + it('should not set authInfo', () => { + // eslint-disable-next-line no-unused-expressions expect(request.authInfo).to.be.undefined; }); }); - }); diff --git a/test/middleware/initialize.test.js b/test/middleware/initialize.test.js index 073c4d0e..a2eca710 100644 --- a/test/middleware/initialize.test.js +++ b/test/middleware/initialize.test.js @@ -1,170 +1,180 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , initialize = require('../../lib/middleware/initialize') - , Passport = require('../..').Passport; +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const Passport = require('../..').Passport; +const initialize = require('../../lib/middleware/initialize'); -describe('middleware/initialize', function() { - - it('should be named initialize', function() { +describe('middleware/initialize', () => { + it('should be named initialize', () => { expect(initialize().name).to.equal('initialize'); }); - - describe('handling a request without a session', function() { - var passport = new Passport(); - var request, error; - before(function(done) { + describe('handling a request without a session', () => { + const passport = new Passport(); + let request; + let error; + + before((done) => { chai.connect.use(initialize(passport)) - .req(function(req) { + .req((req) => { request = req; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should expose authenticator on internal request property', function() { + + it('should expose authenticator on internal request property', () => { expect(request._passport).to.be.an('object'); expect(request._passport.instance).to.be.an.instanceOf(Passport); expect(request._passport.instance).to.equal(passport); }); - - it('should not expose empty object as session storage on internal request property', function() { + + it('should not expose empty object as session storage on internal request property', () => { + // eslint-disable-next-line no-unused-expressions expect(request._passport.session).to.be.undefined; }); }); - - describe('handling a request with a new session', function() { - var passport = new Passport(); - var request, error; - before(function(done) { + describe('handling a request with a new session', () => { + const passport = new Passport(); + let request; + let error; + + before((done) => { chai.connect.use(initialize(passport)) - .req(function(req) { + .req((req) => { request = req; - + req.session = {}; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should not initialize namespace within session', function() { + + it('should not initialize namespace within session', () => { + // eslint-disable-next-line no-unused-expressions expect(request.session.passport).to.be.undefined; }); - - it('should expose authenticator on internal request property', function() { + + it('should expose authenticator on internal request property', () => { expect(request._passport).to.be.an('object'); expect(request._passport.instance).to.be.an.instanceOf(Passport); expect(request._passport.instance).to.equal(passport); }); - - it('should not expose session storage on internal request property', function() { + + it('should not expose session storage on internal request property', () => { + // eslint-disable-next-line no-unused-expressions expect(request._passport.session).to.be.undefined; }); }); - - describe('handling a request with an existing session', function() { - var passport = new Passport(); - var request, error; - before(function(done) { + describe('handling a request with an existing session', () => { + const passport = new Passport(); + let request; + let error; + + before((done) => { chai.connect.use(initialize(passport)) - .req(function(req) { + .req((req) => { request = req; - + req.session = {}; req.session.passport = {}; req.session.passport.user = '123456'; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should maintain data within session', function() { + + it('should maintain data within session', () => { expect(request.session.passport).to.be.an('object'); expect(Object.keys(request.session.passport)).to.have.length(1); expect(request.session.passport.user).to.equal('123456'); }); - - it('should expose authenticator on internal request property', function() { + + it('should expose authenticator on internal request property', () => { expect(request._passport).to.be.an('object'); expect(request._passport.instance).to.be.an.instanceOf(Passport); expect(request._passport.instance).to.equal(passport); }); - - it('should expose session storage on internal request property', function() { + + it('should expose session storage on internal request property', () => { expect(request._passport.session).to.be.an('object'); expect(Object.keys(request._passport.session)).to.have.length(1); expect(request._passport.session.user).to.equal('123456'); }); }); - - describe('handling a request with an existing session using custom session key', function() { - var passport = new Passport(); + + describe('handling a request with an existing session using custom session key', () => { + const passport = new Passport(); passport._key = 'authentication'; - var request, error; + let request; + let error; - before(function(done) { + before((done) => { chai.connect.use(initialize(passport)) - .req(function(req) { + .req((req) => { request = req; - + req.session = {}; req.session.authentication = {}; req.session.authentication.user = '123456'; }) - .next(function(err) { + .next((err) => { error = err; done(); }) .dispatch(); }); - - it('should not error', function() { + + it('should not error', () => { + // eslint-disable-next-line no-unused-expressions expect(error).to.be.undefined; }); - - it('should maintain data within session', function() { + + it('should maintain data within session', () => { expect(request.session.authentication).to.be.an('object'); expect(Object.keys(request.session.authentication)).to.have.length(1); expect(request.session.authentication.user).to.equal('123456'); }); - - it('should expose authenticator on internal request property', function() { + + it('should expose authenticator on internal request property', () => { expect(request._passport).to.be.an('object'); expect(request._passport.instance).to.be.an.instanceOf(Passport); expect(request._passport.instance).to.equal(passport); }); - - it('should expose session storage on internal request property', function() { + + it('should expose session storage on internal request property', () => { expect(request._passport.session).to.be.an('object'); expect(Object.keys(request._passport.session)).to.have.length(1); expect(request._passport.session.user).to.equal('123456'); }); }); - }); diff --git a/test/package.test.js b/test/package.test.js index c34a516c..ea7dfd5e 100644 --- a/test/package.test.js +++ b/test/package.test.js @@ -1,22 +1,20 @@ /* global describe, it, expect */ -var passport = require('..'); +const passport = require('..'); -describe('passport', function() { - - it('should expose singleton authenticator', function() { +describe('passport', () => { + it('should expose singleton authenticator', () => { expect(passport).to.be.an('object'); expect(passport).to.be.an.instanceOf(passport.Authenticator); }); - - it('should export constructors', function() { + + it('should export constructors', () => { expect(passport.Authenticator).to.equal(passport.Passport); expect(passport.Authenticator).to.be.a('function'); expect(passport.Strategy).to.be.a('function'); }); - - it('should export strategies', function() { + + it('should export strategies', () => { expect(passport.strategies.SessionStrategy).to.be.a('function'); }); - }); diff --git a/test/strategies/session.test.js b/test/strategies/session.test.js index 366a2b80..2a210972 100644 --- a/test/strategies/session.test.js +++ b/test/strategies/session.test.js @@ -1,61 +1,65 @@ /* global describe, it, expect, before */ /* jshint expr: true */ -var chai = require('chai') - , SessionStrategy = require('../../lib/strategies/session'); +/* eslint-disable camelcase, no-proto, no-shadow */ +const chai = require('chai'); +const SessionStrategy = require('../../lib/strategies/session'); -describe('SessionStrategy', function() { - - var strategy = new SessionStrategy(); - - it('should be named session', function() { +describe('SessionStrategy', () => { + const strategy = new SessionStrategy(); + + it('should be named session', () => { expect(strategy.name).to.equal('session'); }); - - describe('handling a request without a login session', function() { - var request, pass = false; - - before(function(done) { + + describe('handling a request without a login session', () => { + let request; + let pass = false; + + before((done) => { chai.passport.use(strategy) - .pass(function() { + .pass(() => { pass = true; done(); }) - .req(function(req) { + .req((req) => { request = req; - + req._passport = {}; req._passport.session = {}; }) .authenticate(); }); - - it('should pass', function() { + + it('should pass', () => { + // eslint-disable-next-line no-unused-expressions expect(pass).to.be.true; }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - - describe('handling a request with a login session', function() { - var strategy = new SessionStrategy(function(user, req, done) { + + describe('handling a request with a login session', () => { + const strategy = new SessionStrategy(((user, req, done) => { done(null, { id: user }); - }); - - var request, pass = false; - - before(function(done) { + })); + + let request; + let pass = false; + + before((done) => { chai.passport.use(strategy) - .pass(function() { + .pass(() => { pass = true; done(); }) - .req(function(req) { + .req((req) => { request = req; - + req._passport = {}; req._passport.instance = {}; req._passport.session = {}; @@ -63,38 +67,42 @@ describe('SessionStrategy', function() { }) .authenticate(); }); - - it('should pass', function() { + + it('should pass', () => { + // eslint-disable-next-line no-unused-expressions expect(pass).to.be.true; }); - - it('should set user on request', function() { + + it('should set user on request', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal('123456'); }); - - it('should maintain session', function() { + + it('should maintain session', () => { + // eslint-disable-next-line no-underscore-dangle expect(request._passport.session).to.be.an('object'); + // eslint-disable-next-line no-underscore-dangle expect(request._passport.session.user).to.equal('123456'); }); }); - - describe('handling a request with a login session serialized to 0', function() { - var strategy = new SessionStrategy(function(user, req, done) { + + describe('handling a request with a login session serialized to 0', () => { + const strategy = new SessionStrategy(((user, req, done) => { done(null, { id: user }); - }); - - var request, pass = false; - - before(function(done) { + })); + + let request; + let pass = false; + + before((done) => { chai.passport.use(strategy) - .pass(function() { + .pass(() => { pass = true; done(); }) - .req(function(req) { + .req((req) => { request = req; - + req._passport = {}; req._passport.instance = {}; req._passport.session = {}; @@ -102,38 +110,40 @@ describe('SessionStrategy', function() { }) .authenticate(); }); - - it('should pass', function() { + + it('should pass', () => { + // eslint-disable-next-line no-unused-expressions expect(pass).to.be.true; }); - - it('should set user on request', function() { + + it('should set user on request', () => { expect(request.user).to.be.an('object'); expect(request.user.id).to.equal(0); }); - - it('should maintain session', function() { + + it('should maintain session', () => { expect(request._passport.session).to.be.an('object'); expect(request._passport.session.user).to.equal(0); }); }); - - describe('handling a request with a login session that has been invalidated', function() { - var strategy = new SessionStrategy(function(user, req, done) { + + describe('handling a request with a login session that has been invalidated', () => { + const strategy = new SessionStrategy(((user, req, done) => { done(null, false); - }); - - var request, pass = false; - - before(function(done) { + })); + + let request; + let pass = false; + + before((done) => { chai.passport.use(strategy) - .pass(function() { + .pass(() => { pass = true; done(); }) - .req(function(req) { + .req((req) => { request = req; - + req._passport = {}; req._passport.instance = {}; req._passport.session = {}; @@ -141,37 +151,42 @@ describe('SessionStrategy', function() { }) .authenticate(); }); - - it('should pass', function() { + + it('should pass', () => { + // eslint-disable-next-line no-unused-expressions expect(pass).to.be.true; }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should remove user from session', function() { + + it('should remove user from session', () => { expect(request._passport.session).to.be.an('object'); + // eslint-disable-next-line no-unused-expressions expect(request._passport.session.user).to.be.undefined; }); }); - - describe('handling a request with a login session and setting custom user property', function() { - var strategy = new SessionStrategy(function(user, req, done) { + + describe('handling a request with a login session and setting custom user property', () => { + const strategy = new SessionStrategy(((user, req, done) => { done(null, { id: user }); - }); - - var request, pass = false; - - before(function(done) { + })); + + let request; + let pass = false; + + before((done) => { chai.passport.use(strategy) - .pass(function() { + .pass(() => { pass = true; done(); }) - .req(function(req) { + .req((req) => { request = req; - + + // eslint-disable-next-line no-underscore-dangle req._passport = {}; req._passport.instance = {}; req._passport.instance._userProperty = 'currentUser'; @@ -180,37 +195,40 @@ describe('SessionStrategy', function() { }) .authenticate(); }); - - it('should pass', function() { + + it('should pass', () => { + // eslint-disable-next-line no-unused-expressions expect(pass).to.be.true; }); - - it('should not set "user" on request', function() { + + it('should not set "user" on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should set "currentUser" on request', function() { + + it('should set "currentUser" on request', () => { expect(request.currentUser).to.be.an('object'); expect(request.currentUser.id).to.equal('123456'); }); }); - - describe('handling a request with a login session that encounters an error when deserializing', function() { - var strategy = new SessionStrategy(function(user, req, done) { + + describe('handling a request with a login session that encounters an error when deserializing', () => { + const strategy = new SessionStrategy(((user, req, done) => { done(new Error('something went wrong')); - }); - - var request, error; - - before(function(done) { + })); + + let request; + let error; + + before((done) => { chai.passport.use(strategy) - .error(function(err) { + .error((err) => { error = err; done(); }) - .req(function(req) { + .req((req) => { request = req; - + req._passport = {}; req._passport.instance = {}; req._passport.session = {}; @@ -218,45 +236,47 @@ describe('SessionStrategy', function() { }) .authenticate(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('something went wrong'); }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); - - it('should maintain session', function() { + + it('should maintain session', () => { expect(request._passport.session).to.be.an('object'); expect(request._passport.session.user).to.equal('123456'); }); }); - - describe('handling a request that lacks an authenticator', function() { - var request, error; - - before(function(done) { + + describe('handling a request that lacks an authenticator', () => { + let request; + let error; + + before((done) => { chai.passport.use(strategy) - .error(function(err) { + .error((err) => { error = err; done(); }) - .req(function(req) { + .req((req) => { request = req; }) .authenticate(); }); - - it('should error', function() { + + it('should error', () => { expect(error).to.be.an.instanceOf(Error); expect(error.message).to.equal('passport.initialize() middleware not in use'); }); - - it('should not set user on request', function() { + + it('should not set user on request', () => { + // eslint-disable-next-line no-unused-expressions expect(request.user).to.be.undefined; }); }); - });