refactor(lint): remove jscs, update eslint rules (#477), r=@vbudhram

This commit is contained in:
Vlad Filippov 2017-08-31 11:06:34 -04:00 коммит произвёл Vijay Budhram
Родитель 176c8285fc
Коммит 8bc148ab33
36 изменённых файлов: 1186 добавлений и 1410 удалений

Просмотреть файл

@ -1,11 +1,7 @@
{ plugins:
"extends": "fxa/server", - fxa
"env": { extends: plugin:fxa/server
"mocha": true
}, rules:
"rules": { handle-callback-err: 0
"handle-callback-err": 0, semi: [2, "always"]
"complexity": [2, 10],
"semi": [2, "always"]
}
}

19
.jscsrc
Просмотреть файл

@ -1,19 +0,0 @@
{
"disallowKeywords": ["with", "eval"],
"disallowKeywordsOnNewLine": ["else"],
"disallowMultipleLineStrings": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"maximumLineLength": 160,
"requireCapitalizedConstructors": true,
"requireCurlyBraces": ["for", "while", "do"],
"requireLineFeedAtFileEnd": true,
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return"],
"requireSpaceAfterBinaryOperators": ["=", ",", "+", "-", "/", "*", "==", "===", "!=", "!=="],
"requireSpaceAfterPrefixUnaryOperators": ["~"],
"requireSpacesInConditionalExpression": true,
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
"validateIndentation": 2,
"validateQuoteMarks": "'"
}

Просмотреть файл

@ -1,5 +1,7 @@
FROM node:6.11.1-alpine FROM node:6.11.1-alpine
RUN apk add --no-cache git
RUN addgroup -g 10001 app && \ RUN addgroup -g 10001 app && \
adduser -D -G app -h /app -u 10001 app adduser -D -G app -h /app -u 10001 app
WORKDIR /app WORKDIR /app

Просмотреть файл

@ -36,7 +36,7 @@ program
program.parse(process.argv); program.parse(process.argv);
if (!program.config) { if (! program.config) {
program.config = 'dev'; program.config = 'dev';
} }
@ -45,7 +45,7 @@ process.env.NODE_ENV = program.config;
const db = require('../lib/db'); const db = require('../lib/db');
const logger = require('../lib/logging')('bin.purge_expired_tokens'); const logger = require('../lib/logging')('bin.purge_expired_tokens');
if (!program.pocketId) { if (! program.pocketId) {
logger.error('invalid', { message: 'Required pocket client id!' }); logger.error('invalid', { message: 'Required pocket client id!' });
process.exit(1); process.exit(1);
} }

Просмотреть файл

@ -1,16 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
module.exports = function (grunt) {
'use strict';
grunt.config('jscs', {
app: [
'<%= mainJsFiles %>'
],
options: {
config: '.jscsrc'
}
});
};

Просмотреть файл

@ -8,7 +8,6 @@ module.exports = function (grunt) {
'use strict'; 'use strict';
grunt.registerTask('lint', [ grunt.registerTask('lint', [
'eslint', 'eslint'
'jscs'
]); ]);
}; };

Просмотреть файл

@ -22,19 +22,19 @@ exports.strategy = function() {
authenticate: function dogfoodStrategy(req, reply) { authenticate: function dogfoodStrategy(req, reply) {
var auth = req.headers.authorization; var auth = req.headers.authorization;
logger.debug('check.auth', { header: auth }); logger.debug('check.auth', { header: auth });
if (!auth || auth.indexOf('Bearer ') !== 0) { if (! auth || auth.indexOf('Bearer ') !== 0) {
return reply(AppError.unauthorized('Bearer token not provided')); return reply(AppError.unauthorized('Bearer token not provided'));
} }
var tok = auth.split(' ')[1]; var tok = auth.split(' ')[1];
if (!validators.HEX_STRING.test(tok)) { if (! validators.HEX_STRING.test(tok)) {
return reply(AppError.unauthorized('Illegal Bearer token')); return reply(AppError.unauthorized('Illegal Bearer token'));
} }
token.verify(tok).done(function tokenFound(details) { token.verify(tok).done(function tokenFound(details) {
if (details.scope.indexOf(exports.SCOPE_CLIENT_MANAGEMENT) !== -1) { if (details.scope.indexOf(exports.SCOPE_CLIENT_MANAGEMENT) !== -1) {
logger.debug('check.whitelist'); logger.debug('check.whitelist');
var blocked = !WHITELIST.some(function(re) { var blocked = ! WHITELIST.some(function(re) {
return re.test(details.email); return re.test(details.email);
}); });
if (blocked) { if (blocked) {

Просмотреть файл

@ -21,12 +21,12 @@ exports.strategy = function() {
var auth = req.headers.authorization; var auth = req.headers.authorization;
logger.debug(authName + '.check', { header: auth }); logger.debug(authName + '.check', { header: auth });
if (!auth || auth.indexOf('Bearer ') !== 0) { if (! auth || auth.indexOf('Bearer ') !== 0) {
return reply(AppError.unauthorized('Bearer token not provided')); return reply(AppError.unauthorized('Bearer token not provided'));
} }
var tok = auth.split(' ')[1]; var tok = auth.split(' ')[1];
if (!validators.HEX_STRING.test(tok)) { if (! validators.HEX_STRING.test(tok)) {
return reply(AppError.unauthorized('Illegal Bearer token')); return reply(AppError.unauthorized('Illegal Bearer token'));
} }

Просмотреть файл

@ -65,7 +65,7 @@ module.exports = function verifyAssertion(assertion) {
d.reject(AppError.invalidAssertion()); d.reject(AppError.invalidAssertion());
} }
if (!body || body.status !== 'okay') { if (! body || body.status !== 'okay') {
return error('non-okay response', body); return error('non-okay response', body);
} }
var email = body.email; var email = body.email;
@ -84,7 +84,7 @@ module.exports = function verifyAssertion(assertion) {
} }
var claims = body.idpClaims; var claims = body.idpClaims;
if (!claims || !claims['fxa-verifiedEmail']) { if (! claims || ! claims['fxa-verifiedEmail']) {
return error('incorrect idpClaims', claims); return error('incorrect idpClaims', claims);
} }

Просмотреть файл

@ -383,7 +383,7 @@ if (Object.keys(oldKey).length) {
'openid.key.kid must differ from oldKey'); 'openid.key.kid must differ from oldKey');
assert(oldKey.n, 'openid.oldKey.n is required'); assert(oldKey.n, 'openid.oldKey.n is required');
assert(oldKey.e, 'openid.oldKey.e is required'); assert(oldKey.e, 'openid.oldKey.e is required');
assert(!oldKey.d, 'openid.oldKey.d is forbidden'); assert(! oldKey.d, 'openid.oldKey.d is forbidden');
} }
module.exports = conf; module.exports = conf;

Просмотреть файл

@ -38,7 +38,7 @@ function convertClientToConfigFormat(client) {
if (key === 'hashedSecret' || key === 'hashedSecretPrevious') { if (key === 'hashedSecret' || key === 'hashedSecretPrevious') {
out[key] = unbuf(client[key]); out[key] = unbuf(client[key]);
} else if (key === 'trusted' || key === 'canGrant') { } else if (key === 'trusted' || key === 'canGrant') {
out[key] = !!client[key]; // db stores booleans as 0 or 1. out[key] = !! client[key]; // db stores booleans as 0 or 1.
} else if (typeof client[key] !== 'function') { } else if (typeof client[key] !== 'function') {
out[key] = unbuf(client[key]); out[key] = unbuf(client[key]);
} }
@ -66,7 +66,7 @@ function preClients() {
var REQUIRED_CLIENTS_KEYS = [ 'id', 'hashedSecret', 'name', 'imageUri', var REQUIRED_CLIENTS_KEYS = [ 'id', 'hashedSecret', 'name', 'imageUri',
'redirectUri', 'trusted', 'canGrant' ]; 'redirectUri', 'trusted', 'canGrant' ];
REQUIRED_CLIENTS_KEYS.forEach(function(key) { REQUIRED_CLIENTS_KEYS.forEach(function(key) {
if (!(key in c)) { if (! (key in c)) {
var data = { key: key, name: c.name || 'unknown' }; var data = { key: key, name: c.name || 'unknown' };
logger.error('client.missing.keys', data); logger.error('client.missing.keys', data);
err = new Error('Client config has missing keys'); err = new Error('Client config has missing keys');
@ -77,13 +77,13 @@ function preClients() {
} }
// ensure booleans are boolean and not undefined // ensure booleans are boolean and not undefined
c.trusted = !!c.trusted; c.trusted = !! c.trusted;
c.canGrant = !!c.canGrant; c.canGrant = !! c.canGrant;
c.publicClient = !!c.publicClient; c.publicClient = !! c.publicClient;
// Modification of the database at startup in production and stage is // Modification of the database at startup in production and stage is
// not preferred. This option will be set to false on those stacks. // not preferred. This option will be set to false on those stacks.
if (!config.get('db.autoUpdateClients')) { if (! config.get('db.autoUpdateClients')) {
return P.resolve(); return P.resolve();
} }

Просмотреть файл

@ -80,7 +80,7 @@ const MAX_TTL = config.get('expiration.accessToken');
* } * }
*/ */
function MemoryStore() { function MemoryStore() {
if (!(this instanceof MemoryStore)) { if (! (this instanceof MemoryStore)) {
return new MemoryStore(); return new MemoryStore();
} }
this.clients = {}; this.clients = {};
@ -96,7 +96,7 @@ MemoryStore.connect = function memoryConnect() {
}; };
function clone(obj) { function clone(obj) {
if (!obj) { if (! obj) {
return obj; return obj;
} }
var clone = {}; var clone = {};
@ -131,19 +131,19 @@ MemoryStore.prototype = {
client.createdAt = new Date(); client.createdAt = new Date();
client.imageUri = client.imageUri || ''; client.imageUri = client.imageUri || '';
client.redirectUri = client.redirectUri || ''; client.redirectUri = client.redirectUri || '';
client.canGrant = !!client.canGrant; client.canGrant = !! client.canGrant;
client.trusted = !!client.trusted; client.trusted = !! client.trusted;
this.clients[hex] = client; this.clients[hex] = client;
client.hashedSecret = client.hashedSecret; client.hashedSecret = client.hashedSecret;
client.hashedSecretPrevious = client.hashedSecretPrevious || ''; client.hashedSecretPrevious = client.hashedSecretPrevious || '';
return P.resolve(client); return P.resolve(client);
}, },
updateClient: function updateClient(client) { updateClient: function updateClient(client) {
if (!client.id) { if (! client.id) {
return P.reject(new Error('Update client needs an id')); return P.reject(new Error('Update client needs an id'));
} }
var hex = unbuf(client.id); var hex = unbuf(client.id);
if (!this.clients[hex]) { if (! this.clients[hex]) {
return P.reject(new Error('Client does not exist')); return P.reject(new Error('Client does not exist'));
} }
var old = this.clients[hex]; var old = this.clients[hex];
@ -316,11 +316,11 @@ MemoryStore.prototype = {
return P.resolve(clone(this.refreshTokens[unbuf(token)])); return P.resolve(clone(this.refreshTokens[unbuf(token)]));
}, },
usedRefreshToken: function usedRefreshToken(token) { usedRefreshToken: function usedRefreshToken(token) {
if (!token) { if (! token) {
return P.reject(new Error('Update needs a token')); return P.reject(new Error('Update needs a token'));
} }
var hex = unbuf(token); var hex = unbuf(token);
if (!this.refreshTokens[hex]) { if (! this.refreshTokens[hex]) {
return P.reject(new Error('Token does not exist')); return P.reject(new Error('Token does not exist'));
} }
var old = this.refreshTokens[hex]; var old = this.refreshTokens[hex];

Просмотреть файл

@ -239,9 +239,9 @@ MysqlStore.prototype = {
buf(client.hashedSecret), buf(client.hashedSecret),
client.hashedSecretPrevious ? buf(client.hashedSecretPrevious) : null, client.hashedSecretPrevious ? buf(client.hashedSecretPrevious) : null,
client.redirectUri, client.redirectUri,
!!client.trusted, !! client.trusted,
!!client.canGrant, !! client.canGrant,
!!client.publicClient !! client.publicClient
]).then(function() { ]).then(function() {
logger.debug('registerClient.success', { id: hex(id) }); logger.debug('registerClient.success', { id: hex(id) });
client.id = id; client.id = id;
@ -249,7 +249,7 @@ MysqlStore.prototype = {
}); });
}, },
registerClientDeveloper: function regClientDeveloper(developerId, clientId) { registerClientDeveloper: function regClientDeveloper(developerId, clientId) {
if (!developerId || !clientId) { if (! developerId || ! clientId) {
var err = new Error('Owner registration requires user and developer id'); var err = new Error('Owner registration requires user and developer id');
return P.reject(err); return P.reject(err);
} }
@ -319,7 +319,7 @@ MysqlStore.prototype = {
}); });
}, },
updateClient: function updateClient(client) { updateClient: function updateClient(client) {
if (!client.id) { if (! client.id) {
return P.reject(new Error('Update client needs an id')); return P.reject(new Error('Update client needs an id'));
} }
var secret = client.hashedSecret; var secret = client.hashedSecret;
@ -364,7 +364,7 @@ MysqlStore.prototype = {
codeObj.email, codeObj.email,
codeObj.scope.join(' '), codeObj.scope.join(' '),
codeObj.authAt, codeObj.authAt,
!!codeObj.offline, !! codeObj.offline,
hash, hash,
codeObj.codeChallengeMethod, codeObj.codeChallengeMethod,
codeObj.codeChallenge codeObj.codeChallenge
@ -650,7 +650,7 @@ MysqlStore.prototype = {
needToSetMode = true; needToSetMode = true;
} }
}); });
if (!needToSetMode) { if (! needToSetMode) {
conn._fxa_initialized = true; conn._fxa_initialized = true;
return resolve(conn); return resolve(conn);
} }

Просмотреть файл

@ -11,7 +11,7 @@ const HEX_STRING = require('./validators').HEX_STRING;
var fxaEvents; var fxaEvents;
if (!config.events.region || !config.events.queueUrl) { if (! config.events.region || ! config.events.queueUrl) {
fxaEvents = { fxaEvents = {
start: function start() { start: function start() {
if (env.isProdLike()) { if (env.isProdLike()) {
@ -28,7 +28,7 @@ if (!config.events.region || !config.events.queueUrl) {
logger.verbose('data', message); logger.verbose('data', message);
if (message.event === 'delete') { if (message.event === 'delete') {
var userId = message.uid.split('@')[0]; var userId = message.uid.split('@')[0];
if (!HEX_STRING.test(userId)) { if (! HEX_STRING.test(userId)) {
message.del(); message.del();
return logger.warn('badDelete', { userId: userId }); return logger.warn('badDelete', { userId: userId });
} }

Просмотреть файл

@ -190,7 +190,7 @@ module.exports = {
P.all([ P.all([
verify(req.payload.assertion).then(function(claims) { verify(req.payload.assertion).then(function(claims) {
logger.info('time.browserid_verify', { ms: Date.now() - start }); logger.info('time.browserid_verify', { ms: Date.now() - start });
if (!claims) { if (! claims) {
exitEarly = true; exitEarly = true;
throw AppError.invalidAssertion(); throw AppError.invalidAssertion();
} }
@ -202,10 +202,10 @@ module.exports = {
// assertion was invalid, we can just stop here // assertion was invalid, we can just stop here
return; return;
} }
if (!client) { if (! client) {
logger.debug('notFound', { id: req.payload.client_id }); logger.debug('notFound', { id: req.payload.client_id });
throw AppError.unknownClient(req.payload.client_id); throw AppError.unknownClient(req.payload.client_id);
} else if (!client.trusted) { } else if (! client.trusted) {
var invalidScopes = detectInvalidScopes(scope.values(), var invalidScopes = detectInvalidScopes(scope.values(),
UNTRUSTED_CLIENT_ALLOWED_SCOPES); UNTRUSTED_CLIENT_ALLOWED_SCOPES);
@ -243,7 +243,7 @@ module.exports = {
} }
if (wantsGrant && !client.canGrant) { if (wantsGrant && ! client.canGrant) {
logger.warn('implicitGrant.notAllowed', { logger.warn('implicitGrant.notAllowed', {
id: req.payload.client_id id: req.payload.client_id
}); });

Просмотреть файл

@ -28,7 +28,7 @@ module.exports = {
handler: function requestInfoEndpoint(req, reply) { handler: function requestInfoEndpoint(req, reply) {
var params = req.params; var params = req.params;
db.getClient(Buffer(params.client_id, 'hex')).then(function(client) { db.getClient(Buffer(params.client_id, 'hex')).then(function(client) {
if (!client) { if (! client) {
logger.debug('notFound', { id: params.client_id }); logger.debug('notFound', { id: params.client_id });
throw AppError.unknownClient(params.client_id); throw AppError.unknownClient(params.client_id);
} }

Просмотреть файл

@ -46,8 +46,8 @@ module.exports = {
name: payload.name, name: payload.name,
redirectUri: payload.redirect_uri, redirectUri: payload.redirect_uri,
imageUri: payload.image_uri || '', imageUri: payload.image_uri || '',
canGrant: !!payload.can_grant, canGrant: !! payload.can_grant,
trusted: !!payload.trusted trusted: !! payload.trusted
}; };
var developerEmail = req.auth.credentials.email; var developerEmail = req.auth.credentials.email;
var developerId = null; var developerId = null;

Просмотреть файл

@ -34,7 +34,7 @@ module.exports = {
} }
db[getToken](token).then(function(tok) { db[getToken](token).then(function(tok) {
if (!tok) { if (! tok) {
throw AppError.invalidToken(); throw AppError.invalidToken();
} }
return db[removeToken](token); return db[removeToken](token);

Просмотреть файл

@ -36,7 +36,7 @@ module.exports = {
if (! err) { if (! err) {
delete req.query.action; delete req.query.action;
if (req.query.login_hint && !req.query.email) { if (req.query.login_hint && ! req.query.email) {
req.query.email = req.query.login_hint; req.query.email = req.query.login_hint;
delete req.query.login_hint; delete req.query.login_hint;
} }

Просмотреть файл

@ -13,7 +13,7 @@ try {
var info = require('../../config/version.json'); var info = require('../../config/version.json');
commitHash = info.version.hash; commitHash = info.version.hash;
source = info.version.source; source = info.version.source;
} catch(e) { } catch (e) {
/* ignore */ /* ignore */
} }

Просмотреть файл

@ -228,7 +228,7 @@ function pkceHash(input) {
} }
function validPublicClient(client) { function validPublicClient(client) {
if (!client.publicClient) { if (! client.publicClient) {
logger.debug('client.notPublicClient', { id: client.id }); logger.debug('client.notPublicClient', { id: client.id });
throw AppError.notPublicClient(client.id); throw AppError.notPublicClient(client.id);
} }
@ -249,7 +249,7 @@ function getClientById(clientId) {
function confirmPkceCode(code, pkceVerifier) { function confirmPkceCode(code, pkceVerifier) {
return db.getCode(buf(code)).then(function(codeObj) { return db.getCode(buf(code)).then(function(codeObj) {
if (!codeObj) { if (! codeObj) {
logger.debug('code.notFound', { code: code }); logger.debug('code.notFound', { code: code });
throw AppError.unknownCode(code); throw AppError.unknownCode(code);
} }
@ -299,7 +299,7 @@ function confirmClientSecret(client, secret) {
function confirmCode(id, code) { function confirmCode(id, code) {
return db.getCode(buf(code)).then(function(codeObj) { return db.getCode(buf(code)).then(function(codeObj) {
if (!codeObj) { if (! codeObj) {
logger.debug('code.notFound', { code: code }); logger.debug('code.notFound', { code: code });
throw AppError.unknownCode(code); throw AppError.unknownCode(code);
} else if (hex(codeObj.clientId) !== hex(id)) { } else if (hex(codeObj.clientId) !== hex(id)) {
@ -325,7 +325,7 @@ function confirmCode(id, code) {
function confirmRefreshToken(params) { function confirmRefreshToken(params) {
return db.getRefreshToken(encrypt.hash(params.refresh_token)) return db.getRefreshToken(encrypt.hash(params.refresh_token))
.then(function(tokObj) { .then(function(tokObj) {
if (!tokObj) { if (! tokObj) {
logger.debug('refresh_token.notFound', params.refresh_token); logger.debug('refresh_token.notFound', params.refresh_token);
throw AppError.invalidToken(); throw AppError.invalidToken();
} else if (hex(tokObj.clientId) !== hex(params.client_id)) { } else if (hex(tokObj.clientId) !== hex(params.client_id)) {
@ -334,7 +334,7 @@ function confirmRefreshToken(params) {
code: tokObj.clientId code: tokObj.clientId
}); });
throw AppError.invalidToken(); throw AppError.invalidToken();
} else if (!Scope(tokObj.scope).has(params.scope)) { } else if (! Scope(tokObj.scope).has(params.scope)) {
logger.debug('refresh_token.invalidScopes', { logger.debug('refresh_token.invalidScopes', {
allowed: tokObj.scope, allowed: tokObj.scope,
requested: params.scope requested: params.scope
@ -380,7 +380,7 @@ function confirmJwt(params) {
throw AppError.invalidAssertion(); throw AppError.invalidAssertion();
} }
if (!Scope(client.scope).has(payload.scope)) { if (! Scope(client.scope).has(payload.scope)) {
logger.debug('jwt.invalid.scopes', { logger.debug('jwt.invalid.scopes', {
allowed: client.scope, allowed: client.scope,
requested: payload.scope requested: payload.scope
@ -412,11 +412,11 @@ function confirmJwt(params) {
} }
function _validateJwtSub(sub) { function _validateJwtSub(sub) {
if (!sub) { if (! sub) {
logger.debug('jwt.invalid.sub.missing'); logger.debug('jwt.invalid.sub.missing');
throw AppError.invalidAssertion(); throw AppError.invalidAssertion();
} }
if (sub.length !== 32 || !HEX_STRING.test(sub)) { if (sub.length !== 32 || ! HEX_STRING.test(sub)) {
logger.debug('jwt.invalid.sub', sub); logger.debug('jwt.invalid.sub', sub);
throw AppError.invalidAssertion(); throw AppError.invalidAssertion();
} }

Просмотреть файл

@ -6,10 +6,10 @@
function Scope(arr) { function Scope(arr) {
if (arr instanceof Scope) { if (arr instanceof Scope) {
return arr; return arr;
} else if (!(this instanceof Scope)) { } else if (! (this instanceof Scope)) {
return new Scope(arr); return new Scope(arr);
} }
if (!arr) { if (! arr) {
arr = []; arr = [];
} else if (typeof arr === 'string') { } else if (typeof arr === 'string') {
arr = arr.split(/\s+/); arr = arr.split(/\s+/);
@ -27,7 +27,7 @@ Scope.prototype = {
has: function has(scope) { has: function has(scope) {
return Scope(scope).values().every(function(word) { return Scope(scope).values().every(function(word) {
if (!word || word.lastIndexOf(':') === word.length - 1) { if (! word || word.lastIndexOf(':') === word.length - 1) {
return false; return false;
} else if (word in this._values || word + ':write' in this._values) { } else if (word in this._values || word + ':write' in this._values) {
return true; return true;

Просмотреть файл

@ -70,7 +70,7 @@ exports.create = function createServer() {
routes.forEach(function(route) { routes.forEach(function(route) {
var method = route.method.toUpperCase(); var method = route.method.toUpperCase();
if (method !== 'GET' && method !== 'HEAD') { if (method !== 'GET' && method !== 'HEAD') {
if (!route.config.payload) { if (! route.config.payload) {
route.config.payload = { route.config.payload = {
allow: ['application/json', 'application/x-www-form-urlencoded'] allow: ['application/json', 'application/x-www-form-urlencoded']
}; };

Просмотреть файл

@ -64,7 +64,7 @@ exports.create = function createServer() {
routes.forEach(function(route) { routes.forEach(function(route) {
var method = route.method.toUpperCase(); var method = route.method.toUpperCase();
if (method !== 'GET' && method !== 'HEAD') { if (method !== 'GET' && method !== 'HEAD') {
if (!route.config.payload) { if (! route.config.payload) {
route.config.payload = { route.config.payload = {
allow: ['application/json', 'application/x-www-form-urlencoded'] allow: ['application/json', 'application/x-www-form-urlencoded']
}; };

Просмотреть файл

@ -15,7 +15,7 @@ const TWENTY_FOUR_HOURS = 24 * 60 * 60 * 1000;
exports.verify = function verify(token) { exports.verify = function verify(token) {
return db.getAccessToken(encrypt.hash(token)) return db.getAccessToken(encrypt.hash(token))
.then(function(token) { .then(function(token) {
if (!token) { if (! token) {
throw AppError.invalidToken(); throw AppError.invalidToken();
} else if (+token.expiresAt < Date.now()) { } else if (+token.expiresAt < Date.now()) {
// We dug ourselves a bit of a hole with token expiry, // We dug ourselves a bit of a hole with token expiry,

Просмотреть файл

@ -7,7 +7,7 @@ const crypto = require('crypto');
const config = require('./config'); const config = require('./config');
function unique(length) { function unique(length) {
return crypto.randomBytes(length); return crypto.randomBytes(length); // eslint-disable-line fxa/async-crypto-random
} }
function fn(configName) { function fn(configName) {

2367
npm-shrinkwrap.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -43,13 +43,12 @@
"urijs": "^1.16.1" "urijs": "^1.16.1"
}, },
"devDependencies": { "devDependencies": {
"eslint-config-fxa": "^1.8.0", "eslint-plugin-fxa": "git://github.com/mozilla/eslint-plugin-fxa.git#41504c9dd30e8b52900c15b524946aa0428aef95",
"grunt": "^1.0.1", "grunt": "^1.0.1",
"grunt-bump": "0.8.0", "grunt-bump": "0.8.0",
"grunt-conventional-changelog": "^1.1.0", "grunt-conventional-changelog": "^1.1.0",
"grunt-copyright": "^0.3.0", "grunt-copyright": "^0.3.0",
"grunt-eslint": "^16.0.0", "grunt-eslint": "18.0.0",
"grunt-jscs": "^3.0.1",
"grunt-nodemon": "^0.4.0", "grunt-nodemon": "^0.4.0",
"grunt-nsp": "2.3.1", "grunt-nsp": "2.3.1",
"insist": "1.x", "insist": "1.x",

8
scripts/.eslintrc Normal file
Просмотреть файл

@ -0,0 +1,8 @@
plugins:
- fxa
rules:
fxa/async-crypto-random: 0
fxa/no-new-buffer: 2
no-console: 0
handle-callback-err: 0

Просмотреть файл

@ -30,7 +30,7 @@ const oldKeyPath = './config/oldKey.json';
try { try {
var keysExist = fs.existsSync(keyPath) && fs.existsSync(oldKeyPath); var keysExist = fs.existsSync(keyPath) && fs.existsSync(oldKeyPath);
assert(!keysExist, 'keys already exists'); assert(! keysExist, 'keys already exists');
} catch (e) { } catch (e) {
process.exit(); process.exit();
} }

Просмотреть файл

@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
if (process.argv.length !== 4) { if (process.argv.length !== 4) {
console.error(`Usage: node generate-client-for-ops.js "client-name" "client-redirect-url"`); console.error('Usage: node generate-client-for-ops.js "client-name" "client-redirect-url"');
process.exit(1); process.exit(1);
} }

10
test/.eslintrc Normal file
Просмотреть файл

@ -0,0 +1,10 @@
plugins:
- fxa
extends: ../.eslintrc
env:
mocha: true
rules:
fxa/async-crypto-random: 0
fxa/no-new-buffer: 2

Просмотреть файл

@ -1130,7 +1130,7 @@ describe('/v1', function() {
assertSecurityHeaders(res); assertSecurityHeaders(res);
assert.equal(res.result.token_type, 'bearer'); assert.equal(res.result.token_type, 'bearer');
assert(res.result.access_token); assert(res.result.access_token);
assert(!res.result.refresh_token); assert(! res.result.refresh_token);
assert.equal(res.result.access_token.length, assert.equal(res.result.access_token.length,
config.get('unique.token') * 2); config.get('unique.token') * 2);
assert.equal(res.result.scope, 'foo bar'); assert.equal(res.result.scope, 'foo bar');
@ -2398,7 +2398,7 @@ describe('/v1', function() {
var key = res.result.keys[0]; var key = res.result.keys[0];
assert(key.n); assert(key.n);
assert(key.e); assert(key.e);
assert(!key.d); assert(! key.d);
}); });
}); });
@ -2411,7 +2411,7 @@ describe('/v1', function() {
var keys = res.result.keys; var keys = res.result.keys;
assert.equal(keys.length, 2); assert.equal(keys.length, 2);
assert(!keys[1].d); assert(! keys[1].d);
assert.notEqual(keys[0].kid, keys[1].kid); assert.notEqual(keys[0].kid, keys[1].kid);
}); });
}); });

Просмотреть файл

@ -36,14 +36,14 @@ describe('Scope', function() {
var s1 = Scope('foo bar'); var s1 = Scope('foo bar');
assert(s1.has('foo')); assert(s1.has('foo'));
assert(s1.has('bar')); assert(s1.has('bar'));
assert(!s1.has('baz')); assert(! s1.has('baz'));
}); });
it('should work with another Scope object', function() { it('should work with another Scope object', function() {
var s1 = Scope('foo bar'); var s1 = Scope('foo bar');
var s2 = Scope('bar'); var s2 = Scope('bar');
assert(s1.has(s2)); assert(s1.has(s2));
assert(!s2.has(s1)); assert(! s2.has(s1));
}); });
it('should allow sub-scopes', function() { it('should allow sub-scopes', function() {
@ -51,23 +51,23 @@ describe('Scope', function() {
assert(s1.has('foo:dee')); assert(s1.has('foo:dee'));
assert(s1.has('bar:baz')); assert(s1.has('bar:baz'));
assert(s1.has('foo:mah:pa bar:baz:quux')); assert(s1.has('foo:mah:pa bar:baz:quux'));
assert(!s1.has('bar')); assert(! s1.has('bar'));
assert(!s1.has('foo:write')); assert(! s1.has('foo:write'));
assert(!s1.has('foo:dee:write')); assert(! s1.has('foo:dee:write'));
var s2 = Scope('foo bar baz:quux:write'); var s2 = Scope('foo bar baz:quux:write');
assert(s2.has('foo bar baz:quux')); assert(s2.has('foo bar baz:quux'));
assert(!s2.has('baz:write')); assert(! s2.has('baz:write'));
assert(!s2.has('foo bar baz')); assert(! s2.has('foo bar baz'));
var s3 = Scope('foo:write'); var s3 = Scope('foo:write');
assert(s3.has('foo:bar')); assert(s3.has('foo:bar'));
assert(s3.has('foo:bar:write')); assert(s3.has('foo:bar:write'));
assert(!s3.has('foo::write')); assert(! s3.has('foo::write'));
assert(!s3.has('foo:write:::')); assert(! s3.has('foo:write:::'));
}); });

Просмотреть файл

@ -28,7 +28,7 @@ function checkVersionAndHeaders(path) {
}; };
Object.keys(res.headers).forEach(function(header) { Object.keys(res.headers).forEach(function(header) {
assert.ok(!other[header.toLowerCase()]); assert.ok(! other[header.toLowerCase()]);
}); });
}).done(done, done); }).done(done, done);
}; };

Просмотреть файл

@ -9,7 +9,7 @@ describe('util', function () {
describe('base64URLEncode', function () { describe('base64URLEncode', function () {
it('properly encodes', function () { it('properly encodes', function () {
var testBase64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', var testBase64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
testBuffer = new Buffer(testBase64, 'base64'), testBuffer = Buffer.from(testBase64, 'base64'),
expectedBase64 = testBase64.replace('+', '-').replace('/', '_'); expectedBase64 = testBase64.replace('+', '-').replace('/', '_');
assert.equal(util.base64URLEncode(testBuffer), expectedBase64); assert.equal(util.base64URLEncode(testBuffer), expectedBase64);