diff --git a/packages/dd-trace/test/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.mongoose.plugin.spec.js b/packages/dd-trace/test/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.mongoose.plugin.spec.js index f8b96557a1..75337c63b3 100644 --- a/packages/dd-trace/test/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.mongoose.plugin.spec.js +++ b/packages/dd-trace/test/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.mongoose.plugin.spec.js @@ -10,8 +10,7 @@ const fs = require('fs') const { NODE_MAJOR } = require('../../../../../../version') describe('nosql injection detection in mongodb - whole feature', () => { - // https://github.com/fiznool/express-mongo-sanitize/issues/200 - withVersions('mongoose', 'express', '>4.18.0 <5.0.0', expressVersion => { + withVersions('mongoose', 'express', expressVersion => { withVersions('mongoose', 'mongoose', '>4.0.0', mongooseVersion => { const specificMongooseVersion = require(`../../../../../../versions/mongoose@${mongooseVersion}`).version() if (NODE_MAJOR === 14 && semver.satisfies(specificMongooseVersion, '>=8')) return @@ -28,11 +27,16 @@ describe('nosql injection detection in mongodb - whole feature', () => { const dbName = id().toString() mongoose = require(`../../../../../../versions/mongoose@${mongooseVersion}`).get() - mongoose.connect(`mongodb://localhost:27017/${dbName}`, { + await mongoose.connect(`mongodb://localhost:27017/${dbName}`, { useNewUrlParser: true, useUnifiedTopology: true }) + if (mongoose.models.Test) { + delete mongoose.models?.Test + delete mongoose.modelSchemas?.Test + } + Test = mongoose.model('Test', { name: String }) const src = path.join(__dirname, 'resources', vulnerableMethodFilename) @@ -47,7 +51,12 @@ describe('nosql injection detection in mongodb - whole feature', () => { }) after(() => { - fs.unlinkSync(tmpFilePath) + try { + fs.unlinkSync(tmpFilePath) + } catch (e) { + // ignore the error + } + return mongoose.disconnect() }) diff --git a/packages/dd-trace/test/plugins/externals.json b/packages/dd-trace/test/plugins/externals.json index 7e1c0f9163..288fb9350c 100644 --- a/packages/dd-trace/test/plugins/externals.json +++ b/packages/dd-trace/test/plugins/externals.json @@ -332,7 +332,7 @@ }, { "name": "express", - "versions": [">=4", ">=4.0.0 <4.3.0", ">=4.0.0 <5.0.0", ">=4.3.0 <5.0.0", ">=5.0.0"] + "versions": [">=4", ">=4.0.0 <4.3.0", ">=4.0.0 <5.0.0", ">=4.3.0 <5.0.0"] }, { "name": "body-parser",