diff --git a/core/server/services/auth/api-key/admin.js b/core/server/services/auth/api-key/admin.js index 24473a4fa3..886261536f 100644 --- a/core/server/services/auth/api-key/admin.js +++ b/core/server/services/auth/api-key/admin.js @@ -18,8 +18,6 @@ const _extractTokenFromHeader = function extractTokenFromHeader(header) { if (/^Ghost$/i.test(scheme)) { return token; } - - return; }; /** @@ -36,7 +34,7 @@ const _extractTokenFromHeader = function extractTokenFromHeader(header) { * - the "Audience" claim should match the requested API path * https://tools.ietf.org/html/rfc7519#section-4.1.3 */ -const authenticateAdminApiKey = function authenticateAdminApiKey(req, res, next) { +const authenticate = (req, res, next) => { // we don't have an Authorization header so allow fallthrough to other // auth middleware or final "ensure authenticated" check if (!req.headers || !req.headers.authorization) { @@ -109,5 +107,5 @@ const authenticateAdminApiKey = function authenticateAdminApiKey(req, res, next) }; module.exports = { - authenticateAdminApiKey + authenticate }; diff --git a/core/test/unit/services/auth/api-key/admin_spec.js b/core/test/unit/services/auth/api-key/admin_spec.js index 1192101649..91c7e8445f 100644 --- a/core/test/unit/services/auth/api-key/admin_spec.js +++ b/core/test/unit/services/auth/api-key/admin_spec.js @@ -2,7 +2,7 @@ const jwt = require('jsonwebtoken'); const should = require('should'); const sinon = require('sinon'); const Promise = require('bluebird'); -const {authenticateAdminApiKey} = require('../../../../../server/services/auth/api-key/admin'); +const apiKeyAuth = require('../../../../../server/services/auth/api-key'); const common = require('../../../../../server/lib/common'); const models = require('../../../../../server/models'); const testUtils = require('../../../../utils'); @@ -52,7 +52,7 @@ describe('Admin API Key Auth', function () { }; const res = {}; - authenticateAdminApiKey(req, res, (err) => { + apiKeyAuth.admin.authenticate(req, res, (err) => { should.not.exist(err); req.api_key.should.eql(this.fakeApiKey); done(); @@ -68,7 +68,7 @@ describe('Admin API Key Auth', function () { }; const res = {}; - authenticateAdminApiKey(req, res, function next(err) { + apiKeyAuth.admin.authenticate(req, res, function next(err) { should.exist(err); should.equal(err instanceof common.errors.UnauthorizedError, true); err.code.should.eql('INVALID_AUTH_HEADER'); @@ -86,7 +86,7 @@ describe('Admin API Key Auth', function () { }; const res = {}; - authenticateAdminApiKey(req, res, function next(err) { + apiKeyAuth.admin.authenticate(req, res, function next(err) { should.exist(err); should.equal(err instanceof common.errors.BadRequestError, true); err.code.should.eql('INVALID_JWT'); @@ -112,7 +112,7 @@ describe('Admin API Key Auth', function () { }; const res = {}; - authenticateAdminApiKey(req, res, function next(err) { + apiKeyAuth.admin.authenticate(req, res, function next(err) { should.exist(err); should.equal(err instanceof common.errors.UnauthorizedError, true); err.code.should.eql('UNKNOWN_ADMIN_API_KEY'); @@ -141,7 +141,7 @@ describe('Admin API Key Auth', function () { }; const res = {}; - authenticateAdminApiKey(req, res, function next(err) { + apiKeyAuth.admin.authenticate(req, res, function next(err) { should.exist(err); should.equal(err instanceof common.errors.UnauthorizedError, true); err.code.should.eql('INVALID_JWT'); @@ -171,7 +171,7 @@ describe('Admin API Key Auth', function () { }; const res = {}; - authenticateAdminApiKey(req, res, function next(err) { + apiKeyAuth.admin.authenticate(req, res, function next(err) { should.exist(err); should.equal(err instanceof common.errors.UnauthorizedError, true); err.code.should.eql('INVALID_JWT'); @@ -201,7 +201,7 @@ describe('Admin API Key Auth', function () { this.fakeApiKey.type = 'content'; - authenticateAdminApiKey(req, res, function next(err) { + apiKeyAuth.admin.authenticate(req, res, function next(err) { should.exist(err); should.equal(err instanceof common.errors.UnauthorizedError, true); err.code.should.eql('INVALID_API_KEY_TYPE');