Compare commits

...

9 Commits

Author SHA1 Message Date
John McLear fbb92b589f session: remove some noise 2021-03-05 08:43:41 +00:00
John McLear 4904e7f486 session: check session_id is present in response 2021-03-05 08:43:28 +00:00
John McLear d7fe2afad9 sessions: drop query from database and try to extend sessionstore
This didn't work, need to investigate correct logic.
2021-03-05 08:23:01 +00:00
John McLear ead251a841 sessions: split regex into array and regex 2021-03-05 08:22:06 +00:00
John McLear 4daa0fe030 sessions: additional express session check points 2021-03-05 07:57:32 +00:00
John McLear 2d3f51fe89 sessions: explicitly mention this is an Express Session not a SocketIO Session 2021-03-05 07:53:57 +00:00
John McLear fd285c7748 sessions: export staticPathsRE to be reused in tests. 2021-03-05 07:52:26 +00:00
John McLear d696a048dc Merge branch 'develop' into session-creation-tests 2021-03-05 07:51:46 +00:00
John McLear 3f2c8c6dae tests: rather course (but it works) test coverage for session creation.
*will fail intentionally*

In response to https://github.com/ether/etherpad-lite/issues/4898
2021-03-02 12:43:45 +00:00
3 changed files with 77 additions and 3 deletions

View File

@ -41,4 +41,8 @@ module.exports = class SessionStore extends Store {
logger.debug(`DESTROY ${sid}`); logger.debug(`DESTROY ${sid}`);
DB.db.remove(`sessionstorage:${sid}`, fn); DB.db.remove(`sessionstorage:${sid}`, fn);
} }
store(fn) {
Store.length(null, fn);
}
}; };

View File

@ -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',
@ -23,8 +23,10 @@ const staticPathsRE = new RegExp(`^/(?:${[
'robots.txt', 'robots.txt',
'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;
@ -198,3 +200,5 @@ exports.expressConfigure = (hookName, args, cb) => {
args.app.use((req, res, next) => { checkAccess(req, res, next).catch(next); }); args.app.use((req, res, next) => { checkAccess(req, res, next).catch(next); });
return cb(); return cb();
}; };
exports.staticPaths = staticPaths;

View File

@ -0,0 +1,66 @@
'use strict';
const assert = require('assert').strict;
const common = require('../../common');
const settings = require('../../../../node/utils/Settings');
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 = [
'/p/foo',
'/p/foo/export/html',
'/socket.io',
'/ep_example',
'/admin',
];
describe(__filename, function () {
before(async function () { agent = await common.init(); });
describe('Express Session Creation on endpoint', function () {
if (settings.dbType !== 'dirty') this.skip;
this.timeout(100);
for (const endpoint of shouldNotCreateExpressSession) {
it(endpoint, async function () {
const previousCount = store.length();
await agent.get(endpoint)
.expect(200)
.expect((res) => {
const hasExpressSessionCookie =
res.headers['set-cookie'][0].indexOf('express_sid');
assert(hasExpressSessionCookie === -1);
const newCount = store.length();
assert(newCount === previousCount);
})
});
}
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((res) => {
console.error(res.headers['set-cookie']);
const hasExpressSessionCookie =
res.headers['set-cookie'][0].indexOf('express_sid');
assert(hasExpressSessionCookie !== -1);
const newCount = store.length();
console.log(newCount);
assert(newCount > previousCount);
})
});
}
});
});