From e82a3055e666a9caa3c14a8c1d2aa8ac3b615a94 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 25 Aug 2020 16:55:56 -0400 Subject: [PATCH] webaccess: Whitespace fixes --- src/node/hooks/express/webaccess.js | 40 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/node/hooks/express/webaccess.js b/src/node/hooks/express/webaccess.js index 26f6b3e5f..853385c3f 100644 --- a/src/node/hooks/express/webaccess.js +++ b/src/node/hooks/express/webaccess.js @@ -8,15 +8,15 @@ var stats = require('ep_etherpad-lite/node/stats'); var sessionModule = require('express-session'); var cookieParser = require('cookie-parser'); -//checks for basic http auth -exports.basicAuth = function (req, res, next) { - var hookResultMangle = function (cb) { - return function (err, data) { +// checks for basic http auth +exports.basicAuth = function(req, res, next) { + var hookResultMangle = function(cb) { + return function(err, data) { return cb(!err && data.length && data[0]); } } - var authorize = function (cb) { + var authorize = function(cb) { // Do not require auth for static paths and the API...this could be a bit brittle if (req.path.match(/^\/(static|javascripts|pluginfw|api)/)) return cb(true); @@ -27,10 +27,10 @@ exports.basicAuth = function (req, res, next) { if (req.session && req.session.user && req.session.user.is_admin) return cb(true); - hooks.aCallFirst("authorize", {req: req, res:res, next:next, resource: req.path}, hookResultMangle(cb)); + hooks.aCallFirst("authorize", {req: req, res: res, next: next, resource: req.path}, hookResultMangle(cb)); } - var authenticate = function (cb) { + var authenticate = function(cb) { // If auth headers are present use them to authenticate... if (req.headers.authorization && req.headers.authorization.search('Basic ') === 0) { var userpass = Buffer.from(req.headers.authorization.split(' ')[1], 'base64').toString().split(":") @@ -51,22 +51,22 @@ exports.basicAuth = function (req, res, next) { req.session.user = settings.users[username]; return cb(true); }; - return hooks.aCallFirst("authenticate", {req: req, res:res, next:next, username: username, password: password}, hookResultMangle(fallback)); + return hooks.aCallFirst("authenticate", {req: req, res: res, next: next, username: username, password: password}, hookResultMangle(fallback)); } - hooks.aCallFirst("authenticate", {req: req, res:res, next:next}, hookResultMangle(cb)); + hooks.aCallFirst("authenticate", {req: req, res: res, next: next}, hookResultMangle(cb)); } /* Authentication OR authorization failed. */ - var failure = function () { - return hooks.aCallFirst("authFailure", {req: req, res:res, next:next}, hookResultMangle(function (ok) { - if (ok) return; + var failure = function() { + return hooks.aCallFirst("authFailure", {req: req, res: res, next: next}, hookResultMangle(function(ok) { + if (ok) return; /* No plugin handler for invalid auth. Return Auth required * Headers, delayed for 1 second, if authentication failed * before. */ res.header('WWW-Authenticate', 'Basic realm="Protected Area"'); if (req.headers.authorization) { - setTimeout(function () { + setTimeout(function() { res.status(401).send('Authentication required'); }, 1000); } else { @@ -87,11 +87,11 @@ exports.basicAuth = function (req, res, next) { */ - authorize(function (ok) { + authorize(function(ok) { if (ok) return next(); - authenticate(function (ok) { + authenticate(function(ok) { if (!ok) return failure(); - authorize(function (ok) { + authorize(function(ok) { if (ok) return next(); failure(); }); @@ -101,7 +101,7 @@ exports.basicAuth = function (req, res, next) { exports.secret = null; -exports.expressConfigure = function (hook_name, args, cb) { +exports.expressConfigure = function(hook_name, args, cb) { // Measure response time args.app.use(function(req, res, next) { var stopWatch = stats.timer('httpRequests').start(); @@ -116,7 +116,7 @@ exports.expressConfigure = function (hook_name, args, cb) { // If the log level specified in the config file is WARN or ERROR the application server never starts listening to requests as reported in issue #158. // Not installing the log4js connect logger when the log level has a higher severity than INFO since it would not log at that level anyway. if (!(settings.loglevel === "WARN" || settings.loglevel == "ERROR")) - args.app.use(log4js.connectLogger(httpLogger, { level: log4js.levels.DEBUG, format: ':status, :method :url'})); + args.app.use(log4js.connectLogger(httpLogger, {level: log4js.levels.DEBUG, format: ':status, :method :url'})); /* Do not let express create the session, so that we can retain a * reference to it for socket.io to use. Also, set the key (cookie @@ -128,9 +128,9 @@ exports.expressConfigure = function (hook_name, args, cb) { exports.secret = settings.sessionKey; } - if(settings.ssl){ + if (settings.ssl) { var sameSite = "Strict"; - }else{ + } else { var sameSite = "Lax"; }