@@ -17,6 +17,7 @@ import com.datadog.appsec.event.data.MapDataBundle
1717import com.datadog.appsec.gateway.AppSecRequestContext
1818import com.datadog.appsec.gateway.GatewayContext
1919import com.datadog.appsec.report.AppSecEvent
20+ import datadog.trace.api.telemetry.RuleType
2021import datadog.trace.util.stacktrace.StackTraceEvent
2122import com.datadog.appsec.test.StubAppSecConfigService
2223import datadog.communication.monitor.Monitoring
@@ -959,7 +960,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
959960 assert ! flow. blocking
960961 }
961962
962- void ' timeout is honored' () {
963+ void 'timeout is honored ( waf ) ' () {
963964 setup:
964965 injectSysConfig(' appsec. waf. timeout' , ' 1 ' )
965966 PowerWAFModule.createLimitsObject()
@@ -981,8 +982,13 @@ class PowerWAFModuleSpecification extends DDSpecification {
981982 ctx.getOrCreateAdditive(_, true) >> {
982983 pwafAdditive = it[0].openAdditive() }
983984 assert !flow.blocking
984- 1 * ctx. increaseTimeouts()
985+ 1 * ctx.isAdditiveClosed()
986+ 1 * ctx.getOrCreateAdditive(_, true, false) >> {
987+ pwafAdditive = it[0].openAdditive() }
988+ 1 * ctx.getWafMetrics()
989+ 1 * ctx.increaseWafTimeouts()
985990 1 * mockWafMetricCollector.get().wafRequestTimeout()
991+ 0 * _
986992
987993 when:
988994 pp.processTraceSegment(segment, ctx, [])
@@ -996,6 +1002,53 @@ class PowerWAFModuleSpecification extends DDSpecification {
9961002 PowerWAFModule.createLimitsObject()
9971003 }
9981004
1005+ void ' timeout is honored (rasp)' () {
1006+ setup:
1007+ injectSysConfig(' appsec. waf. timeout' , ' 1 ' )
1008+ PowerWAFModule.createLimitsObject()
1009+ setupWithStubConfigService()
1010+ DataBundle db = MapDataBundle.of(KnownAddresses.HEADERS_NO_COOKIES,
1011+ new CaseInsensitiveMap<List<String>>([' user- agent' : ' Arachni / v' + (' a' * 4000)]))
1012+ ChangeableFlow flow = new ChangeableFlow()
1013+
1014+ TraceSegment segment = Mock()
1015+ TraceSegmentPostProcessor pp = service.traceSegmentPostProcessors.last()
1016+
1017+ def mockWafMetricCollector = Mock(WafMetricCollector)
1018+ WafMetricCollector.INSTANCE = mockWafMetricCollector
1019+
1020+ gwCtx = new GatewayContext(false, RuleType.SQL_INJECTION)
1021+
1022+ when:
1023+ dataListener.onDataAvailable(flow, ctx, db, gwCtx)
1024+
1025+ then:
1026+ ctx.getOrCreateAdditive(_, true) >> {
1027+ pwafAdditive = it[0].openAdditive() }
1028+ assert !flow.blocking
1029+ 1 * ctx.isAdditiveClosed()
1030+ 1 * ctx.getOrCreateAdditive(_, true, true) >> {
1031+ pwafAdditive = it[0].openAdditive() }
1032+ 1 * ctx.getRaspMetrics()
1033+ 1 * ctx.getRaspMetricsCounter()
1034+ 1 * ctx.increaseRaspTimeouts()
1035+ 1 * mockWafMetricCollector.get().raspTimeout(gwCtx.raspRuleType)
1036+ 1 * mockWafMetricCollector.raspRuleEval(RuleType.SQL_INJECTION)
1037+ 0 * _
1038+
1039+ when:
1040+ pp.processTraceSegment(segment, ctx, [])
1041+
1042+ then:
1043+ 1 * segment.setTagTop(' _dd. appsec. rasp. timeout' , 1L)
1044+ _ * segment.setTagTop(_, _)
1045+
1046+ cleanup:
1047+ injectSysConfig(' appsec. waf. timeout' , ConfigDefaults.DEFAULT_APPSEC_WAF_TIMEOUT as String)
1048+ PowerWAFModule.createLimitsObject()
1049+ gwCtx = new GatewayContext(false)
1050+ }
1051+
9991052 void ' configuration can be given later' () {
10001053 def cfgService = new StubAppSecConfigService([waf: null])
10011054 AppSecModuleConfigurer.Reconfiguration reconf = Mock()
@@ -1112,7 +1165,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
11121165 1 * ctx.getWafMetrics()
11131166 1 * ctx.isAdditiveClosed() >> false
11141167 1 * ctx.closeAdditive() >> { pwafAdditive.close() }
1115- _ * ctx. increaseTimeouts()
1168+ _ * ctx.increaseWafTimeouts()
1169+ _ * ctx.increaseRaspTimeouts()
11161170 0 * _
11171171
11181172 when: ' removing data and override config'
@@ -1136,7 +1190,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
11361190 1 * ctx.isAdditiveClosed() >> false
11371191 1 * ctx.closeAdditive() >> {pwafAdditive.close()}
11381192 1 * reconf.reloadSubscriptions()
1139- _ * ctx. increaseTimeouts()
1193+ _ * ctx.increaseWafTimeouts()
1194+ _ * ctx.increaseRaspTimeouts()
11401195 0 * _
11411196
11421197 when: ' data is readded'
@@ -1162,7 +1217,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
11621217 1 * ctx.closeAdditive() >> {pwafAdditive.close()}
11631218 1 * flow.isBlocking()
11641219 1 * ctx.isThrottled(null)
1165- _ * ctx. increaseTimeouts()
1220+ _ * ctx.increaseWafTimeouts()
1221+ _ * ctx.increaseRaspTimeouts()
11661222 0 * _
11671223
11681224 when: ' toggling the rule off'
@@ -1184,7 +1240,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
11841240 1 * ctx.getWafMetrics()
11851241 1 * ctx.isAdditiveClosed() >> false
11861242 1 * ctx.closeAdditive()
1187- _ * ctx. increaseTimeouts()
1243+ _ * ctx.increaseWafTimeouts()
1244+ _ * ctx.increaseRaspTimeouts()
11881245 0 * _
11891246 }
11901247
@@ -1214,7 +1271,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
12141271 1 * ctx.getWafMetrics()
12151272 1 * ctx.isAdditiveClosed() >> false
12161273 1 * ctx.closeAdditive() >> {pwafAdditive.close()}
1217- _ * ctx. increaseTimeouts()
1274+ _ * ctx.increaseWafTimeouts()
1275+ _ * ctx.increaseRaspTimeouts()
12181276 0 * _
12191277
12201278 when: ' rule enabled in config a has no effect'
@@ -1238,7 +1296,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
12381296 1 * ctx.getWafMetrics()
12391297 1 * ctx.isAdditiveClosed() >> false
12401298 1 * ctx.closeAdditive() >> {pwafAdditive.close()}
1241- _ * ctx. increaseTimeouts()
1299+ _ * ctx.increaseWafTimeouts()
1300+ _ * ctx.increaseRaspTimeouts()
12421301 0 * _
12431302
12441303 when: ' rule enabled in config c overrides b'
@@ -1266,7 +1325,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
12661325 1 * ctx.reportEvents(_ as Collection<AppSecEvent>)
12671326 1 * ctx.isAdditiveClosed() >> false
12681327 1 * ctx.closeAdditive() >> {pwafAdditive.close()}
1269- _ * ctx. increaseTimeouts()
1328+ _ * ctx.increaseWafTimeouts()
1329+ _ * ctx.increaseRaspTimeouts()
12701330 1 * ctx.isThrottled(null)
12711331 0 * _
12721332
@@ -1289,7 +1349,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
12891349 1 * ctx.getWafMetrics()
12901350 1 * ctx.isAdditiveClosed() >> false
12911351 1 * ctx.closeAdditive()
1292- _ * ctx. increaseTimeouts()
1352+ _ * ctx.increaseWafTimeouts()
1353+ _ * ctx.increaseRaspTimeouts()
12931354 0 * _
12941355 }
12951356
0 commit comments