mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +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';
|
hooks.deprecationNotices.authFailure = 'use the authnFailure and authzFailure hooks instead';
|
||||||
|
|
||||||
const staticPathsRE = new RegExp(`^/(?:${[
|
const staticPaths = [
|
||||||
'api(?:/.*)?',
|
'api(?:/.*)?',
|
||||||
'favicon\\.ico',
|
'favicon\\.ico',
|
||||||
'ep/pad/connection-diagnostic-info',
|
'ep/pad/connection-diagnostic-info',
|
||||||
|
@ -24,7 +24,9 @@ const staticPathsRE = new RegExp(`^/(?:${[
|
||||||
'static/.*',
|
'static/.*',
|
||||||
'stats/?',
|
'stats/?',
|
||||||
'tests/frontend(?:/.*)?',
|
'tests/frontend(?:/.*)?',
|
||||||
].join('|')})$`);
|
];
|
||||||
|
|
||||||
|
const staticPathsRE = new RegExp(`^/(?:${staticPaths.join('|')})$`);
|
||||||
|
|
||||||
exports.normalizeAuthzLevel = (level) => {
|
exports.normalizeAuthzLevel = (level) => {
|
||||||
if (!level) return false;
|
if (!level) return false;
|
||||||
|
@ -199,4 +201,4 @@ exports.expressConfigure = (hookName, args, cb) => {
|
||||||
return cb();
|
return cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.staticPathsRE = staticPathsRE;
|
exports.staticPaths = staticPaths;
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
const assert = require('assert').strict;
|
const assert = require('assert').strict;
|
||||||
const common = require('../../common');
|
const common = require('../../common');
|
||||||
const settings = require('../../../../node/utils/Settings');
|
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 fs = require('fs');
|
||||||
|
const SessionStore = require('../../../../node/db/SessionStore');
|
||||||
|
const store = new SessionStore;
|
||||||
let agent;
|
let agent;
|
||||||
|
|
||||||
const shouldCreateExpressSession = [
|
const shouldCreateExpressSession = [
|
||||||
|
@ -15,22 +18,6 @@ const shouldCreateExpressSession = [
|
||||||
'/admin',
|
'/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 () {
|
describe(__filename, function () {
|
||||||
before(async function () { agent = await common.init(); });
|
before(async function () { agent = await common.init(); });
|
||||||
|
|
||||||
|
@ -41,23 +28,29 @@ describe(__filename, function () {
|
||||||
|
|
||||||
for (const endpoint of shouldNotCreateExpressSession) {
|
for (const endpoint of shouldNotCreateExpressSession) {
|
||||||
it(endpoint, async function () {
|
it(endpoint, async function () {
|
||||||
const previousCount = getDatabaseSize();
|
const previousCount = store.length();
|
||||||
await agent.get(endpoint)
|
await agent.get(endpoint)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect(() => {
|
.expect(() => {
|
||||||
const newCount = getDatabaseSize();
|
const newCount = store.length();
|
||||||
assert(newCount === previousCount);
|
assert(newCount === previousCount);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const endpoint of shouldCreateExpressSession) {
|
for (let endpoint of shouldCreateExpressSession) {
|
||||||
const previousCount = getDatabaseSize();
|
// 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 () {
|
it(endpoint, async function () {
|
||||||
await agent.get(endpoint)
|
await agent.get(endpoint)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect(() => {
|
.expect(() => {
|
||||||
const newCount = getDatabaseSize();
|
const newCount = store.length();
|
||||||
|
console.log(newCount);
|
||||||
assert(newCount > previousCount);
|
assert(newCount > previousCount);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue