Skip to content

Commit

Permalink
Fix circular dependencies in waf calls (#4125)
Browse files Browse the repository at this point in the history
  • Loading branch information
uurien committed Mar 7, 2024
1 parent ae671d5 commit 78d56b9
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"node": ">=16"
},
"dependencies": {
"@datadog/native-appsec": "7.0.0",
"@datadog/native-appsec": "7.1.0",
"@datadog/native-iast-rewriter": "2.2.3",
"@datadog/native-iast-taint-tracking": "1.7.0",
"@datadog/native-metrics": "^2.0.0",
Expand Down
93 changes: 93 additions & 0 deletions packages/dd-trace/test/appsec/index.sequelize.plugin.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
'use strict'

const path = require('path')
const axios = require('axios')
const getPort = require('get-port')
const agent = require('../plugins/agent')
const appsec = require('../../src/appsec')
const Config = require('../../src/config')

describe('sequelize', () => {
withVersions('sequelize', 'sequelize', sequelizeVersion => {
withVersions('mysql2', 'mysql2', () => {
withVersions('sequelize', 'express', (expressVersion) => {
let sequelize, User, server, port

// init tracer
before(async () => {
await agent.load(['express', 'http'], { client: false }, { flushInterval: 1 })
appsec.enable(new Config({
appsec: {
enabled: true,
rules: path.join(__dirname, 'express-rules.json'),
apiSecurity: {
enabled: true,
requestSampling: 1
}
}
}))
})

// close agent
after(() => {
appsec.disable()
return agent.close()
})

// init database
before(async () => {
const { Sequelize, DataTypes } = require(`../../../../versions/sequelize@${sequelizeVersion}`).get()

sequelize = new Sequelize('db', 'root', '', {
host: '127.0.0.1',
dialect: 'mysql'
})
User = sequelize.define('User', {
username: DataTypes.STRING,
birthday: DataTypes.DATE
})

await sequelize.sync({ force: true })
await User.create({
username: 'janedoe',
birthday: new Date(1980, 6, 20)
})
})

// clean database
after(async () => {
await User.drop()
})

// init express
before((done) => {
const express = require(`../../../../versions/express@${expressVersion}`).get()

const app = express()
app.get('/users', async (req, res) => {
const users = await User.findAll()
res.json(users)
})

getPort().then(newPort => {
port = newPort
server = app.listen(newPort, () => {
done()
})
})
})

// stop express
after(() => {
return server.close()
})

it('Should complete the request on time', (done) => {
axios.get(`http://localhost:${port}/users`)
.then(() => done())
.catch(done)
})
})
})
})
})
6 changes: 6 additions & 0 deletions packages/dd-trace/test/plugins/externals.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,11 @@
"name": "redis",
"versions": ["^4"]
}
],
"sequelize": [
{
"name": "express",
"versions": [">=4"]
}
]
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@
resolved "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz"
integrity "sha1-u1BFecHK6SPmV2pPXaQ9Jfl729k= sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ=="

"@datadog/native-appsec@7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@datadog/native-appsec/-/native-appsec-7.0.0.tgz#a380174dd49aef2d9bb613a0ec8ead6dc7822095"
integrity sha512-bywstWFW2hWxzPuS0+mFMVHHL0geulx5yQFtsjfszaH2LTAgk2D+Rt40MKbAoZ8q3tRw2dy6aYQ7svO3ca8jpA==
"@datadog/native-appsec@7.1.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@datadog/native-appsec/-/native-appsec-7.1.0.tgz#e8e6254236ac6fd7d4fb8b1156b34de64ec3e174"
integrity sha512-5FATunIxmvuSGDwPmbXfOi21wC7rjfbdLX4QiT5LR+iRLjRLT5iETqwdTsqy0WOQIHmxdWuddRvuakAg3921aA==
dependencies:
node-gyp-build "^3.9.0"

Expand Down

0 comments on commit 78d56b9

Please sign in to comment.