@@ -8,6 +8,9 @@ import java.util.concurrent.TimeUnit
8
8
9
9
class WafMetricCollectorTest extends DDSpecification {
10
10
11
+ public static final int DD_WAF_RUN_INTERNAL_ERROR = -3
12
+ public static final int DD_WAF_RUN_INVALID_OBJECT_ERROR = -2
13
+
11
14
def " no metrics - drain empty list" () {
12
15
when :
13
16
WafMetricCollector . get(). prepareMetrics()
@@ -32,8 +35,8 @@ class WafMetricCollectorTest extends DDSpecification {
32
35
WafMetricCollector . get(). raspRuleMatch(RuleType . SQL_INJECTION )
33
36
WafMetricCollector . get(). raspRuleEval(RuleType . SQL_INJECTION )
34
37
WafMetricCollector . get(). raspTimeout(RuleType . SQL_INJECTION )
35
- WafMetricCollector . get(). raspErrorCode(RuleType . SHELL_INJECTION , -3 )
36
- WafMetricCollector . get(). raspErrorCode(RuleType . SQL_INJECTION , -2 )
38
+ WafMetricCollector . get(). raspErrorCode(RuleType . SHELL_INJECTION , DD_WAF_RUN_INTERNAL_ERROR )
39
+ WafMetricCollector . get(). raspErrorCode(RuleType . SQL_INJECTION , DD_WAF_RUN_INVALID_OBJECT_ERROR )
37
40
38
41
WafMetricCollector . get(). prepareMetrics()
39
42
@@ -144,15 +147,20 @@ class WafMetricCollectorTest extends DDSpecification {
144
147
' rule_type:command_injection' ,
145
148
' rule_variant:shell' ,
146
149
' event_rules_version:rules.3' ,
147
- ' waf_error:-3 '
150
+ ' waf_error:' + DD_WAF_RUN_INTERNAL_ERROR
148
151
]. toSet()
149
152
150
153
def raspInvalidObjectCode = (WafMetricCollector.RaspError )metrics[11 ]
151
154
raspInvalidObjectCode. type == ' count'
152
155
raspInvalidObjectCode. value == 1
153
156
raspInvalidObjectCode. namespace == ' appsec'
154
157
raspInvalidObjectCode. metricName == ' rasp.error'
155
- raspInvalidObjectCode. tags. toSet() == [' rule_type:sql_injection' , ' waf_version:waf_ver1' , ' waf_error:-2' ]. toSet()
158
+ raspInvalidObjectCode. tags. toSet() == [
159
+ ' rule_type:sql_injection' ,
160
+ ' waf_version:waf_ver1' ,
161
+ ' waf_error:' + DD_WAF_RUN_INVALID_OBJECT_ERROR
162
+ ]
163
+ .toSet()
156
164
}
157
165
158
166
def " overflowing WafMetricCollector does not crash" () {
@@ -326,7 +334,7 @@ class WafMetricCollectorTest extends DDSpecification {
326
334
WafMetricCollector . get(). raspRuleMatch(ruleType)
327
335
WafMetricCollector . get(). raspRuleEval(ruleType)
328
336
WafMetricCollector . get(). raspTimeout(ruleType)
329
- WafMetricCollector . get(). raspErrorCode(ruleType, -3 )
337
+ WafMetricCollector . get(). raspErrorCode(ruleType, DD_WAF_RUN_INTERNAL_ERROR )
330
338
WafMetricCollector . get(). prepareMetrics()
331
339
332
340
then :
@@ -378,7 +386,7 @@ class WafMetricCollectorTest extends DDSpecification {
378
386
' rule_type:command_injection' ,
379
387
' rule_variant:' + ruleType. variant,
380
388
' event_rules_version:rules.1' ,
381
- ' waf_error:-3 '
389
+ ' waf_error:' + DD_WAF_RUN_INTERNAL_ERROR
382
390
]. toSet()
383
391
384
392
where :
0 commit comments