@@ -30,6 +30,11 @@ describe('Appsec Waf Telemetry metrics', () => {
30
30
afterEach ( sinon . restore )
31
31
32
32
describe ( 'if enabled' , ( ) => {
33
+ const metrics = {
34
+ wafVersion,
35
+ rulesVersion
36
+ }
37
+
33
38
beforeEach ( ( ) => {
34
39
appsecTelemetry . enable ( {
35
40
enabled : true ,
@@ -38,11 +43,6 @@ describe('Appsec Waf Telemetry metrics', () => {
38
43
} )
39
44
40
45
describe ( 'updateWafRequestsMetricTags' , ( ) => {
41
- const metrics = {
42
- wafVersion,
43
- rulesVersion
44
- }
45
-
46
46
it ( 'should skip update if no request is provided' , ( ) => {
47
47
const result = appsecTelemetry . updateWafRequestsMetricTags ( metrics )
48
48
@@ -57,7 +57,8 @@ describe('Appsec Waf Telemetry metrics', () => {
57
57
event_rules_version : rulesVersion ,
58
58
request_blocked : false ,
59
59
rule_triggered : false ,
60
- waf_timeout : false
60
+ waf_timeout : false ,
61
+ input_truncated : false
61
62
} )
62
63
} )
63
64
@@ -66,6 +67,7 @@ describe('Appsec Waf Telemetry metrics', () => {
66
67
blockTriggered : true ,
67
68
ruleTriggered : true ,
68
69
wafTimeout : true ,
70
+ maxTruncatedString : 5000 ,
69
71
...metrics
70
72
} , req )
71
73
@@ -74,7 +76,8 @@ describe('Appsec Waf Telemetry metrics', () => {
74
76
event_rules_version : rulesVersion ,
75
77
request_blocked : true ,
76
78
rule_triggered : true ,
77
- waf_timeout : true
79
+ waf_timeout : true ,
80
+ input_truncated : true
78
81
} )
79
82
} )
80
83
@@ -93,7 +96,8 @@ describe('Appsec Waf Telemetry metrics', () => {
93
96
event_rules_version : rulesVersion ,
94
97
request_blocked : false ,
95
98
rule_triggered : true ,
96
- waf_timeout : false
99
+ waf_timeout : false ,
100
+ input_truncated : false
97
101
} )
98
102
} )
99
103
@@ -102,6 +106,7 @@ describe('Appsec Waf Telemetry metrics', () => {
102
106
blockTriggered : true ,
103
107
ruleTriggered : true ,
104
108
wafTimeout : true ,
109
+ maxTruncatedContainerSize : 300 ,
105
110
...metrics
106
111
} , req )
107
112
@@ -120,7 +125,8 @@ describe('Appsec Waf Telemetry metrics', () => {
120
125
event_rules_version : rulesVersion ,
121
126
request_blocked : true ,
122
127
rule_triggered : true ,
123
- waf_timeout : true
128
+ waf_timeout : true ,
129
+ input_truncated : true
124
130
} )
125
131
} )
126
132
@@ -250,7 +256,8 @@ describe('Appsec Waf Telemetry metrics', () => {
250
256
rule_triggered : false ,
251
257
waf_timeout : true ,
252
258
waf_version : wafVersion ,
253
- event_rules_version : rulesVersion
259
+ event_rules_version : rulesVersion ,
260
+ input_truncated : false
254
261
} )
255
262
} )
256
263
@@ -260,6 +267,63 @@ describe('Appsec Waf Telemetry metrics', () => {
260
267
expect ( count ) . to . not . have . been . called
261
268
} )
262
269
} )
270
+
271
+ describe ( 'WAF Truncation metrics' , ( ) => {
272
+ it ( 'should report truncated string metrics' , ( ) => {
273
+ const result = appsecTelemetry . updateWafRequestsMetricTags ( { maxTruncatedString : 5000 } , req )
274
+ expect ( result ) . to . have . property ( 'input_truncated' , true )
275
+
276
+ expect ( count ) . to . have . been . calledWith ( 'waf.input_truncated' , { truncation_reason : 1 } )
277
+ expect ( inc ) . to . have . been . calledWith ( 1 )
278
+
279
+ expect ( distribution ) . to . have . been . calledWith ( 'waf.truncated_value_size' , { truncation_reason : 1 } )
280
+ expect ( track ) . to . have . been . calledWith ( 5000 )
281
+ } )
282
+
283
+ it ( 'should report truncated container size metrics' , ( ) => {
284
+ const result = appsecTelemetry . updateWafRequestsMetricTags ( { maxTruncatedContainerSize : 300 } , req )
285
+ expect ( result ) . to . have . property ( 'input_truncated' , true )
286
+
287
+ expect ( count ) . to . have . been . calledWith ( 'waf.input_truncated' , { truncation_reason : 2 } )
288
+ expect ( inc ) . to . have . been . calledWith ( 1 )
289
+
290
+ expect ( distribution ) . to . have . been . calledWith ( 'waf.truncated_value_size' , { truncation_reason : 2 } )
291
+ expect ( track ) . to . have . been . calledWith ( 300 )
292
+ } )
293
+
294
+ it ( 'should report truncated container depth metrics' , ( ) => {
295
+ const result = appsecTelemetry . updateWafRequestsMetricTags ( { maxTruncatedContainerDepth : 20 } , req )
296
+ expect ( result ) . to . have . property ( 'input_truncated' , true )
297
+
298
+ expect ( count ) . to . have . been . calledWith ( 'waf.input_truncated' , { truncation_reason : 4 } )
299
+ expect ( inc ) . to . have . been . calledWith ( 1 )
300
+
301
+ expect ( distribution ) . to . have . been . calledWith ( 'waf.truncated_value_size' , { truncation_reason : 4 } )
302
+ expect ( track ) . to . have . been . calledWith ( 20 )
303
+ } )
304
+
305
+ it ( 'should combine truncation reasons when multiple truncations occur' , ( ) => {
306
+ const result = appsecTelemetry . updateWafRequestsMetricTags ( {
307
+ maxTruncatedString : 5000 ,
308
+ maxTruncatedContainerSize : 300 ,
309
+ maxTruncatedContainerDepth : 20
310
+ } , req )
311
+ expect ( result ) . to . have . property ( 'input_truncated' , true )
312
+
313
+ expect ( count ) . to . have . been . calledWith ( 'waf.input_truncated' , { truncation_reason : 7 } )
314
+ expect ( distribution ) . to . have . been . calledWith ( 'waf.truncated_value_size' , { truncation_reason : 1 } )
315
+ expect ( distribution ) . to . have . been . calledWith ( 'waf.truncated_value_size' , { truncation_reason : 2 } )
316
+ expect ( distribution ) . to . have . been . calledWith ( 'waf.truncated_value_size' , { truncation_reason : 4 } )
317
+ } )
318
+
319
+ it ( 'should not report truncation metrics when no truncation occurs' , ( ) => {
320
+ const result = appsecTelemetry . updateWafRequestsMetricTags ( metrics , req )
321
+ expect ( result ) . to . have . property ( 'input_truncated' , false )
322
+
323
+ expect ( count ) . to . not . have . been . calledWith ( 'waf.input_truncated' )
324
+ expect ( distribution ) . to . not . have . been . calledWith ( 'waf.truncated_value_size' )
325
+ } )
326
+ } )
263
327
} )
264
328
265
329
describe ( 'if disabled' , ( ) => {
0 commit comments