mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
tests: Make the fake webaccess hook registrations look more real
The additional properties will be needed once `aCallAll()` is upgraded to use `callHookFnAsync()`.
This commit is contained in:
parent
47f0a7dacf
commit
ba02e70020
1 changed files with 14 additions and 4 deletions
|
@ -10,6 +10,13 @@ describe(__filename, function () {
|
||||||
const backups = {};
|
const backups = {};
|
||||||
const authHookNames = ['preAuthorize', 'authenticate', 'authorize'];
|
const authHookNames = ['preAuthorize', 'authenticate', 'authorize'];
|
||||||
const failHookNames = ['preAuthzFailure', 'authnFailure', 'authzFailure', 'authFailure'];
|
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(); });
|
before(async function () { agent = await common.init(); });
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
backups.hooks = {};
|
backups.hooks = {};
|
||||||
|
@ -139,7 +146,10 @@ describe(__filename, function () {
|
||||||
const h0 = new Handler(hookName, '_0');
|
const h0 = new Handler(hookName, '_0');
|
||||||
const h1 = new Handler(hookName, '_1');
|
const h1 = new Handler(hookName, '_1');
|
||||||
handlers[hookName] = [h0, h1];
|
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 () {
|
it('runs preAuthzFailure hook when access is denied', async function () {
|
||||||
handlers.preAuthorize[0].innerHandle = () => [false];
|
handlers.preAuthorize[0].innerHandle = () => [false];
|
||||||
let called = 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.equal(hookName, 'preAuthzFailure');
|
||||||
assert(req != null);
|
assert(req != null);
|
||||||
assert(res != null);
|
assert(res != null);
|
||||||
|
@ -203,7 +213,7 @@ describe(__filename, function () {
|
||||||
called = true;
|
called = true;
|
||||||
res.status(200).send('injected');
|
res.status(200).send('injected');
|
||||||
return cb([true]);
|
return cb([true]);
|
||||||
}}];
|
})];
|
||||||
await agent.get('/admin/').auth('admin', 'admin-password').expect(200, 'injected');
|
await agent.get('/admin/').auth('admin', 'admin-password').expect(200, 'injected');
|
||||||
assert(called);
|
assert(called);
|
||||||
});
|
});
|
||||||
|
@ -404,7 +414,7 @@ describe(__filename, function () {
|
||||||
failHookNames.forEach((hookName) => {
|
failHookNames.forEach((hookName) => {
|
||||||
const handler = new Handler(hookName);
|
const handler = new Handler(hookName);
|
||||||
handlers[hookName] = handler;
|
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.requireAuthentication = true;
|
||||||
settings.requireAuthorization = true;
|
settings.requireAuthorization = true;
|
||||||
|
|
Loading…
Reference in a new issue