mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 22:23:33 +01:00
sessions: drop query from database and try to extend sessionstore
This didn't work, need to investigate correct logic.
This commit is contained in:
parent
ead251a841
commit
d7fe2afad9
2 changed files with 20 additions and 25 deletions
|
@ -9,7 +9,7 @@ const readOnlyManager = require('../../db/ReadOnlyManager');
|
|||
|
||||
hooks.deprecationNotices.authFailure = 'use the authnFailure and authzFailure hooks instead';
|
||||
|
||||
const staticPathsRE = new RegExp(`^/(?:${[
|
||||
const staticPaths = [
|
||||
'api(?:/.*)?',
|
||||
'favicon\\.ico',
|
||||
'ep/pad/connection-diagnostic-info',
|
||||
|
@ -24,7 +24,9 @@ const staticPathsRE = new RegExp(`^/(?:${[
|
|||
'static/.*',
|
||||
'stats/?',
|
||||
'tests/frontend(?:/.*)?',
|
||||
].join('|')})$`);
|
||||
];
|
||||
|
||||
const staticPathsRE = new RegExp(`^/(?:${staticPaths.join('|')})$`);
|
||||
|
||||
exports.normalizeAuthzLevel = (level) => {
|
||||
if (!level) return false;
|
||||
|
@ -199,4 +201,4 @@ exports.expressConfigure = (hookName, args, cb) => {
|
|||
return cb();
|
||||
};
|
||||
|
||||
exports.staticPathsRE = staticPathsRE;
|
||||
exports.staticPaths = staticPaths;
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
const assert = require('assert').strict;
|
||||
const common = require('../../common');
|
||||
const settings = require('../../../../node/utils/Settings');
|
||||
const staticPathsRE = require('../../../../node/hooks/express/webaccess').staticPathsRE;
|
||||
const shouldNotCreateExpressSession =
|
||||
require('../../../../node/hooks/express/webaccess').staticPaths;
|
||||
const fs = require('fs');
|
||||
const SessionStore = require('../../../../node/db/SessionStore');
|
||||
const store = new SessionStore;
|
||||
let agent;
|
||||
|
||||
const shouldCreateExpressSession = [
|
||||
|
@ -15,22 +18,6 @@ const shouldCreateExpressSession = [
|
|||
'/admin',
|
||||
];
|
||||
|
||||
const shouldNotCreateExpressSession = [
|
||||
'/',
|
||||
'/api/',
|
||||
'/favicon.ico',
|
||||
'/locales.json',
|
||||
'/pluginfw/plugin-definitions.json',
|
||||
'/static/js/pad.js',
|
||||
'/stats/',
|
||||
];
|
||||
|
||||
const getDatabaseSize = () => {
|
||||
const dbFile = settings.dbSettings.filename;
|
||||
const database = fs.readFileSync(settings.dbSettings.filename, 'utf8');
|
||||
return database.split('\n').length;
|
||||
}
|
||||
|
||||
describe(__filename, function () {
|
||||
before(async function () { agent = await common.init(); });
|
||||
|
||||
|
@ -41,23 +28,29 @@ describe(__filename, function () {
|
|||
|
||||
for (const endpoint of shouldNotCreateExpressSession) {
|
||||
it(endpoint, async function () {
|
||||
const previousCount = getDatabaseSize();
|
||||
const previousCount = store.length();
|
||||
await agent.get(endpoint)
|
||||
.expect(200)
|
||||
.expect(() => {
|
||||
const newCount = getDatabaseSize();
|
||||
const newCount = store.length();
|
||||
assert(newCount === previousCount);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
for (const endpoint of shouldCreateExpressSession) {
|
||||
const previousCount = getDatabaseSize();
|
||||
for (let endpoint of shouldCreateExpressSession) {
|
||||
// clean up endpoint as it's designed for use in regex
|
||||
endpoint = endpoint.split('(')[0];
|
||||
endpoint = endpoint.replace('\\', '');
|
||||
endpoint = endpoint.replace('.*', '');
|
||||
endpoint = endpoint.replace('?', '');
|
||||
const previousCount = store.length();
|
||||
it(endpoint, async function () {
|
||||
await agent.get(endpoint)
|
||||
.expect(200)
|
||||
.expect(() => {
|
||||
const newCount = getDatabaseSize();
|
||||
const newCount = store.length();
|
||||
console.log(newCount);
|
||||
assert(newCount > previousCount);
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue