Skip to content

Commit 05f01a0

Browse files
authored
chore(test): Fixing flaky rasp ssrf express tests (#7617)
1 parent 6ae97d5 commit 05f01a0

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

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

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,19 @@ describe('RASP - ssrf', () => {
5757

5858
describe('ssrf', () => {
5959
async function testBlockingRequest () {
60-
try {
61-
await axios.get('/?host=localhost/ifconfig.pro')
62-
} catch (e) {
60+
const assertPromise = checkRaspExecutedAndHasThreat(agent, 'rasp-ssrf-rule-id-1')
61+
const blockingRequestPromise = axios.get('/?host=localhost/ifconfig.pro').then(() => {
62+
assert.fail('Request should be blocked')
63+
}).catch(e => {
6364
if (!e.response) {
6465
throw e
6566
}
67+
})
6668

67-
return checkRaspExecutedAndHasThreat(agent, 'rasp-ssrf-rule-id-1')
68-
}
69-
70-
assert.fail('Request should be blocked')
69+
await Promise.all([
70+
blockingRequestPromise,
71+
assertPromise,
72+
])
7173
}
7274

7375
['http', 'https'].forEach(protocol => {
@@ -77,14 +79,18 @@ describe('RASP - ssrf', () => {
7779
const module = require(protocol)
7880

7981
app = (req, res) => {
80-
const clientRequest = module.get(`${protocol}://${req.query.host}`)
82+
const clientRequest = module.get(`${protocol}://${req.query.host}`, function (incomingResponse) {
83+
incomingResponse.resume()
84+
res.end('end')
85+
})
86+
8187
clientRequest.on('error', noop)
82-
res.end('end')
8388
}
8489

85-
axios.get('/?host=www.datadoghq.com')
86-
87-
return checkRaspExecutedAndNotThreat(agent)
90+
await Promise.all([
91+
checkRaspExecutedAndNotThreat(agent),
92+
axios.get('/?host=www.datadoghq.com'),
93+
])
8894
})
8995

9096
it('Should detect threat doing a GET request', async () => {
@@ -140,9 +146,10 @@ describe('RASP - ssrf', () => {
140146
.then(() => res.end('end'))
141147
}
142148

143-
await axios.get('/?host=www.datadoghq.com')
144-
145-
return checkRaspExecutedAndNotThreat(agent)
149+
await Promise.all([
150+
axios.get('/?host=www.datadoghq.com'),
151+
checkRaspExecutedAndNotThreat(agent),
152+
])
146153
})
147154

148155
it('Should detect threat doing a GET request', async () => {
@@ -193,9 +200,10 @@ describe('RASP - ssrf', () => {
193200
})
194201
}
195202

196-
axios.get('/?host=www.datadoghq.com')
197-
198-
return checkRaspExecutedAndNotThreat(agent)
203+
await Promise.all([
204+
axios.get('/?host=www.datadoghq.com'),
205+
checkRaspExecutedAndNotThreat(agent),
206+
])
199207
})
200208

201209
it('Should detect threat doing a GET request', async () => {

0 commit comments

Comments
 (0)