mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-31 19:02:59 +01:00
tests: Clear auth hooks before running socket.io unit tests
This commit is contained in:
parent
4829bb8962
commit
03d8882383
1 changed files with 17 additions and 10 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
/* global __dirname, __filename, afterEach, before, beforeEach, clearTimeout, describe, it, require, setTimeout */
|
||||||
|
|
||||||
function m(mod) { return __dirname + '/../../../src/' + mod; }
|
function m(mod) { return __dirname + '/../../../src/' + mod; }
|
||||||
|
|
||||||
const assert = require('assert').strict;
|
const assert = require('assert').strict;
|
||||||
|
@ -35,7 +37,7 @@ const getSocketEvent = async (socket, event) => {
|
||||||
logger.debug(`socket.io ${event} event`);
|
logger.debug(`socket.io ${event} event`);
|
||||||
if (args.length > 1) return resolve(args);
|
if (args.length > 1) return resolve(args);
|
||||||
resolve(args[0]);
|
resolve(args[0]);
|
||||||
}
|
};
|
||||||
Object.entries(handlers).forEach(([event, handler]) => socket.on(event, handler));
|
Object.entries(handlers).forEach(([event, handler]) => socket.on(event, handler));
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
|
@ -91,10 +93,8 @@ const handshake = async (socket, padID) => {
|
||||||
|
|
||||||
describe(__filename, function() {
|
describe(__filename, function() {
|
||||||
let agent;
|
let agent;
|
||||||
before(async function() { agent = await common.init(); });
|
|
||||||
|
|
||||||
let authorize;
|
let authorize;
|
||||||
let authorizeHooksBackup;
|
const backups = {};
|
||||||
const cleanUpPads = async () => {
|
const cleanUpPads = async () => {
|
||||||
const padIds = ['pad', 'other-pad', 'päd'];
|
const padIds = ['pad', 'other-pad', 'päd'];
|
||||||
await Promise.all(padIds.map(async (padId) => {
|
await Promise.all(padIds.map(async (padId) => {
|
||||||
|
@ -104,12 +104,19 @@ describe(__filename, function() {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
const settingsBackup = {};
|
|
||||||
let socket;
|
let socket;
|
||||||
|
|
||||||
|
before(async function() { agent = await common.init(); });
|
||||||
beforeEach(async function() {
|
beforeEach(async function() {
|
||||||
Object.assign(settingsBackup, settings);
|
backups.hooks = {};
|
||||||
assert(socket == null);
|
for (const hookName of ['preAuthorize', 'authenticate', 'authorize']) {
|
||||||
|
backups.hooks[hookName] = plugins.hooks[hookName];
|
||||||
|
plugins.hooks[hookName] = [];
|
||||||
|
}
|
||||||
|
backups.settings = {};
|
||||||
|
for (const setting of ['editOnly', 'requireAuthentication', 'requireAuthorization', 'users']) {
|
||||||
|
backups.settings[setting] = settings[setting];
|
||||||
|
}
|
||||||
settings.editOnly = false;
|
settings.editOnly = false;
|
||||||
settings.requireAuthentication = false;
|
settings.requireAuthentication = false;
|
||||||
settings.requireAuthorization = false;
|
settings.requireAuthorization = false;
|
||||||
|
@ -117,19 +124,19 @@ describe(__filename, function() {
|
||||||
admin: {password: 'admin-password', is_admin: true},
|
admin: {password: 'admin-password', is_admin: true},
|
||||||
user: {password: 'user-password'},
|
user: {password: 'user-password'},
|
||||||
};
|
};
|
||||||
|
assert(socket == null);
|
||||||
authorize = () => true;
|
authorize = () => true;
|
||||||
authorizeHooksBackup = plugins.hooks.authorize;
|
|
||||||
plugins.hooks.authorize = [{hook_fn: (hookName, {req}, cb) => {
|
plugins.hooks.authorize = [{hook_fn: (hookName, {req}, cb) => {
|
||||||
return cb([authorize(req)]);
|
return cb([authorize(req)]);
|
||||||
}}];
|
}}];
|
||||||
await cleanUpPads();
|
await cleanUpPads();
|
||||||
});
|
});
|
||||||
afterEach(async function() {
|
afterEach(async function() {
|
||||||
Object.assign(settings, settingsBackup);
|
|
||||||
if (socket) socket.close();
|
if (socket) socket.close();
|
||||||
socket = null;
|
socket = null;
|
||||||
plugins.hooks.authorize = authorizeHooksBackup;
|
|
||||||
await cleanUpPads();
|
await cleanUpPads();
|
||||||
|
Object.assign(plugins.hooks, backups.hooks);
|
||||||
|
Object.assign(settings, backups.settings);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Normal accesses', function() {
|
describe('Normal accesses', function() {
|
||||||
|
|
Loading…
Reference in a new issue