Permalink
Browse files

converting over to semistandard from jshint (#371)

  • Loading branch information...
1 parent af8b590 commit 0d1653fabd9745dd7b703c6acd2d65a734a44b0e @ekryski ekryski committed on GitHub Dec 14, 2016
Showing with 174 additions and 180 deletions.
  1. +0 −34 .jshintrc
  2. +2 −2 example/app.js
  3. +9 −2 package.json
  4. +2 −2 src/express/authenticate.js
  5. +3 −3 src/express/emit-events.js
  6. +1 −1 src/express/expose-cookies.js
  7. +1 −1 src/express/expose-headers.js
  8. +3 −3 src/express/failure-redirect.js
  9. +4 −4 src/express/set-cookie.js
  10. +2 −2 src/express/success-redirect.js
  11. +6 −5 src/hooks/authenticate.js
  12. +5 −5 src/index.js
  13. +2 −2 src/options.js
  14. +6 −8 src/passport/authenticate.js
  15. +1 −1 src/passport/index.js
  16. +3 −3 src/passport/initialize.js
  17. +5 −5 src/service.js
  18. +6 −6 src/socket/handler.js
  19. +5 −5 src/socket/index.js
  20. +3 −3 src/utils.js
  21. +1 −1 test/express/authenticate.test.js
  22. +1 −1 test/express/emit-events.test.js
  23. +2 −6 test/express/expose-cookies.test.js
  24. +2 −6 test/express/expose-headers.test.js
  25. +1 −1 test/express/failure-redirect.test.js
  26. +1 −1 test/express/index.test.js
  27. +1 −1 test/express/set-cookie.test.js
  28. +1 −1 test/express/success-redirect.test.js
  29. +4 −4 test/fixtures/server.js
  30. +3 −3 test/fixtures/strategy.js
  31. +5 −5 test/hooks/authenticate.test.js
  32. +1 −1 test/hooks/index.test.js
  33. +2 −2 test/index.test.js
  34. +26 −11 test/integration/primus.test.js
  35. +18 −18 test/integration/rest.test.js
  36. +26 −10 test/integration/socketio.test.js
  37. +1 −1 test/options.test.js
  38. +3 −3 test/passport/authenticate.test.js
  39. +1 −1 test/passport/index.test.js
  40. +1 −1 test/passport/initialize.test.js
  41. +2 −2 test/service.test.js
  42. +1 −2 test/socket/index.test.js
  43. +1 −1 test/utils.test.js
View
@@ -1,34 +0,0 @@
-{
- "node": true,
- "esnext": true,
- "bitwise": true,
- "camelcase": true,
- "curly": true,
- "eqeqeq": true,
- "immed": true,
- "indent": 2,
- "latedef": "nofunc",
- "newcap": false,
- "noarg": true,
- "quotmark": "single",
- "regexp": true,
- "undef": true,
- "unused": false,
- "strict": false,
- "trailing": true,
- "smarttabs": true,
- "white": false,
- "node": true,
- "expr": true,
- "globals": {
- "window": true,
- "it": true,
- "describe": true,
- "before": true,
- "beforeEach": true,
- "after": true,
- "afterEach": true,
- "document": true,
- "localStorage": true
- }
-}
View
@@ -1,10 +1,10 @@
+const path = require('path');
const feathers = require('feathers');
const rest = require('feathers-rest');
const socketio = require('feathers-socketio');
const hooks = require('feathers-hooks');
const memory = require('feathers-memory');
const bodyParser = require('body-parser');
-const errors = require('feathers-errors');
const errorHandler = require('feathers-errors/handler');
const local = require('feathers-authentication-local');
const jwt = require('feathers-authentication-jwt');
@@ -20,7 +20,7 @@ app.configure(rest())
.configure(local())
.configure(jwt())
.use('/users', memory())
- .use('/', feathers.static(__dirname + '/public'));
+ .use('/', feathers.static(path.resolve(__dirname, '/public')));
app.service('authentication').hooks({
before: {
View
@@ -35,11 +35,17 @@
"release:pre": "npm publish --tag next",
"compile": "rimraf -rf lib/ && babel -d lib/ src/",
"watch": "babel --watch -d lib/ src/",
- "jshint": "jshint src/. test/. --config",
+ "lint": "semistandard --fix",
"mocha": "mocha --opts mocha.opts",
- "test": "npm run compile && npm run jshint && npm run coverage && nsp check",
+ "test": "npm run compile && npm run lint && npm run coverage && nsp check",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- --opts mocha.opts"
},
+ "semistandard": {
+ "sourceType": "module",
+ "env": [
+ "mocha"
+ ]
+ },
"directories": {
"lib": "lib"
},
@@ -81,6 +87,7 @@
"rimraf": "^2.5.4",
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0",
+ "semistandard": "^9.1.0",
"socket.io-client": "^1.4.8",
"superagent": "^3.0.0",
"ws": "^1.1.1"
@@ -37,7 +37,7 @@ export default function authenticate (strategy, options = {}) {
return next();
}
- if (result.fail) {
+ if (result.fail) {
if (options.failureRedirect) {
debug(`Redirecting to ${options.failureRedirect}`);
res.status(302);
@@ -65,4 +65,4 @@ export default function authenticate (strategy, options = {}) {
next();
}).catch(next);
};
-}
+}
@@ -2,8 +2,8 @@ import Debug from 'debug';
const debug = Debug('feathers-authentication:express:emit-events');
-export default function emitEvents() {
- return function(req, res, next) {
+export default function emitEvents () {
+ return function (req, res, next) {
const method = res.hook && res.hook.method;
let event = null;
@@ -25,7 +25,7 @@ export default function emitEvents() {
res
});
}
-
+
next();
};
}
@@ -4,7 +4,7 @@ const debug = Debug('feathers-authentication:express:expose-cookies');
export default function () {
debug('Registering exposeCookies middleware');
- return function exposeCookies(req, res, next) {
+ return function exposeCookies (req, res, next) {
debug('Exposing Express cookies to hooks and services', req.cookies);
req.feathers.cookies = req.cookies;
next();
@@ -4,7 +4,7 @@ const debug = Debug('feathers-authentication:express:expose-headers');
export default function () {
debug('Registering exposeHeaders middleware');
- return function exposeHeaders(req, res, next) {
+ return function exposeHeaders (req, res, next) {
debug('Exposing Express headers to hooks and services');
req.feathers.headers = req.headers;
next();
@@ -1,10 +1,10 @@
import Debug from 'debug';
const debug = Debug('feathers-authentication:middleware:failure-redirect');
-export default function failureRedirect(options = {}) {
+export default function failureRedirect (options = {}) {
debug('Registering failureRedirect middleware');
- return function(error, req, res, next) {
+ return function (error, req, res, next) {
if (options.cookie && options.cookie.enabled) {
debug(`Clearing old '${options.cookie.name}' cookie`);
res.clearCookie(options.cookie.name);
@@ -13,7 +13,7 @@ export default function failureRedirect(options = {}) {
if (res.hook && res.hook.data && res.hook.data.__redirect) {
const { url, status } = res.hook.data.__redirect;
debug(`Redirecting to ${url} after failed authentication.`);
-
+
res.status(status || 302);
return res.redirect(url);
}
@@ -4,14 +4,14 @@ import ms from 'ms';
const debug = Debug('feathers-authentication:middleware:set-cookie');
-export default function setCookie(authOptions = {}) {
+export default function setCookie (authOptions = {}) {
debug('Registering setCookie middleware');
- function makeExpiry(timeframe){
+ function makeExpiry (timeframe) {
return new Date(Date.now() + ms(timeframe));
}
- return function(req, res, next) {
+ return function (req, res, next) {
const app = req.app;
const options = authOptions.cookie || {};
@@ -31,7 +31,7 @@ export default function setCookie(authOptions = {}) {
debug(`Clearing old '${cookie}' cookie`);
res.clearCookie(cookie);
-
+
// Only set the cookie if we weren't removing the token and we
// have a JWT access token.
if (!res.hook || (res.hook && res.hook.method !== 'remove') && res.data && res.data.accessToken) {
@@ -1,10 +1,10 @@
import Debug from 'debug';
const debug = Debug('feathers-authentication:middleware:success-redirect');
-export default function successRedirect() {
+export default function successRedirect () {
debug('Registering successRedirect middleware');
- return function(req, res, next) {
+ return function (req, res, next) {
if (res.hook && res.hook.data && res.hook.data.__redirect) {
const { url, status } = res.hook.data.__redirect;
debug(`Redirecting to ${url} after successful authentication.`);
@@ -3,8 +3,6 @@ import Debug from 'debug';
const debug = Debug('feathers-authentication:hooks:authenticate');
export default function authenticate (strategy, options = {}) {
- // TODO (EK): Handle chaining multiple strategies
-
if (!strategy) {
throw new Error(`The 'authenticate' hook requires one of your registered passport strategies.`);
}
@@ -21,10 +19,11 @@ export default function authenticate (strategy, options = {}) {
return Promise.reject(new Error(`The 'authenticate' hook should only be used as a 'before' hook.`));
}
+ // NOTE (EK): Bring this in when we decide to make the strategy required by the client
// if (!hook.app.passport._strategy(strategy)) {
// return Promise.reject(new Error(`Your '${strategy}' authentication strategy is not registered with passport.`));
// }
-
+
// NOTE (EK): Passport expects an express/connect
// like request object. So we need to create on.
let request = {
@@ -36,6 +35,8 @@ export default function authenticate (strategy, options = {}) {
session: {}
};
+ debug(`Attempting to authenticate using ${strategy} strategy with options`, options);
+
return app.authenticate(strategy, options)(request).then((result = {}) => {
if (result.fail) {
// TODO (EK): Reject with something...
@@ -52,7 +53,7 @@ export default function authenticate (strategy, options = {}) {
if (options.failureMessage) {
message = options.failureMessage;
}
-
+
return Promise.reject(new errors[status](message, challenge));
}
@@ -72,4 +73,4 @@ export default function authenticate (strategy, options = {}) {
return Promise.resolve(hook);
});
};
-}
+}
View
@@ -9,8 +9,8 @@ import socket from './socket';
const debug = Debug('feathers-authentication:index');
-export default function init(config = {}) {
- return function authentication() {
+export default function init (config = {}) {
+ return function authentication () {
const app = this;
const _super = app.setup;
// Merge and flatten options
@@ -21,7 +21,7 @@ export default function init(config = {}) {
}
if (!options.secret) {
- throw new Error (`You must provide a 'secret' in your authentication configuration`);
+ throw new Error(`You must provide a 'secret' in your authentication configuration`);
}
// Make sure cookies don't have to be sent over HTTPS
@@ -32,7 +32,7 @@ export default function init(config = {}) {
app.set('auth', options);
- debug('Setting up Passport');
+ debug('Setting up Passport');
// Set up our framework adapter
passport.framework(adapter.call(app, options));
// Expose passport on the app object
@@ -53,7 +53,7 @@ export default function init(config = {}) {
app.configure(service(options));
app.passport.initialize();
- app.setup = function() {
+ app.setup = function () {
let result = _super.apply(this, arguments);
// Socket.io middleware
View
@@ -23,6 +23,6 @@ const defaults = {
}
};
-export default function(... otherOptions) {
- return merge({}, defaults, ... otherOptions);
+export default function (...otherOptions) {
+ return merge({}, defaults, ...otherOptions);
}
@@ -8,18 +8,16 @@ import makeDebug from 'debug';
const debug = makeDebug('feathers-authentication:passport:authenticate');
export default function authenticate (options = {}) {
- const app = this;
-
debug('Initializing custom passport authenticate', options);
// This function is bound by passport and called by passport.authenticate()
- return function (passport, name, strategyOptions = {}, callback = () => {}) {
+ return function (passport, name, strategyOptions = {}, callback = () => {}) {
// This is called by the feathers middleware, hook or socket. The request object
// is a mock request derived from an http request, socket object, or hook.
return function (request = {}) {
return new Promise((resolve, reject) => {
// TODO (EK): Support transformAuthInfo
-
+
// Allow you to set a location for the success payload.
// Default is hook.params.user, req.user and socket.user.
const entity = strategyOptions.entity || strategyOptions.assignProperty || options.entity;
@@ -44,9 +42,9 @@ export default function authenticate (options = {}) {
strategies = [name];
}
- function attempt(index) {
+ function attempt (index) {
const layer = strategies[index];
-
+
if (!layer) {
// If there isn't another strategy then they
// all failed and we'll return the first failure.
@@ -83,7 +81,7 @@ export default function authenticate (options = {}) {
// We failed so attempt with next strategy
attempt(index + 1);
};
-
+
strategy.error = error => {
debug(`Error in '${layer}' authentication strategy`, error);
reject(error);
@@ -114,4 +112,4 @@ export default function authenticate (options = {}) {
});
};
};
-}
+}
@@ -18,4 +18,4 @@ export default function feathersPassport (options) {
initialize: initialize.call(app, options),
authenticate: authenticate.call(app, options)
};
-}
+}
@@ -13,12 +13,12 @@ export default function initialize (options = {}) {
return function (passport) {
// NOTE (EK): This is called by passport.initialize() when calling
// app.configure(authentication()).
-
+
// Expose our JWT util functions globally
passport._feathers = {};
passport.createJWT = createJWT;
passport.verifyJWT = verifyJWT;
- passport.options = function(name, strategyOptions) {
+ passport.options = function (name, strategyOptions) {
if (!name) {
return passport._feathers;
}
@@ -33,4 +33,4 @@ export default function initialize (options = {}) {
}
};
};
-}
+}
Oops, something went wrong.

0 comments on commit 0d1653f

Please sign in to comment.