Skip to content

Commit

Permalink
fix mongoose tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasShabi committed Nov 27, 2024
1 parent 1d4f0e4 commit 55b322d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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()
})

Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/plugins/externals.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 55b322d

Please sign in to comment.