Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vulnerabilities #18

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,913 changes: 2,006 additions & 907 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@villedemontreal/mongo",
"version": "7.1.1",
"version": "7.1.2",
"description": "Utilities for Mongo / Mongoose",
"main": "dist/src/index.js",
"typings": "dist/src",
Expand Down Expand Up @@ -29,15 +29,15 @@
"author": "Ville de Montréal",
"license": "MIT",
"dependencies": {
"@villedemontreal/general-utils": "5.16.8",
"@villedemontreal/logger": "6.5.9",
"@villedemontreal/general-utils": "5.17.4",
"@villedemontreal/logger": "6.6.2",
"app-root-path": "3.1.0",
"fs-extra": "10.1.0",
"http-status-codes": "2.2.0",
"lodash": "4.17.21",
"mongodb": "4.16.0",
"mongodb": "4.17.2",
"mongodb-memory-server-core": "8.6.1",
"mongoose": "6.11.3",
"mongoose": "6.12.6",
"semver": "7.5.2"
},
"devDependencies": {
Expand All @@ -50,11 +50,11 @@
"@types/sinon": "10.0.13",
"@typescript-eslint/eslint-plugin": "5.59.2",
"@typescript-eslint/parser": "5.59.2",
"@villedemontreal/scripting": "2.1.6",
"@villedemontreal/scripting": "2.1.8",
"chai": "4.3.7",
"eslint": "8.40.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-prettier": "5.1.3",
"mocha": "9.2.2",
"mocha-jenkins-reporter": "0.4.8",
"nyc": "15.1.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class TestScript extends ScriptBase<Options> {
{
default: `output/test-results/report.xml`,
validator: program.STRING,
}
},
);
}

Expand Down
6 changes: 3 additions & 3 deletions scripts/testUnits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class TestUnitsScript extends ScriptBase<Options> {
{
default: `output/test-results/report.xml`,
validator: program.STRING,
}
},
);
}

Expand Down Expand Up @@ -58,7 +58,7 @@ export class TestUnitsScript extends ScriptBase<Options> {
cmdArgs.push(`${configs.libRoot}/node_modules/nyc/bin/nyc`);
} else {
this.logger.warn(
`The "nyc" direct dependency was not found in your project. The tests will be run using Mocha only!`
`The "nyc" direct dependency was not found in your project. The tests will be run using Mocha only!`,
);
}

Expand Down Expand Up @@ -109,7 +109,7 @@ export class TestUnitsScript extends ScriptBase<Options> {
});

this.logger.info(
" \u21b3 type 'run show-coverage' (or './run show-coverage' on Linux/Mac) to display the HTML report"
" \u21b3 type 'run show-coverage' (or './run show-coverage' on Linux/Mac) to display the HTML report",
);
} catch (err) {
throw new Error('Some unit tests failed');
Expand Down
4 changes: 2 additions & 2 deletions scripts/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ that point since the incremental compilation is already done by this script.`;
this.logger.info(
`\n==========================================\n` +
`Starting incremental compilation...\n` +
`==========================================\n`
`==========================================\n`,
);
const projectName = require(configs.libRoot + '/package.json').namae;
let ignoreNextCompilationComplete = false;
Expand Down Expand Up @@ -94,7 +94,7 @@ that point since the incremental compilation is already done by this script.`;
],
{
outputHandler,
}
},
);
} catch (err) {
// ==========================================
Expand Down
14 changes: 7 additions & 7 deletions src/config/mongooseConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class MongooseConfigs implements IMongooseConfigs {
if (!_.isNil(overridingConfigs.updater.lockMaxAgeSeconds)) {
if (!utils.isIntegerValue(overridingConfigs.updater.lockMaxAgeSeconds, true, false)) {
throw new Error(
`The updater.lockMaxAgeSeconds config is not valid : ${overridingConfigs.updater.lockMaxAgeSeconds}`
`The updater.lockMaxAgeSeconds config is not valid : ${overridingConfigs.updater.lockMaxAgeSeconds}`,
);
}
this.updater.lockMaxAgeSeconds = Number(overridingConfigs.updater.lockMaxAgeSeconds);
Expand All @@ -138,7 +138,7 @@ export class MongooseConfigs implements IMongooseConfigs {
utils.isBlank(overridingConfigs.updater.appSchemaCollectionName)
) {
throw new Error(
`The appSchemaCollectionName config is not valid : ${overridingConfigs.updater.appSchemaCollectionName}`
`The appSchemaCollectionName config is not valid : ${overridingConfigs.updater.appSchemaCollectionName}`,
);
}
this.updater.appSchemaCollectionName = overridingConfigs.updater.appSchemaCollectionName;
Expand All @@ -147,7 +147,7 @@ export class MongooseConfigs implements IMongooseConfigs {
if (!_.isNil(overridingConfigs.applyUpdates)) {
if (!_.isBoolean(overridingConfigs.applyUpdates)) {
throw new Error(
`The applyUpdates config must be a boolean: ${overridingConfigs.applyUpdates}`
`The applyUpdates config must be a boolean: ${overridingConfigs.applyUpdates}`,
);
}
this.applyUpdates = overridingConfigs.applyUpdates;
Expand All @@ -159,20 +159,20 @@ export class MongooseConfigs implements IMongooseConfigs {
utils.isBlank(overridingConfigs.connectionString)
) {
throw new Error(
`The connectionString config is not valid : ${overridingConfigs.connectionString}`
`The connectionString config is not valid : ${overridingConfigs.connectionString}`,
);
}
this.connectionString = overridingConfigs.connectionString;
} else {
logger.warning(
`No "connectionString" config was provided: a *mocked* Mongo server will be used!`
`No "connectionString" config was provided: a *mocked* Mongo server will be used!`,
);
}

if (!_.isNil(overridingConfigs.connectionOptions)) {
if (!_.isObject(overridingConfigs.connectionOptions)) {
throw new Error(
`The connectionOptions config is not valid : ${overridingConfigs.connectionString}`
`The connectionOptions config is not valid : ${overridingConfigs.connectionString}`,
);
}
this.connectionOptions = overridingConfigs.connectionOptions;
Expand All @@ -187,7 +187,7 @@ export class MongooseConfigs implements IMongooseConfigs {
utils.isBlank(overridingConfigs.mockServer.serverVersion)
) {
throw new Error(
`The mockServer.serverVersion config is not valid : ${overridingConfigs.mockServer.serverVersion}`
`The mockServer.serverVersion config is not valid : ${overridingConfigs.mockServer.serverVersion}`,
);
}
this.mockServer.serverVersion = overridingConfigs.mockServer.serverVersion;
Expand Down
6 changes: 3 additions & 3 deletions src/mongoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let mongooseConnection: mongoose.Connection;
async function doInitMongoose(
mongooseConfigClean: MongooseConfigs,
resolve: (value: mongoose.Connection) => void,
reject: (reason?: any) => void
reject: (reason?: any) => void,
): Promise<void> {
let connectionString = mongooseConfigClean.connectionString;

Expand All @@ -26,7 +26,7 @@ async function doInitMongoose(
// ==========================================
const mongoServer = await mongoUtils.mockMongoose(
null,
mongooseConfigClean.mockServer.serverVersion
mongooseConfigClean.mockServer.serverVersion,
);

connectionString = mongoServer.getUri();
Expand Down Expand Up @@ -113,7 +113,7 @@ async function checkForUpdates(mongooseConfig: IMongooseConfigs): Promise<void>
connection.db,
mongooseConfig.updater.mongoSchemaUpdatesDirPath,
mongooseConfig.updater.lockMaxAgeSeconds,
mongooseConfig.updater.appSchemaCollectionName
mongooseConfig.updater.appSchemaCollectionName,
);
await updater.checkInstallation();
await updater.checkUpdates();
Expand Down
14 changes: 7 additions & 7 deletions src/mongoUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Mongo Updater', () => {
mongoDb,
testconfig.updater.mongoSchemaUpdatesDirPath,
testconfig.updater.lockMaxAgeSeconds,
testconfig.updater.appSchemaCollectionName
testconfig.updater.appSchemaCollectionName,
);
});

Expand Down Expand Up @@ -101,7 +101,7 @@ describe('Mongo Updater', () => {
assert.strictEqual(collections[0].name, testconfig.updater.appSchemaCollectionName);

const schema: MongoDb.Collection = mongoDb.collection(
testconfig.updater.appSchemaCollectionName
testconfig.updater.appSchemaCollectionName,
);
const schemaDb: any[] = await schema.find().toArray();
assert.strictEqual(schemaDb[0].version, '0.0.0');
Expand All @@ -118,7 +118,7 @@ describe('Mongo Updater', () => {
describe('lock', () => {
it('lock should be equal to false', async () => {
const schema: MongoDb.Collection = mongoDb.collection(
testconfig.updater.appSchemaCollectionName
testconfig.updater.appSchemaCollectionName,
);
const schemaDb: any[] = await schema.find().toArray();
assert.strictEqual(schemaDb[0].lock, false);
Expand All @@ -131,7 +131,7 @@ describe('Mongo Updater', () => {

it('lock should be equal to true', async () => {
const schema: MongoDb.Collection = mongoDb.collection(
testconfig.updater.appSchemaCollectionName
testconfig.updater.appSchemaCollectionName,
);
const schemaDb: any[] = await schema.find().toArray();
assert.strictEqual(schemaDb[0].lock, true);
Expand All @@ -146,7 +146,7 @@ describe('Mongo Updater', () => {
describe('unlock', () => {
it('lock should be equal to true', async () => {
const schema: MongoDb.Collection = mongoDb.collection(
testconfig.updater.appSchemaCollectionName
testconfig.updater.appSchemaCollectionName,
);
const schemaDb: any[] = await schema.find().toArray();
assert.strictEqual(schemaDb[0].lock, true);
Expand All @@ -159,7 +159,7 @@ describe('Mongo Updater', () => {

it('lock should be equal to false', async () => {
const schema: MongoDb.Collection = mongoDb.collection(
testconfig.updater.appSchemaCollectionName
testconfig.updater.appSchemaCollectionName,
);
const schemaDb: any[] = await schema.find().toArray();
assert.strictEqual(schemaDb[0].lock, false);
Expand All @@ -170,7 +170,7 @@ describe('Mongo Updater', () => {
assert.strictEqual(isUnlocked, false);

const schema: MongoDb.Collection = mongoDb.collection(
testconfig.updater.appSchemaCollectionName
testconfig.updater.appSchemaCollectionName,
);
const schemaDb: any[] = await schema.find().toArray();
assert.strictEqual(schemaDb[0].lock, false);
Expand Down
28 changes: 14 additions & 14 deletions src/mongoUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class MongoUpdater implements IMongoUpdater {
*/
private mongoSchemaUpdatesDirPath: string,
private lockMaxAgeSeconds: number,
private appSchemaCollectionName: string
private appSchemaCollectionName: string,
) {}

public async installAppSchemaCollection(): Promise<any> {
Expand All @@ -98,7 +98,7 @@ export class MongoUpdater implements IMongoUpdater {
// tslint:disable-next-line: prefer-template
logger.info(' > Installing the "' + this.appSchemaCollectionName + '" collection.');
const collection: MongoDb.Collection = await this.mongoDb.createCollection(
this.appSchemaCollectionName
this.appSchemaCollectionName,
);

// ==========================================
Expand Down Expand Up @@ -162,13 +162,13 @@ export class MongoUpdater implements IMongoUpdater {
await appSchemaCollection.updateOne({}, { $set: { version: newVersion } });
// tslint:disable-next-line: prefer-template
logger.info(
' > MongoDB App Schema updagred from version ' + currentVersion + ' to version ' + newVersion
' > MongoDB App Schema updagred from version ' + currentVersion + ' to version ' + newVersion,
);
}

public async getAppSchemaUpdateFiles(
currentAppSchemaVersion: string,
targetAppSchemaVersion: string
targetAppSchemaVersion: string,
): Promise<string[]> {
return new Promise<string[]>((resolve, reject) => {
fs.readdir(this.getAppSchemaFilesDirPath(), (err, files) => {
Expand Down Expand Up @@ -206,7 +206,7 @@ export class MongoUpdater implements IMongoUpdater {
public async applyAppSchemaUpdates(currentVersion: string, newVersion: string): Promise<void> {
const updateFileNames: string[] = await this.getAppSchemaUpdateFiles(
currentVersion,
newVersion
newVersion,
);
if (updateFileNames.length > 0) {
for (const updateFileName of updateFileNames) {
Expand All @@ -224,7 +224,7 @@ export class MongoUpdater implements IMongoUpdater {
if (!isFunction(updateFunction)) {
return Promise.reject(
'The default export for an app schema update file must be a function! Was not for file : ' +
updateFilePath
updateFilePath,
);
}

Expand Down Expand Up @@ -269,7 +269,7 @@ export class MongoUpdater implements IMongoUpdater {
lock: true,
lockTimestamp: new Date().getTime(),
},
}
},
);

if (document.value !== null) {
Expand Down Expand Up @@ -301,7 +301,7 @@ export class MongoUpdater implements IMongoUpdater {
lock: true,
lockTimestamp: new Date().getTime(),
},
}
},
);

// ==========================================
Expand Down Expand Up @@ -331,7 +331,7 @@ export class MongoUpdater implements IMongoUpdater {
lock: false,
lockTimestamp: 0,
},
}
},
);

if (document.value !== null) {
Expand All @@ -345,20 +345,20 @@ export class MongoUpdater implements IMongoUpdater {

public async checkInstallation(): Promise<void> {
logger.info(
`Validating that the "${this.appSchemaCollectionName}" collection required by the application has been installed.`
`Validating that the "${this.appSchemaCollectionName}" collection required by the application has been installed.`,
);
const collections: any[] = await this.mongoDb
.listCollections({ name: this.appSchemaCollectionName })
.toArray();

if (collections.length === 0) {
logger.info(
` > The "${this.appSchemaCollectionName}" collection was not found... Starting a new installation.`
` > The "${this.appSchemaCollectionName}" collection was not found... Starting a new installation.`,
);
await this.installAppSchemaCollection();
} else {
logger.info(
` > The "${this.appSchemaCollectionName}" collection was found. No installation required.`
` > The "${this.appSchemaCollectionName}" collection was found. No installation required.`,
);
}
}
Expand All @@ -379,7 +379,7 @@ export class MongoUpdater implements IMongoUpdater {
if (semver.gte(currentAppSchemaVersion, targetVersion)) {
// tslint:disable-next-line: prefer-template
logger.info(
' > Current database app schema is up to date : ' + currentAppSchemaVersion + ').'
' > Current database app schema is up to date : ' + currentAppSchemaVersion + ').',
);
return;
}
Expand All @@ -395,7 +395,7 @@ export class MongoUpdater implements IMongoUpdater {
const wait = 1000;
logger.warning(
`The lock can't be acquired. The maximum age it can be before being considered ` +
`to be too old is ${this.lockMaxAgeSeconds} seconds. Waiting for ${wait} milliseconds...`
`to be too old is ${this.lockMaxAgeSeconds} seconds. Waiting for ${wait} milliseconds...`,
);
await utils.sleep(wait);
} else {
Expand Down
Loading
Loading