From 42deb7abbec043f5a75579e885e56c90308dc38b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 28 Feb 2018 19:20:51 +0100 Subject: [PATCH] Rename middleware --- lib/cartodb/controllers/named_maps_admin.js | 4 +-- .../{apikey-credentials.js => credentials.js} | 4 +-- lib/cartodb/middleware/context/index.js | 4 +-- test/unit/cartodb/prepare-context.test.js | 30 +++++++++---------- 4 files changed, 21 insertions(+), 21 deletions(-) rename lib/cartodb/middleware/context/{apikey-credentials.js => credentials.js} (94%) diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index b1c6a451..3c501ee1 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -2,11 +2,11 @@ const { templateName } = require('../backends/template_maps'); const cors = require('../middleware/cors'); const userMiddleware = require('../middleware/user'); const localsMiddleware = require('../middleware/context/locals'); -const apikeyCredentialsMiddleware = require('../middleware/context/apikey-credentials'); +const credentialsMiddleware = require('../middleware/context/credentials'); const apikeyMiddleware = [ localsMiddleware, - apikeyCredentialsMiddleware(), + credentialsMiddleware(), ]; /** diff --git a/lib/cartodb/middleware/context/apikey-credentials.js b/lib/cartodb/middleware/context/credentials.js similarity index 94% rename from lib/cartodb/middleware/context/apikey-credentials.js rename to lib/cartodb/middleware/context/credentials.js index b70718ab..25851e36 100644 --- a/lib/cartodb/middleware/context/apikey-credentials.js +++ b/lib/cartodb/middleware/context/credentials.js @@ -1,7 +1,7 @@ 'use strict'; -module.exports = function apikeyToken () { - return function apikeyTokenMiddleware(req, res, next) { +module.exports = function credentials () { + return function credentialsMiddleware(req, res, next) { const apikeyCredentials = getApikeyCredentialsFromRequest(req); res.locals.api_key = apikeyCredentials.token; diff --git a/lib/cartodb/middleware/context/index.js b/lib/cartodb/middleware/context/index.js index 8922739f..9394cfd0 100644 --- a/lib/cartodb/middleware/context/index.js +++ b/lib/cartodb/middleware/context/index.js @@ -1,7 +1,7 @@ const locals = require('./locals'); const cleanUpQueryParams = require('./clean-up-query-params'); const layergroupToken = require('./layergroup-token'); -const apikeyCredentials = require('./apikey-credentials'); +const credentials = require('./credentials'); const authorize = require('./authorize'); const dbConnSetup = require('./db-conn-setup'); @@ -10,7 +10,7 @@ module.exports = function prepareContextMiddleware(authApi, pgConnection) { locals, cleanUpQueryParams(), layergroupToken, - apikeyCredentials(), + credentials(), authorize(authApi), dbConnSetup(pgConnection) ]; diff --git a/test/unit/cartodb/prepare-context.test.js b/test/unit/cartodb/prepare-context.test.js index 2eb7e890..802063eb 100644 --- a/test/unit/cartodb/prepare-context.test.js +++ b/test/unit/cartodb/prepare-context.test.js @@ -10,7 +10,7 @@ var TemplateMaps = require('../../../lib/cartodb/backends/template_maps'); const cleanUpQueryParamsMiddleware = require('../../../lib/cartodb/middleware/context/clean-up-query-params'); const authorizeMiddleware = require('../../../lib/cartodb/middleware/context/authorize'); const dbConnSetupMiddleware = require('../../../lib/cartodb/middleware/context/db-conn-setup'); -const apikeyCredentialsMiddleware = require('../../../lib/cartodb/middleware/context/apikey-credentials'); +const credentialsMiddleware = require('../../../lib/cartodb/middleware/context/credentials'); const localsMiddleware = require('../../../lib/cartodb/middleware/context/locals'); var windshaft = require('windshaft'); @@ -24,7 +24,7 @@ describe('prepare-context', function() { let cleanUpQueryParams; let dbConnSetup; let authorize; - let setApikeyCredentials; + let setCredentials; before(function() { var redisPool = new RedisPool(global.environment.redis); @@ -37,7 +37,7 @@ describe('prepare-context', function() { cleanUpQueryParams = cleanUpQueryParamsMiddleware(); authorize = authorizeMiddleware(authApi); dbConnSetup = dbConnSetupMiddleware(pgConnection); - setApikeyCredentials = apikeyCredentialsMiddleware(); + setCredentials = credentialsMiddleware(); }); @@ -74,7 +74,7 @@ describe('prepare-context', function() { done(); }); }); - + it('cleans up request', function(done){ var req = {headers: { host:'localhost' }, query: {dbuser:'hacker',dbname:'secret'}}; var res = {}; @@ -106,18 +106,18 @@ describe('prepare-context', function() { }); it('sets also dbuser for authenticated requests', function(done){ - var req = { - headers: { - host: 'localhost' - }, + var req = { + headers: { + host: 'localhost' + }, query: { api_key: '1234' } }; - var res = { + var res = { set: function () {}, locals: { - api_key: '1234' + api_key: '1234' } }; @@ -169,7 +169,7 @@ describe('prepare-context', function() { } }; var res = {}; - + cleanUpQueryParams(prepareRequest(req), prepareResponse(res), function (err) { if ( err ) { return done(err); @@ -194,12 +194,12 @@ describe('prepare-context', function() { } }; var res = {}; - setApikeyCredentials(prepareRequest(req), prepareResponse(res), function (err) { + setCredentials(prepareRequest(req), prepareResponse(res), function (err) { if (err) { return done(err); } var query = res.locals; - + assert.equal('1234', query.api_key); done(); }); @@ -215,7 +215,7 @@ describe('prepare-context', function() { } }; var res = {}; - setApikeyCredentials(prepareRequest(req), prepareResponse(res), function (err) { + setCredentials(prepareRequest(req), prepareResponse(res), function (err) { if (err) { return done(err); } @@ -234,7 +234,7 @@ describe('prepare-context', function() { } }; var res = {}; - setApikeyCredentials(prepareRequest(req), prepareResponse(res), function (err) { + setCredentials(prepareRequest(req), prepareResponse(res), function (err) { if (err) { return done(err); }