diff --git a/src/node/db/AuthorManager.ts b/src/node/db/AuthorManager.ts index 4bcfa2c0d..41fb93251 100644 --- a/src/node/db/AuthorManager.ts +++ b/src/node/db/AuthorManager.ts @@ -19,7 +19,7 @@ * limitations under the License. */ -const db = require('./DB'); +import db from './DB'; const CustomError = require('../utils/customError'); const hooks = require('../../static/js/pluginfw/hooks'); import padutils, {randomString} from "../../static/js/pad_utils"; @@ -131,6 +131,7 @@ const mapAuthorWithDBKey = async (mapperkey: string, mapper:string) => { // there is an author with this mapper // update the timestamp of this author + // @ts-ignore await db.setSub(`globalAuthor:${author}`, ['timestamp'], Date.now()); // return the author @@ -222,6 +223,7 @@ exports.getAuthor = async (author: string) => await db.get(`globalAuthor:${autho * Returns the color Id of the author * @param {String} author The id of the author */ +// @ts-ignore exports.getAuthorColorId = async (author: string) => await db.getSub(`globalAuthor:${author}`, ['colorId']); /** @@ -230,12 +232,14 @@ exports.getAuthorColorId = async (author: string) => await db.getSub(`globalAuth * @param {String} colorId The color id of the author */ exports.setAuthorColorId = async (author: string, colorId: string) => await db.setSub( - `globalAuthor:${author}`, ['colorId'], colorId); + // @ts-ignore + `globalAuthor:${author}`, ['colorId'], colorId); /** * Returns the name of the author * @param {String} author The id of the author */ +// @ts-ignore exports.getAuthorName = async (author: string) => await db.getSub(`globalAuthor:${author}`, ['name']); /** @@ -244,7 +248,8 @@ exports.getAuthorName = async (author: string) => await db.getSub(`globalAuthor: * @param {String} name The name of the author */ exports.setAuthorName = async (author: string, name: string) => await db.setSub( - `globalAuthor:${author}`, ['name'], name); + // @ts-ignore + `globalAuthor:${author}`, ['name'], name); /** * Returns an array of all pads this author contributed to diff --git a/src/node/db/DB.ts b/src/node/db/DB.ts index 9e70514b0..785f586d4 100644 --- a/src/node/db/DB.ts +++ b/src/node/db/DB.ts @@ -24,37 +24,55 @@ import {Database} from 'ueberdb2'; import settings from '../utils/Settings'; import log4js from 'log4js'; -const stats = require('../stats') +import stats from '../stats'; const logger = log4js.getLogger('ueberDB'); /** * The UeberDB Object that provides the database functions */ -exports.db = null; +export let db:Database|null = null; /** * Initializes the database with the settings provided by the settings module */ -exports.init = async () => { - exports.db = new Database(settings.dbType, settings.dbSettings, null, logger); - await exports.db.init(); - if (exports.db.metrics != null) { - for (const [metric, value] of Object.entries(exports.db.metrics)) { +export const init = async () => { + db = new Database(settings.dbType, settings.dbSettings, null, logger); + await db.init(); + if (db.metrics != null) { + for (const [metric, value] of Object.entries(db.metrics)) { if (typeof value !== 'number') continue; - stats.gauge(`ueberdb_${metric}`, () => exports.db.metrics[metric]); + stats.gauge(`ueberdb_${metric}`, () => db!.metrics[metric]); } } for (const fn of ['get', 'set', 'findKeys', 'getSub', 'setSub', 'remove']) { - const f = exports.db[fn]; - exports[fn] = async (...args:string[]) => await f.call(exports.db, ...args); - Object.setPrototypeOf(exports[fn], Object.getPrototypeOf(f)); - Object.defineProperties(exports[fn], Object.getOwnPropertyDescriptors(f)); + // @ts-ignore + const f = db[fn]; + // @ts-ignore + dbInstance[fn] = async (...args:string[]) => await f.call(db, ...args); + // @ts-ignore + Object.setPrototypeOf(dbInstance[fn], Object.getPrototypeOf(f)); + // @ts-ignore + Object.defineProperties(dbInstance[fn], Object.getOwnPropertyDescriptors(f)); } }; -exports.shutdown = async (hookName: string, context:any) => { - if (exports.db != null) await exports.db.close(); - exports.db = null; +export const shutdown = async (hookName: string, context:any) => { + if (db != null) await db.close(); + db = null; logger.log('Database closed'); }; + +let dbInstance = {} as { + get: (key:string) => any; + set: (key:string, value:any) => void; + findKeys: (key:string) => string[]; + getSub: (key:string, subkey:string) => any; + setSub: (key:string, subkey:string, value:any) => void; + remove: (key:string) => void; + init: () => Promise; +} + +dbInstance.init = init + +export default dbInstance diff --git a/src/node/db/GroupManager.ts b/src/node/db/GroupManager.ts index b8cb6db02..9a74eb529 100644 --- a/src/node/db/GroupManager.ts +++ b/src/node/db/GroupManager.ts @@ -21,7 +21,7 @@ const CustomError = require('../utils/customError'); import {randomString} from "../../static/js/pad_utils"; -const db = require('./DB'); +import db from './DB'; const padManager = require('./PadManager'); const sessionManager = require('./SessionManager'); @@ -69,6 +69,7 @@ exports.deleteGroup = async (groupID: string): Promise => { // UeberDB's setSub() method atomically reads the record, updates the appropriate property, and // writes the result. Setting a property to `undefined` deletes that property (JSON.stringify() // ignores such properties). + // @ts-ignore db.setSub('groups', [groupID], undefined), ...Object.keys(group.mappings || {}).map(async (m) => await db.remove(`mapper2group:${m}`)), ]); @@ -99,6 +100,7 @@ exports.createGroup = async () => { // Add the group to the `groups` record after the group's individual record is created so that // the state is consistent. Note: UeberDB's setSub() method atomically reads the record, updates // the appropriate property, and writes the result. + // @ts-ignore await db.setSub('groups', [groupID], 1); return {groupID}; }; @@ -121,6 +123,7 @@ exports.createGroupIfNotExistsFor = async (groupMapper: string|object) => { // deleted. Although the core Etherpad API does not support multiple mappings for the same // group, the database record does support multiple mappings in case a plugin decides to extend // the core Etherpad functionality. (It's also easy to implement it this way.) + // @ts-ignore db.setSub(`group:${result.groupID}`, ['mappings', groupMapper], 1), ]); return result; @@ -157,6 +160,7 @@ exports.createGroupPad = async (groupID: string, padName: string, text: string, await padManager.getPad(padID, text, authorId); // create an entry in the group for this pad + // @ts-ignore await db.setSub(`group:${groupID}`, ['pads', padID], 1); return {padID}; @@ -176,6 +180,7 @@ exports.listPads = async (groupID: string): Promise<{ padIDs: string[]; }> => { } // group exists, let's get the pads + // @ts-ignore const result = await db.getSub(`group:${groupID}`, ['pads']); const padIDs = Object.keys(result); diff --git a/src/node/db/Pad.ts b/src/node/db/Pad.ts index efd07b0ba..082f60279 100644 --- a/src/node/db/Pad.ts +++ b/src/node/db/Pad.ts @@ -13,7 +13,7 @@ import ChatMessage from '../../static/js/ChatMessage'; import AttributePool from '../../static/js/AttributePool'; const Stream = require('../utils/Stream'); const assert = require('assert').strict; -const db = require('./DB'); +import db from './DB'; import settings from '../utils/Settings'; const authorManager = require('./AuthorManager'); const padManager = require('./PadManager'); @@ -56,6 +56,7 @@ class Pad { * own database table, or to validate imported pad data before it is written to the database. */ constructor(id:string, database = db) { + // @ts-ignore this.db = database; this.atext = makeAText('\n'); this.pool = new AttributePool(); @@ -428,6 +429,7 @@ class Pad { yield* Stream.range(0, this.chatHead + 1).map((i) => copyRecord(`:chat:${i}`)); // @ts-ignore yield this.copyAuthorInfoToDestinationPad(destinationID); + // @ts-ignore if (destGroupID) yield db.setSub(`group:${destGroupID}`, ['pads', destinationID], 1); }).call(this); for (const p of new Stream(promises).batch(100).buffer(99)) await p; @@ -511,6 +513,7 @@ class Pad { // Group pad? Add it to the group's list if (destGroupID) { + // @ts-ignore await db.setSub(`group:${destGroupID}`, ['pads', destinationID], 1); } diff --git a/src/node/db/PadManager.ts b/src/node/db/PadManager.ts index 292261531..487f485f3 100644 --- a/src/node/db/PadManager.ts +++ b/src/node/db/PadManager.ts @@ -24,7 +24,7 @@ import {PadType} from "../types/PadType"; const CustomError = require('../utils/customError'); const Pad = require('../db/Pad'); -const db = require('./DB'); +import db from './DB'; import settings from '../utils/Settings'; /** @@ -74,6 +74,7 @@ const padList = new class { async getPads() { if (!this._loaded) { this._loaded = (async () => { + // @ts-ignore const dbData = await db.findKeys('pad:*', '*:*:*'); if (dbData == null) return; for (const val of dbData) this.addPad(val.replace(/^pad:/, '')); diff --git a/src/node/db/ReadOnlyManager.ts b/src/node/db/ReadOnlyManager.ts index 23639d665..f16d92ad9 100644 --- a/src/node/db/ReadOnlyManager.ts +++ b/src/node/db/ReadOnlyManager.ts @@ -20,8 +20,8 @@ */ -const db = require('./DB'); -const randomString = require('../utils/randomstring'); +import db from './DB'; +import randomString from '../utils/randomstring'; /** diff --git a/src/node/db/SessionManager.ts b/src/node/db/SessionManager.ts index c0e43a659..de2438669 100644 --- a/src/node/db/SessionManager.ts +++ b/src/node/db/SessionManager.ts @@ -23,7 +23,7 @@ const CustomError = require('../utils/customError'); const promises = require('../utils/promises'); const randomString = require('../utils/randomstring'); -const db = require('./DB'); +import db from './DB'; const groupManager = require('./GroupManager'); const authorManager = require('./AuthorManager'); @@ -151,7 +151,9 @@ exports.createSession = async (groupID: string, authorID: string, validUntil: nu await Promise.all([ // UeberDB's setSub() method atomically reads the record, updates the appropriate (sub)object // property, and writes the result. + // @ts-ignore db.setSub(`group2sessions:${groupID}`, ['sessionIDs', sessionID], 1), + // @ts-ignore db.setSub(`author2sessions:${authorID}`, ['sessionIDs', sessionID], 1), ]); @@ -196,7 +198,9 @@ exports.deleteSession = async (sessionID:string) => { // UeberDB's setSub() method atomically reads the record, updates the appropriate (sub)object // property, and writes the result. Setting a property to `undefined` deletes that property // (JSON.stringify() ignores such properties). + // @ts-ignore db.setSub(`group2sessions:${groupID}`, ['sessionIDs', sessionID], undefined), + // @ts-ignore db.setSub(`author2sessions:${authorID}`, ['sessionIDs', sessionID], undefined), ]); diff --git a/src/node/db/SessionStore.ts b/src/node/db/SessionStore.ts index 0b398efad..e2b28a7ce 100644 --- a/src/node/db/SessionStore.ts +++ b/src/node/db/SessionStore.ts @@ -1,6 +1,6 @@ 'use strict'; -const DB = require('./DB'); +import DB from './DB'; const Store = require('@etherpad/express-session').Store; const log4js = require('log4js'); const util = require('util'); @@ -19,7 +19,7 @@ class SessionStore extends Store { * Etherpad is restarted. Use `null` to prevent `touch()` from ever updating the record. * Ignored if the cookie does not expire. */ - constructor(refresh = null) { + constructor(refresh:number|null = null) { super(); this._refresh = refresh; // Maps session ID to an object with the following properties: @@ -111,4 +111,4 @@ for (const m of ['get', 'set', 'destroy', 'touch']) { SessionStore.prototype[m] = util.callbackify(SessionStore.prototype[`_${m}`]); } -module.exports = SessionStore; +export default SessionStore diff --git a/src/node/handler/PadMessageHandler.ts b/src/node/handler/PadMessageHandler.ts index 0ab97bf0e..a12c72113 100644 --- a/src/node/handler/PadMessageHandler.ts +++ b/src/node/handler/PadMessageHandler.ts @@ -36,8 +36,8 @@ const plugins = require('../../static/js/pluginfw/plugin_defs'); import log4js from 'log4js'; const messageLogger = log4js.getLogger('message'); const accessLogger = log4js.getLogger('access'); -const hooks = require('../../static/js/pluginfw/hooks'); -const stats = require('../stats') +const hooks = require('../../static/js/pluginfw/hooks.js'); +import stats from '../stats'; const assert = require('assert').strict; import {RateLimiterMemory} from 'rate-limiter-flexible'; import {ChangesetRequest, PadUserInfo, SocketClientRequest} from "../types/SocketClientRequest"; diff --git a/src/node/handler/SocketIORouter.ts b/src/node/handler/SocketIORouter.ts index 2206dbc7a..abdf73d69 100644 --- a/src/node/handler/SocketIORouter.ts +++ b/src/node/handler/SocketIORouter.ts @@ -22,9 +22,9 @@ import {MapArrayType} from "../types/MapType"; import {SocketModule} from "../types/SocketModule"; -const log4js = require('log4js'); +import log4js from 'log4js'; import settings from '../utils/Settings'; -const stats = require('../../node/stats') +import stats from '../../node/stats'; const logger = log4js.getLogger('socket.io'); diff --git a/src/node/hooks/express.ts b/src/node/hooks/express.ts index ad7df99c2..b0c400fb3 100644 --- a/src/node/hooks/express.ts +++ b/src/node/hooks/express.ts @@ -13,9 +13,9 @@ import expressSession from '@etherpad/express-session'; import fs from 'fs'; const hooks = require('../../static/js/pluginfw/hooks'); import log4js from 'log4js'; -const SessionStore = require('../db/SessionStore'); +import SessionStore from '../db/SessionStore'; import settings from '../utils/Settings'; -const stats = require('../stats') +import stats from '../stats'; import util from 'util'; const webaccess = require('./express/webaccess'); diff --git a/src/node/hooks/express/errorhandling.ts b/src/node/hooks/express/errorhandling.ts index 2de819b0e..734d915b2 100644 --- a/src/node/hooks/express/errorhandling.ts +++ b/src/node/hooks/express/errorhandling.ts @@ -3,7 +3,7 @@ import {ArgsExpressType} from "../../types/ArgsExpressType"; import {ErrorCaused} from "../../types/ErrorCaused"; -const stats = require('../../stats') +import stats from '../../stats'; exports.expressCreateServer = (hook_name:string, args: ArgsExpressType, cb:Function) => { exports.app = args.app; diff --git a/src/node/security/SecretRotator.ts b/src/node/security/SecretRotator.ts index ee5bec772..777e32e83 100644 --- a/src/node/security/SecretRotator.ts +++ b/src/node/security/SecretRotator.ts @@ -5,7 +5,7 @@ import {LegacyParams} from "../types/LegacyParams"; const {Buffer} = require('buffer'); const crypto = require('./crypto'); -const db = require('../db/DB'); +import db from '../db/DB'; const log4js = require('log4js'); class Kdf { @@ -173,6 +173,7 @@ export class SecretRotator { // TODO: This is racy. If two instances start up at the same time and there are no existing // matching publications, each will generate and publish their own paramters. In practice this // is unlikely to happen, and if it does it can be fixed by restarting both Etherpad instances. + // @ts-ignore const dbKeys:string[] = await db.findKeys(`${this._dbPrefix}:*`, null) || []; let currentParams:any = null; let currentId = null; diff --git a/src/node/server.ts b/src/node/server.ts index 7393271fc..211388ba8 100755 --- a/src/node/server.ts +++ b/src/node/server.ts @@ -69,13 +69,13 @@ NodeVersion.enforceMinNodeVersion(pkg.engines.node.replace(">=", "")); NodeVersion.checkDeprecationStatus(pkg.engines.node.replace(">=", ""), '2.1.0'); const UpdateCheck = require('./utils/UpdateCheck'); -const db = require('./db/DB'); +import db from './db/DB'; const express = require('./hooks/express'); const hooks = require('../static/js/pluginfw/hooks'); const pluginDefs = require('../static/js/pluginfw/plugin_defs'); const plugins = require('../static/js/pluginfw/plugins'); const {Gate} = require('./utils/promises'); -const stats = require('./stats') +import stats from './stats'; const logger = log4js.getLogger('server'); diff --git a/src/node/stats.ts b/src/node/stats.ts index f1fc0cccf..79eadf75f 100644 --- a/src/node/stats.ts +++ b/src/node/stats.ts @@ -1,10 +1,13 @@ 'use strict'; -const measured = require('measured-core'); +// @ts-ignore +import measured from 'measured-core'; -module.exports = measured.createCollection(); +const coll = measured.createCollection() + +export default coll; // @ts-ignore -module.exports.shutdown = async (hookName, context) => { - module.exports.end(); -}; \ No newline at end of file +export const shutdown = async (hookName, context) => { + coll.end(); +}; diff --git a/src/node/utils/ImportEtherpad.ts b/src/node/utils/ImportEtherpad.ts index cf34107c7..492a1e4c6 100644 --- a/src/node/utils/ImportEtherpad.ts +++ b/src/node/utils/ImportEtherpad.ts @@ -22,7 +22,7 @@ import AttributePool from '../../static/js/AttributePool'; const {Pad} = require('../db/Pad'); const Stream = require('./Stream'); const authorManager = require('../db/AuthorManager'); -const db = require('../db/DB'); +import db from '../db/DB'; const hooks = require('../../static/js/pluginfw/hooks'); import log4js from 'log4js'; const supportedElems = require('../../static/js/contentcollector').supportedElems; diff --git a/src/node/utils/Settings.ts b/src/node/utils/Settings.ts index 89dfbc756..2fee4fccd 100644 --- a/src/node/utils/Settings.ts +++ b/src/node/utils/Settings.ts @@ -779,7 +779,7 @@ class Settings { * * The isSettings variable only controls the error logging. */ - private parseSettings = (settingsFilename: string, isSettings: boolean) => { + parseSettings = (settingsFilename: string, isSettings: boolean) => { let settingsStr = ''; let settingsType, notFoundMessage, notFoundFunction; @@ -964,3 +964,4 @@ export default settings + diff --git a/src/tests/backend-new/specs/admin_utils.ts b/src/tests/backend-new/specs/admin_utils.ts index b115a38a6..254accbfc 100644 --- a/src/tests/backend-new/specs/admin_utils.ts +++ b/src/tests/backend-new/specs/admin_utils.ts @@ -1,5 +1,5 @@ -'use strict'; - +import {cleanComments, minify} from "admin/src/utils/utils"; +import {expect, describe, it, beforeAll} from 'vitest' import {strict as assert} from "assert"; import {cleanComments, minify} from "admin/src/utils/utils"; diff --git a/src/tests/backend-new/specs/settings.json b/src/tests/backend-new/specs/settings.json new file mode 100644 index 000000000..12b4748c0 --- /dev/null +++ b/src/tests/backend-new/specs/settings.json @@ -0,0 +1,39 @@ +// line comment +/* + * block comment + */ +{ + "trailing commas": { + "lists": { + "multiple lines": [ + "", + ] + }, + "objects": { + "multiple lines": { + "key": "", + } + } + }, + "environment variable substitution": { + "set": { + "true": "${SET_VAR_TRUE}", + "false": "${SET_VAR_FALSE}", + "null": "${SET_VAR_NULL}", + "undefined": "${SET_VAR_UNDEFINED}", + "number": "${SET_VAR_NUMBER}", + "string": "${SET_VAR_STRING}", + "empty string": "${SET_VAR_EMPTY_STRING}" + }, + "unset": { + "no default": "${UNSET_VAR}", + "true": "${UNSET_VAR:true}", + "false": "${UNSET_VAR:false}", + "null": "${UNSET_VAR:null}", + "undefined": "${UNSET_VAR:undefined}", + "number": "${UNSET_VAR:123}", + "string": "${UNSET_VAR:foo}", + "empty string": "${UNSET_VAR:}" + } + } +} diff --git a/src/tests/backend/specs/settings.ts b/src/tests/backend-new/specs/settings.ts similarity index 65% rename from src/tests/backend/specs/settings.ts rename to src/tests/backend-new/specs/settings.ts index d6dcaf71a..17fc3c28d 100644 --- a/src/tests/backend/specs/settings.ts +++ b/src/tests/backend-new/specs/settings.ts @@ -1,9 +1,8 @@ -'use strict'; +import settingsMod from '../../../node/utils/Settings'; -const assert = require('assert').strict; -const {parseSettings} = require('../../../node/utils/Settings').exportedForTestingOnly; import path from 'path'; import process from 'process'; +import {expect, describe, it, beforeAll} from 'vitest' describe(__filename, function () { describe('parseSettings', function () { @@ -18,11 +17,11 @@ describe(__filename, function () { {name: 'empty string', val: '', var: 'SET_VAR_EMPTY_STRING', want: ''}, ]; - before(async function () { + beforeAll(async function () { for (const tc of envVarSubstTestCases) process.env[tc.var] = tc.val; delete process.env.UNSET_VAR; - settings = parseSettings(path.join(__dirname, 'settings.json'), true); - assert(settings != null); + settings = settingsMod.parseSettings(path.join(__dirname, 'settings.json'), true); + expect(settings).not.toBe(null); }); describe('environment variable substitution', function () { @@ -31,9 +30,9 @@ describe(__filename, function () { it(tc.name, async function () { const obj = settings['environment variable substitution'].set; if (tc.name === 'undefined') { - assert(!(tc.name in obj)); + expect(obj[tc.name]).toBe(undefined); } else { - assert.equal(obj[tc.name], tc.want); + expect(obj[tc.name]).toBe(tc.want); } }); } @@ -42,16 +41,16 @@ describe(__filename, function () { describe('unset', function () { it('no default', async function () { const obj = settings['environment variable substitution'].unset; - assert.equal(obj['no default'], null); + expect(obj['no default']).toBe(null); }); for (const tc of envVarSubstTestCases) { it(tc.name, async function () { const obj = settings['environment variable substitution'].unset; if (tc.name === 'undefined') { - assert(!(tc.name in obj)); + expect(obj[tc.name]).toBe(undefined); } else { - assert.equal(obj[tc.name], tc.want); + expect(obj[tc.name]).toBe(tc.want); } }); } @@ -62,31 +61,31 @@ describe(__filename, function () { describe("Parse plugin settings", function () { - before(async function () { + beforeAll(async function () { process.env["EP__ADMIN__PASSWORD"] = "test" }) it('should parse plugin settings', async function () { - let settings = parseSettings(path.join(__dirname, 'settings.json'), true); - assert.equal(settings.ADMIN.PASSWORD, "test"); + let settings = settingsMod.parseSettings(path.join(__dirname, 'settings.json'), true); + expect(settings!.ADMIN.PASSWORD).toBe("test"); }) it('should bundle settings with same path', async function () { process.env["EP__ADMIN__USERNAME"] = "test" - let settings = parseSettings(path.join(__dirname, 'settings.json'), true); - assert.deepEqual(settings.ADMIN, {PASSWORD: "test", USERNAME: "test"}); + let settings = settingsMod.parseSettings(path.join(__dirname, 'settings.json'), true); + expect(settings!.ADMIN).toEqual({PASSWORD: "test", USERNAME: "test"}); }) it("Can set the ep themes", async function () { process.env["EP__ep_themes__default_theme"] = "hacker" - let settings = parseSettings(path.join(__dirname, 'settings.json'), true); - assert.deepEqual(settings.ep_themes, {"default_theme": "hacker"}); + let settings = settingsMod.parseSettings(path.join(__dirname, 'settings.json'), true); + expect(settings!.ep_themes.default_theme).toBe("hacker"); }) it("can set the ep_webrtc settings", async function () { process.env["EP__ep_webrtc__enabled"] = "true" - let settings = parseSettings(path.join(__dirname, 'settings.json'), true); - assert.deepEqual(settings.ep_webrtc, {"enabled": true}); + let settings = settingsMod.parseSettings(path.join(__dirname, 'settings.json'), true); + expect(settings!.ep_webrtc.enabled).toBe(true); }) }) }); diff --git a/src/tests/backend/common.ts b/src/tests/backend/common.ts index 9c7eb67a6..bae3f2aaf 100644 --- a/src/tests/backend/common.ts +++ b/src/tests/backend/common.ts @@ -8,7 +8,7 @@ const io = require('socket.io-client'); const log4js = require('log4js'); import padutils from '../../static/js/pad_utils'; const process = require('process'); -const server = require('../../node/server'); +const server = require('../../node/server') const setCookieParser = require('set-cookie-parser'); import settings from '../../node/utils/Settings'; import supertest from 'supertest'; diff --git a/src/tests/backend/specs/ImportEtherpad.ts b/src/tests/backend/specs/ImportEtherpad.ts index b9ac9baaf..969346bbb 100644 --- a/src/tests/backend/specs/ImportEtherpad.ts +++ b/src/tests/backend/specs/ImportEtherpad.ts @@ -4,7 +4,7 @@ import {MapArrayType} from "../../../node/types/MapType"; const assert = require('assert').strict; const authorManager = require('../../../node/db/AuthorManager'); -const db = require('../../../node/db/DB'); +import db from '../../../node/db/DB'; const importEtherpad = require('../../../node/utils/ImportEtherpad'); const padManager = require('../../../node/db/PadManager'); const plugins = require('../../../static/js/pluginfw/plugin_defs'); diff --git a/src/tests/backend/specs/SecretRotator.ts b/src/tests/backend/specs/SecretRotator.ts index d95b6dba1..d06975f73 100644 --- a/src/tests/backend/specs/SecretRotator.ts +++ b/src/tests/backend/specs/SecretRotator.ts @@ -3,7 +3,7 @@ import {strict} from "assert"; const common = require('../common'); const crypto = require('../../../node/security/crypto'); -const db = require('../../../node/db/DB'); +import db from '../../../node/db/DB'; const SecretRotator = require("../../../node/security/SecretRotator").SecretRotator; const logger = common.logger; @@ -121,7 +121,8 @@ describe(__filename, function () { if (sr != null) sr.stop(); sr = null; await Promise.all( - (await db.findKeys(`${dbPrefix}:*`, null)).map(async (dbKey: string) => await db.remove(dbKey))); + // @ts-ignore + (await db.findKeys(`${dbPrefix}:*`, null)).map(async (dbKey: string) => await db.remove(dbKey))); }); describe('constructor', function () { @@ -163,6 +164,7 @@ describe(__filename, function () { sr = newRotator(); const fc = setFakeClock(sr); await sr.start(); + // @ts-ignore const dbKeys = await db.findKeys(`${dbPrefix}:*`, null); strict.equal(dbKeys.length, 1); const [id] = dbKeys; @@ -196,12 +198,14 @@ describe(__filename, function () { const fc = setFakeClock(sr); await sr.start(); const {secrets} = sr; + // @ts-ignore const dbKeys = await db.findKeys(`${dbPrefix}:*`, null); sr.stop(); sr = newRotator(); setFakeClock(sr, fc); await sr.start(); strict.deepEqual(sr.secrets, secrets); + // @ts-ignore strict.deepEqual(await db.findKeys(`${dbPrefix}:*`, null), dbKeys); }); @@ -209,6 +213,7 @@ describe(__filename, function () { sr = newRotator(); const fc = setFakeClock(sr); await sr.start(); + // @ts-ignore const [oldId] = await db.findKeys(`${dbPrefix}:*`, null); strict(oldId != null); sr.stop(); @@ -217,6 +222,7 @@ describe(__filename, function () { sr = newRotator(); setFakeClock(sr, fc); await sr.start(); + // @ts-ignore const ids = await db.findKeys(`${dbPrefix}:*`, null); strict.equal(ids.length, 1); const [newId] = ids; @@ -229,6 +235,7 @@ describe(__filename, function () { await sr.start(); const [, , future] = sr.secrets; sr.stop(); + // @ts-ignore const [origId] = await db.findKeys(`${dbPrefix}:*`, null); const p = await db.get(origId); await fc.advance(p.end + p.lifetime + p.interval - 1); @@ -237,6 +244,7 @@ describe(__filename, function () { await sr.start(); strict(sr.secrets.slice(1).includes(future)); // It should have created a new publication, not extended the life of the old publication. + // @ts-ignore strict.equal((await db.findKeys(`${dbPrefix}:*`, null)).length, 2); strict.deepEqual(await db.get(origId), p); }); @@ -247,10 +255,12 @@ describe(__filename, function () { await sr.start(); strict.equal(fc.timeouts.size, 1); const secrets = [...sr.secrets]; + // @ts-ignore const dbKeys = await db.findKeys(`${dbPrefix}:*`, null); await sr.start(); strict.equal(fc.timeouts.size, 1); strict.deepEqual(sr.secrets, secrets); + // @ts-ignore strict.deepEqual(await db.findKeys(`${dbPrefix}:*`, null), dbKeys); }); @@ -335,6 +345,7 @@ describe(__filename, function () { await sr.start(); strict.equal(sr.secrets.length, 4); // 1 for the legacy secret, 3 for past, current, future strict(sr.secrets.slice(1).includes('legacy')); // Should not be the current secret. + // @ts-ignore const ids = await db.findKeys(`${dbPrefix}:*`, null); const params = (await Promise.all(ids.map(async (id:string) => await db.get(id)))) .sort((a, b) => a.algId - b.algId); @@ -380,6 +391,7 @@ describe(__filename, function () { await sr.start(); strict.equal(sr.secrets.length, 5); // s0 through s3 and the legacy secret. strict.deepEqual(sr.secrets, [s2, s1, s0, sr.secrets[3], 'legacy']); + // @ts-ignore const ids = await db.findKeys(`${dbPrefix}:*`, null); const params = (await Promise.all(ids.map(async (id:string) => await db.get(id)))) .sort((a, b) => a.algId - b.algId); @@ -425,6 +437,7 @@ describe(__filename, function () { await sr.start(); strict.deepEqual(sr.secrets, [...new Set(sr.secrets)]); // There shouldn't be multiple publications for the same legacy secret. + // @ts-ignore strict.equal((await db.findKeys(`${dbPrefix}:*`, null)).length, 2); }); @@ -511,8 +524,10 @@ describe(__filename, function () { sr = newRotator(); setFakeClock(sr, fc); await sr.start(); + // @ts-ignore strict.equal((await db.findKeys(`${dbPrefix}:*`, null)).length, 2); await fc.advance(lifetime + (3 * origInterval)); + // @ts-ignore strict.equal((await db.findKeys(`${dbPrefix}:*`, null)).length, 1); }); diff --git a/src/tests/backend/specs/SessionStore.ts b/src/tests/backend/specs/SessionStore.ts index 5dfc44ff2..010ff7b65 100644 --- a/src/tests/backend/specs/SessionStore.ts +++ b/src/tests/backend/specs/SessionStore.ts @@ -1,9 +1,9 @@ 'use strict'; -const SessionStore = require('../../../node/db/SessionStore'); +import SessionStore from '../../../node/db/SessionStore'; import {strict as assert} from 'assert'; const common = require('../common'); -const db = require('../../../node/db/DB'); +import db from '../../../node/db/DB'; import util from 'util'; type Session = { @@ -15,7 +15,7 @@ type Session = { } describe(__filename, function () { - let ss: Session|null; + let ss: SessionStore|null; let sid: string|null; const set = async (sess: string|null) => await util.promisify(ss!.set).call(ss, sid, sess); diff --git a/src/tests/backend/specs/api/sessionsAndGroups.ts b/src/tests/backend/specs/api/sessionsAndGroups.ts index a7e85fbe9..b6d20e17c 100644 --- a/src/tests/backend/specs/api/sessionsAndGroups.ts +++ b/src/tests/backend/specs/api/sessionsAndGroups.ts @@ -5,7 +5,7 @@ import {agent, generateJWTToken, init, logger} from "../../common"; import TestAgent from "supertest/lib/agent"; import supertest from "supertest"; const assert = require('assert').strict; -const db = require('../../../../node/db/DB'); +import db from '../../../../node/db/DB'; let apiVersion = 1; let groupID = ''; diff --git a/src/tests/backend/specs/regression-db.ts b/src/tests/backend/specs/regression-db.ts index ba50e5240..ca5117aa2 100644 --- a/src/tests/backend/specs/regression-db.ts +++ b/src/tests/backend/specs/regression-db.ts @@ -2,14 +2,14 @@ const AuthorManager = require('../../../node/db/AuthorManager'); import {strict as assert} from "assert"; -const common = require('../common'); -const db = require('../../../node/db/DB'); +import {init} from '../common'; +import db from '../../../node/db/DB'; describe(__filename, function () { let setBackup: Function; before(async function () { - await common.init(); + await init(); setBackup = db.set; db.set = async (...args:any) => { @@ -20,7 +20,7 @@ describe(__filename, function () { }); after(async function () { - db.set = setBackup; + db.set = setBackup as any; }); it('regression test for missing await in createAuthor (#5000)', async function () {