Skip to content

Commit 7954ef0

Browse files
committed
ut
1 parent bc84226 commit 7954ef0

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

dd-java-agent/appsec/src/test/groovy/com/datadog/appsec/gateway/AppSecRequestContextSpecification.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,17 @@ class AppSecRequestContextSpecification extends DDSpecification {
303303
ctx.getRaspError(AppSecRequestContext.DD_WAF_RUN_INVALID_ARGUMENT_ERROR) == 0
304304
ctx.getRaspError(0) == 0
305305
}
306+
307+
def "test increase and get WafErrors"() {
308+
when:
309+
ctx.increaseWafErrorCode(-3)
310+
ctx.increaseWafErrorCode(-3)
311+
ctx.increaseWafErrorCode(-2)
312+
313+
then:
314+
ctx.getWafError(-3) == 2
315+
ctx.getWafError(-2) == 1
316+
ctx.getWafError(-1) == 0
317+
ctx.getWafError(0) == 0
318+
}
306319
}

internal-api/src/test/groovy/datadog/trace/api/telemetry/WafMetricCollectorTest.groovy

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class WafMetricCollectorTest extends DDSpecification {
3636
WafMetricCollector.get().raspRuleEval(RuleType.SQL_INJECTION)
3737
WafMetricCollector.get().raspTimeout(RuleType.SQL_INJECTION)
3838
WafMetricCollector.get().raspErrorCode(RuleType.SHELL_INJECTION, DD_WAF_RUN_INTERNAL_ERROR)
39+
WafMetricCollector.get().wafErrorCode(RuleType.SHELL_INJECTION, DD_WAF_RUN_INTERNAL_ERROR)
3940
WafMetricCollector.get().raspErrorCode(RuleType.SQL_INJECTION, DD_WAF_RUN_INVALID_OBJECT_ERROR)
41+
WafMetricCollector.get().wafErrorCode(RuleType.SQL_INJECTION, DD_WAF_RUN_INVALID_OBJECT_ERROR)
4042

4143
WafMetricCollector.get().prepareMetrics()
4244

@@ -150,7 +152,20 @@ class WafMetricCollectorTest extends DDSpecification {
150152
'waf_error:' + DD_WAF_RUN_INTERNAL_ERROR
151153
].toSet()
152154

153-
def raspInvalidObjectCode = (WafMetricCollector.RaspError)metrics[11]
155+
def wafInvalidCode = (WafMetricCollector.WafError)metrics[11]
156+
wafInvalidCode.type == 'count'
157+
wafInvalidCode.value == 1
158+
wafInvalidCode.namespace == 'appsec'
159+
wafInvalidCode.metricName == 'waf.error'
160+
wafInvalidCode.tags.toSet() == [
161+
'waf_version:waf_ver1',
162+
'rule_type:command_injection',
163+
'rule_variant:shell',
164+
'event_rules_version:rules.3',
165+
'waf_error:' +DD_WAF_RUN_INTERNAL_ERROR
166+
].toSet()
167+
168+
def raspInvalidObjectCode = (WafMetricCollector.RaspError)metrics[12]
154169
raspInvalidObjectCode.type == 'count'
155170
raspInvalidObjectCode.value == 1
156171
raspInvalidObjectCode.namespace == 'appsec'
@@ -161,6 +176,15 @@ class WafMetricCollectorTest extends DDSpecification {
161176
'waf_error:' + DD_WAF_RUN_INVALID_OBJECT_ERROR
162177
]
163178
.toSet()
179+
180+
def wafInvalidObjectCode = (WafMetricCollector.WafError)metrics[13]
181+
wafInvalidObjectCode.type == 'count'
182+
wafInvalidObjectCode.value == 1
183+
wafInvalidObjectCode.namespace == 'appsec'
184+
wafInvalidObjectCode.metricName == 'waf.error'
185+
wafInvalidObjectCode.tags.toSet() == ['rule_type:sql_injection', 'waf_version:waf_ver1',
186+
'waf_error:'+DD_WAF_RUN_INVALID_OBJECT_ERROR].toSet()
187+
164188
}
165189

166190
def "overflowing WafMetricCollector does not crash"() {
@@ -335,6 +359,7 @@ class WafMetricCollectorTest extends DDSpecification {
335359
WafMetricCollector.get().raspRuleEval(ruleType)
336360
WafMetricCollector.get().raspTimeout(ruleType)
337361
WafMetricCollector.get().raspErrorCode(ruleType, DD_WAF_RUN_INTERNAL_ERROR)
362+
WafMetricCollector.get().wafErrorCode(ruleType, DD_WAF_RUN_INTERNAL_ERROR)
338363
WafMetricCollector.get().prepareMetrics()
339364

340365
then:
@@ -389,6 +414,19 @@ class WafMetricCollectorTest extends DDSpecification {
389414
'waf_error:' + DD_WAF_RUN_INTERNAL_ERROR
390415
].toSet()
391416

417+
def wafInvalidCode = (WafMetricCollector.WafError)metrics[5]
418+
wafInvalidCode.type == 'count'
419+
wafInvalidCode.value == 1
420+
wafInvalidCode.namespace == 'appsec'
421+
wafInvalidCode.metricName == 'waf.error'
422+
wafInvalidCode.tags.toSet() == [
423+
'waf_version:waf_ver1',
424+
'rule_type:command_injection',
425+
'rule_variant:' + ruleType.variant,
426+
'event_rules_version:rules.1',
427+
'waf_error:-3'
428+
].toSet()
429+
392430
where:
393431
ruleType << [RuleType.COMMAND_INJECTION, RuleType.SHELL_INJECTION]
394432
}

0 commit comments

Comments
 (0)