Skip to content

Commit a821fcf

Browse files
committed
add more test for input_truncated
1 parent f9bd84e commit a821fcf

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/dd-trace/test/appsec/telemetry/waf.spec.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ describe('Appsec Waf Telemetry metrics', () => {
270270

271271
describe('WAF Truncation metrics', () => {
272272
it('should report truncated string metrics', () => {
273-
appsecTelemetry.updateWafRequestsMetricTags({ maxTruncatedString: 5000 }, req)
273+
const result = appsecTelemetry.updateWafRequestsMetricTags({ maxTruncatedString: 5000 }, req)
274+
expect(result).to.have.property('input_truncated', true)
274275

275276
expect(count).to.have.been.calledWith('waf.input_truncated', { truncation_reason: 1 })
276277
expect(inc).to.have.been.calledWith(1)
@@ -280,7 +281,8 @@ describe('Appsec Waf Telemetry metrics', () => {
280281
})
281282

282283
it('should report truncated container size metrics', () => {
283-
appsecTelemetry.updateWafRequestsMetricTags({ maxTruncatedContainerSize: 300 }, req)
284+
const result = appsecTelemetry.updateWafRequestsMetricTags({ maxTruncatedContainerSize: 300 }, req)
285+
expect(result).to.have.property('input_truncated', true)
284286

285287
expect(count).to.have.been.calledWith('waf.input_truncated', { truncation_reason: 2 })
286288
expect(inc).to.have.been.calledWith(1)
@@ -290,7 +292,8 @@ describe('Appsec Waf Telemetry metrics', () => {
290292
})
291293

292294
it('should report truncated container depth metrics', () => {
293-
appsecTelemetry.updateWafRequestsMetricTags({ maxTruncatedContainerDepth: 20 }, req)
295+
const result = appsecTelemetry.updateWafRequestsMetricTags({ maxTruncatedContainerDepth: 20 }, req)
296+
expect(result).to.have.property('input_truncated', true)
294297

295298
expect(count).to.have.been.calledWith('waf.input_truncated', { truncation_reason: 4 })
296299
expect(inc).to.have.been.calledWith(1)
@@ -300,11 +303,12 @@ describe('Appsec Waf Telemetry metrics', () => {
300303
})
301304

302305
it('should combine truncation reasons when multiple truncations occur', () => {
303-
appsecTelemetry.updateWafRequestsMetricTags({
306+
const result = appsecTelemetry.updateWafRequestsMetricTags({
304307
maxTruncatedString: 5000,
305308
maxTruncatedContainerSize: 300,
306309
maxTruncatedContainerDepth: 20
307310
}, req)
311+
expect(result).to.have.property('input_truncated', true)
308312

309313
expect(count).to.have.been.calledWith('waf.input_truncated', { truncation_reason: 7 })
310314
expect(distribution).to.have.been.calledWith('waf.truncated_value_size', { truncation_reason: 1 })
@@ -313,7 +317,8 @@ describe('Appsec Waf Telemetry metrics', () => {
313317
})
314318

315319
it('should not report truncation metrics when no truncation occurs', () => {
316-
appsecTelemetry.updateWafRequestsMetricTags(metrics, req)
320+
const result = appsecTelemetry.updateWafRequestsMetricTags(metrics, req)
321+
expect(result).to.have.property('input_truncated', false)
317322

318323
expect(count).to.not.have.been.calledWith('waf.input_truncated')
319324
expect(distribution).to.not.have.been.calledWith('waf.truncated_value_size')

0 commit comments

Comments
 (0)