Skip to content

Commit bab39ed

Browse files
authored
test(appsec): deflake RASP SSRF "should not detect threat" express tests (#9417)
* test(appsec): deflake RASP SSRF "should not detect threat" express tests * test(appsec): disable proxy on RASP SSRF outbound "not detect threat" requests
1 parent c85534e commit bab39ed

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

packages/dd-trace/test/appsec/rasp/ssrf.express.plugin.spec.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const { checkRaspExecutedAndNotThreat, checkRaspExecutedAndHasThreat } = require
1515

1616
function noop () {}
1717

18+
const UNRESOLVABLE_HOST = 'not-a-threat.invalid'
19+
1820
describe('RASP - ssrf', () => {
1921
withVersions('express', 'express', expressVersion => {
2022
let app, server, axios
@@ -84,12 +86,12 @@ describe('RASP - ssrf', () => {
8486
res.end('end')
8587
})
8688

87-
clientRequest.on('error', noop)
89+
clientRequest.on('error', () => res.end('end'))
8890
}
8991

9092
await Promise.all([
9193
checkRaspExecutedAndNotThreat(agent),
92-
axios.get('/?host=www.datadoghq.com'),
94+
axios.get(`/?host=${UNRESOLVABLE_HOST}`),
9395
])
9496
})
9597

@@ -146,13 +148,13 @@ describe('RASP - ssrf', () => {
146148

147149
it('Should not detect threat', async () => {
148150
app = (req, res) => {
149-
axiosToTest.get(`https://${req.query.host}`)
151+
axiosToTest.get(`https://${req.query.host}`, { proxy: false })
150152
.catch(noop) // swallow network error
151153
.then(() => res.end('end'))
152154
}
153155

154156
await Promise.all([
155-
axios.get('/?host=www.datadoghq.com'),
157+
axios.get(`/?host=${UNRESOLVABLE_HOST}`),
156158
checkRaspExecutedAndNotThreat(agent),
157159
])
158160
})
@@ -200,13 +202,13 @@ describe('RASP - ssrf', () => {
200202

201203
it('Should not detect threat', async () => {
202204
app = (req, res) => {
203-
requestToTest.get(`https://${req.query.host}`).on('response', () => {
204-
res.end('end')
205-
})
205+
requestToTest.get(`https://${req.query.host}`, { proxy: false })
206+
.on('response', () => res.end('end'))
207+
.on('error', () => res.end('end'))
206208
}
207209

208210
await Promise.all([
209-
axios.get('/?host=www.datadoghq.com'),
211+
axios.get(`/?host=${UNRESOLVABLE_HOST}`),
210212
checkRaspExecutedAndNotThreat(agent),
211213
])
212214
})

0 commit comments

Comments
 (0)