From ba02e700201f4d94c233c1b2211414ee978cdfa5 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 1 Feb 2021 23:55:16 -0500 Subject: [PATCH] tests: Make the fake webaccess hook registrations look more real The additional properties will be needed once `aCallAll()` is upgraded to use `callHookFnAsync()`. --- tests/backend/specs/webaccess.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/backend/specs/webaccess.js b/tests/backend/specs/webaccess.js index 3b140c46c..b82a5f017 100644 --- a/tests/backend/specs/webaccess.js +++ b/tests/backend/specs/webaccess.js @@ -10,6 +10,13 @@ describe(__filename, function () { const backups = {}; const authHookNames = ['preAuthorize', 'authenticate', 'authorize']; const failHookNames = ['preAuthzFailure', 'authnFailure', 'authzFailure', 'authFailure']; + const makeHook = (hookName, hookFn) => ({ + hook_fn: hookFn, + hook_fn_name: `fake_plugin/${hookName}`, + hook_name: hookName, + part: {plugin: 'fake_plugin'}, + }); + before(async function () { agent = await common.init(); }); beforeEach(async function () { backups.hooks = {}; @@ -139,7 +146,10 @@ describe(__filename, function () { const h0 = new Handler(hookName, '_0'); const h1 = new Handler(hookName, '_1'); handlers[hookName] = [h0, h1]; - plugins.hooks[hookName] = [{hook_fn: h0.handle.bind(h0)}, {hook_fn: h1.handle.bind(h1)}]; + plugins.hooks[hookName] = [ + makeHook(hookName, h0.handle.bind(h0)), + makeHook(hookName, h1.handle.bind(h1)), + ]; } }); @@ -195,7 +205,7 @@ describe(__filename, function () { it('runs preAuthzFailure hook when access is denied', async function () { handlers.preAuthorize[0].innerHandle = () => [false]; let called = false; - plugins.hooks.preAuthzFailure = [{hook_fn: (hookName, {req, res}, cb) => { + plugins.hooks.preAuthzFailure = [makeHook('preAuthzFailure', (hookName, {req, res}, cb) => { assert.equal(hookName, 'preAuthzFailure'); assert(req != null); assert(res != null); @@ -203,7 +213,7 @@ describe(__filename, function () { called = true; res.status(200).send('injected'); return cb([true]); - }}]; + })]; await agent.get('/admin/').auth('admin', 'admin-password').expect(200, 'injected'); assert(called); }); @@ -404,7 +414,7 @@ describe(__filename, function () { failHookNames.forEach((hookName) => { const handler = new Handler(hookName); handlers[hookName] = handler; - plugins.hooks[hookName] = [{hook_fn: handler.handle.bind(handler)}]; + plugins.hooks[hookName] = [makeHook(hookName, handler.handle.bind(handler))]; }); settings.requireAuthentication = true; settings.requireAuthorization = true;