From 683ba0383a489b16c7aff3eb4de44eb55e9508ae Mon Sep 17 00:00:00 2001 From: Pedro Rosario Date: Wed, 24 Apr 2019 11:11:24 -0400 Subject: [PATCH 1/2] New auth approach --- lib/routes.js | 4 +++- lib/routes.test.js | 1 + lib/services/plugins.js | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/routes.js b/lib/routes.js index 3b1fe0ac..4029759f 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -200,6 +200,8 @@ function addSite(router, { providers, sessionStore }, site) { const siteControllerConfig = site.dir ? files.tryRequire(site.dir) : {}, midleware = _.get(siteControllerConfig, 'middleware', null); + amphoraAuth.useAuth(siteRouter); + if (Array.isArray(midleware)) { siteRouter.use(midleware); } @@ -310,7 +312,7 @@ function loadFromConfig(router, providers, sessionStore) { // iterate through the hosts _.each(siteHosts, hostname => { - const sites = _.filter(sitesMap, {host: hostname}).sort(sortByDepthOfPath); + const sites = _.filter(sitesMap, { host: hostname }).sort(sortByDepthOfPath); addHost({ router, diff --git a/lib/routes.test.js b/lib/routes.test.js index 1e7aa54f..77579bb7 100644 --- a/lib/routes.test.js +++ b/lib/routes.test.js @@ -27,6 +27,7 @@ describe(_.startCase(filename), function () { fakeLog = sandbox.stub(); fakeAuth = sandbox.stub(); fakeAuth.addRoutes = sandbox.stub(); + fakeAuth.useAuth = sandbox.stub(); lib.setLog(fakeLog); lib.setamphoraAuth(fakeAuth); diff --git a/lib/services/plugins.js b/lib/services/plugins.js index 067a00e2..bb0d96b7 100644 --- a/lib/services/plugins.js +++ b/lib/services/plugins.js @@ -1,6 +1,7 @@ 'use strict'; const bluebird = require('bluebird'), + { useAuth } = require('amphora-auth'), db = require('../services/db'), sites = require('../services/sites'), { getMeta, patchMeta } = require('../services/metadata'), @@ -24,7 +25,7 @@ function initPlugins(router, site) { return bluebird.all(module.exports.plugins.map(plugin => { return bluebird.try(() => { if (typeof plugin === 'function') { - return plugin(router, pluginDBAdapter, publish, sites, site); + return plugin(router, pluginDBAdapter, publish, sites, site, useAuth); } else { log('warn', 'Plugin is not a function'); return bluebird.resolve(); From 640e73f4d8f4b7ef79b886f84782994415b9ea2e Mon Sep 17 00:00:00 2001 From: Pedro Rosario Date: Wed, 1 May 2019 16:57:09 -0400 Subject: [PATCH 2/2] Check if useAuth is being called --- lib/routes.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/routes.test.js b/lib/routes.test.js index 77579bb7..d96b7820 100644 --- a/lib/routes.test.js +++ b/lib/routes.test.js @@ -181,6 +181,7 @@ describe(_.startCase(filename), function () { return fn(router, { providers: ['ldap'] }, siteStub) .then(function () { sinon.assert.called(innerRouter.use); + sinon.assert.calledWith(fakeAuth.useAuth, innerRouter); }); });