tests: Make the fake webaccess hook registrations look more real

The additional properties will be needed once `aCallAll()` is upgraded
to use `callHookFnAsync()`.
pull/4698/head
Richard Hansen 2021-02-01 23:55:16 -05:00 committed by John McLear
parent 47f0a7dacf
commit ba02e70020
1 changed files with 14 additions and 4 deletions

View File

@ -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;