Skip to content

Commit cc38d6d

Browse files
committed
Check for header names in integration test
1 parent 3f7bc24 commit cc38d6d

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

integration-tests/appsec/data-collection.spec.js

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ describe('ASM Data collection', () => {
5959
// Request headers
6060
assert.equal(
6161
Object.keys(payload[0][0].meta).filter(tagName => tagName.startsWith('http.request.headers.')).length,
62-
Object.keys(requestHeaders).length
62+
requestHeaders.length
6363
)
64-
Object.entries(requestHeaders).forEach(([headerName, headerValue]) => {
65-
assert.equal(payload[0][0].meta[`http.request.headers.${headerName}`], headerValue)
64+
requestHeaders.forEach((headerName) => {
65+
assert.property(payload[0][0].meta, `http.request.headers.${headerName}`)
6666
})
6767

6868
// Response headers
6969
assert.equal(
7070
Object.keys(payload[0][0].meta).filter(tagName => tagName.startsWith('http.response.headers.')).length,
71-
Object.keys(responseHeaders).length
71+
responseHeaders.length
7272
)
73-
Object.entries(responseHeaders).forEach(([headerName, headerValue]) => {
74-
assert.equal(payload[0][0].meta[`http.response.headers.${headerName}`], headerValue)
73+
responseHeaders.forEach((headerName) => {
74+
assert.property(payload[0][0].meta, `http.response.headers.${headerName}`)
7575
})
7676
})
7777
}
@@ -80,17 +80,17 @@ describe('ASM Data collection', () => {
8080
startServer(false)
8181

8282
it('should collect event headers', async () => {
83-
const expectedRequestHeaders = {
84-
'user-agent': 'Arachni/v1',
85-
accept: 'application/json, text/plain, */*',
86-
host: `localhost:${appPort}`,
87-
'accept-encoding': 'gzip, compress, deflate, br'
88-
}
89-
90-
const expectedResponseHeaders = {
91-
'content-type': 'text/plain; charset=utf-8',
92-
'content-language': 'en'
93-
}
83+
const expectedRequestHeaders = [
84+
'user-agent',
85+
'accept',
86+
'host',
87+
'accept-encoding'
88+
]
89+
90+
const expectedResponseHeaders = [
91+
'content-type',
92+
'content-language'
93+
]
9494

9595
await axios.get('/', { headers: { 'User-Agent': 'Arachni/v1' } })
9696
await assertHeadersReported(expectedRequestHeaders, expectedResponseHeaders)
@@ -101,24 +101,22 @@ describe('ASM Data collection', () => {
101101
startServer(true)
102102

103103
it('should collect extended headers', async () => {
104-
const expectedRequestHeaders = {
105-
'user-agent': 'Arachni/v1',
106-
accept: 'application/json, text/plain, */*',
107-
host: `localhost:${appPort}`,
108-
'accept-encoding': 'gzip, compress, deflate, br',
109-
connection: 'keep-alive'
110-
}
111-
112-
const expectedResponseHeaders = {
113-
...Object.fromEntries(
114-
Array.from({ length: 22 }, (_, i) =>
115-
[`x-datadog-res-${i}`, `ext-res-${i}`]
116-
)
104+
const expectedRequestHeaders = [
105+
'user-agent',
106+
'accept',
107+
'host',
108+
'accept-encoding',
109+
'connection'
110+
]
111+
112+
const expectedResponseHeaders = [
113+
...Array.from({ length: 22 }, (_, i) =>
114+
`x-datadog-res-${i}`
117115
),
118-
'x-powered-by': 'Express',
119-
'content-type': 'text/plain; charset=utf-8',
120-
'content-language': 'en'
121-
}
116+
'x-powered-by',
117+
'content-type',
118+
'content-language'
119+
]
122120

123121
await axios.get('/', { headers: { 'User-Agent': 'Arachni/v1' } })
124122
await assertHeadersReported(expectedRequestHeaders, expectedResponseHeaders)

0 commit comments

Comments
 (0)