@@ -70,7 +70,10 @@ class PowerWAFModuleSpecification extends DDSpecification {
70
70
Additive pwafAdditive
71
71
PowerwafMetrics metrics
72
72
73
+ WafMetricCollector wafMetricCollector = Mock (WafMetricCollector )
74
+
73
75
void setup () {
76
+ WafMetricCollector . INSTANCE = wafMetricCollector
74
77
AgentTracer . forceRegister(tracer)
75
78
}
76
79
@@ -206,6 +209,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
206
209
ctx. closeAdditive()
207
210
208
211
then :
212
+ 1 * wafMetricCollector. wafInit(Powerwaf . LIB_VERSION , _, true )
213
+ 1 * wafMetricCollector. wafUpdates(_, true )
209
214
1 * reconf. reloadSubscriptions()
210
215
1 * flow. setAction({ Flow.Action.RequestBlockingAction rba ->
211
216
rba. statusCode == 501 &&
@@ -241,6 +246,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
241
246
ctx. closeAdditive()
242
247
243
248
then :
249
+ 1 * wafMetricCollector. wafInit(Powerwaf . LIB_VERSION , _, true )
244
250
1 * flow. setAction({ Flow.Action.RequestBlockingAction rba ->
245
251
rba. statusCode == 403 &&
246
252
rba. blockingContentType == BlockingContentType . AUTO
@@ -282,6 +288,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
282
288
ctx. closeAdditive()
283
289
284
290
then :
291
+ 1 * wafMetricCollector. wafUpdates(_, true )
285
292
1 * reconf. reloadSubscriptions()
286
293
1 * flow. setAction({ Flow.Action.RequestBlockingAction rba ->
287
294
rba. statusCode == 403 &&
@@ -364,6 +371,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
364
371
ctx. closeAdditive()
365
372
366
373
then :
374
+ 1 * wafMetricCollector. wafUpdates(_, true )
367
375
1 * reconf. reloadSubscriptions()
368
376
1 * flow. setAction({ Flow.Action.RequestBlockingAction rba ->
369
377
rba. statusCode == 403 &&
@@ -440,7 +448,10 @@ class PowerWAFModuleSpecification extends DDSpecification {
440
448
}
441
449
442
450
then :
451
+ 1 * wafMetricCollector. wafInit(Powerwaf . LIB_VERSION , _, true )
452
+ 1 * wafMetricCollector. wafUpdates(_, true )
443
453
1 * reconf. reloadSubscriptions()
454
+ 0 * _
444
455
445
456
when :
446
457
dataListener. onDataAvailable(flow, ctx, ATTACK_BUNDLE , gwCtx)
@@ -522,7 +533,10 @@ class PowerWAFModuleSpecification extends DDSpecification {
522
533
}
523
534
524
535
then :
536
+ 1 * wafMetricCollector. wafInit(Powerwaf . LIB_VERSION , _, true )
537
+ 1 * wafMetricCollector. wafUpdates(_, true )
525
538
1 * reconf. reloadSubscriptions()
539
+ 0 * _
526
540
527
541
when :
528
542
dataListener. onDataAvailable(flow, ctx, ATTACK_BUNDLE , gwCtx)
@@ -597,7 +611,10 @@ class PowerWAFModuleSpecification extends DDSpecification {
597
611
}
598
612
599
613
then :
614
+ 1 * wafMetricCollector. wafInit(Powerwaf . LIB_VERSION , _, true )
615
+ 2 * wafMetricCollector. wafUpdates(_, true )
600
616
2 * reconf. reloadSubscriptions()
617
+ 0 * _
601
618
602
619
when :
603
620
dataListener. onDataAvailable(flow, ctx, ATTACK_BUNDLE , gwCtx)
@@ -972,9 +989,6 @@ class PowerWAFModuleSpecification extends DDSpecification {
972
989
TraceSegment segment = Mock()
973
990
TraceSegmentPostProcessor pp = service.traceSegmentPostProcessors.last()
974
991
975
- def mockWafMetricCollector = Mock(WafMetricCollector)
976
- WafMetricCollector.INSTANCE = mockWafMetricCollector
977
-
978
992
when:
979
993
dataListener.onDataAvailable(flow, ctx, db, gwCtx)
980
994
@@ -987,7 +1001,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
987
1001
pwafAdditive = it[0].openAdditive() }
988
1002
1 * ctx.getWafMetrics()
989
1003
1 * ctx.increaseWafTimeouts()
990
- 1 * mockWafMetricCollector .get().wafRequestTimeout()
1004
+ 1 * wafMetricCollector .get().wafRequestTimeout()
991
1005
0 * _
992
1006
993
1007
when:
@@ -1014,9 +1028,6 @@ class PowerWAFModuleSpecification extends DDSpecification {
1014
1028
TraceSegment segment = Mock()
1015
1029
TraceSegmentPostProcessor pp = service.traceSegmentPostProcessors.last()
1016
1030
1017
- def mockWafMetricCollector = Mock(WafMetricCollector)
1018
- WafMetricCollector.INSTANCE = mockWafMetricCollector
1019
-
1020
1031
gwCtx = new GatewayContext(false, RuleType.SQL_INJECTION)
1021
1032
1022
1033
when:
@@ -1032,8 +1043,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
1032
1043
1 * ctx.getRaspMetrics()
1033
1044
1 * ctx.getRaspMetricsCounter()
1034
1045
1 * ctx.increaseRaspTimeouts()
1035
- 1 * mockWafMetricCollector .get().raspTimeout(gwCtx.raspRuleType)
1036
- 1 * mockWafMetricCollector .raspRuleEval(RuleType.SQL_INJECTION)
1046
+ 1 * wafMetricCollector .get().raspTimeout(gwCtx.raspRuleType)
1047
+ 1 * wafMetricCollector .raspRuleEval(RuleType.SQL_INJECTION)
1037
1048
0 * _
1038
1049
1039
1050
when:
@@ -1059,6 +1070,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1059
1070
1060
1071
then:
1061
1072
thrown AppSecModule.AppSecModuleActivationException
1073
+ 0 * _
1062
1074
1063
1075
when:
1064
1076
cfgService.listeners[' waf' ].onNewSubconfig(defaultConfig[' waf' ], reconf)
@@ -1070,7 +1082,14 @@ class PowerWAFModuleSpecification extends DDSpecification {
1070
1082
1 * ctx.getOrCreateAdditive(_, true, false) >> {
1071
1083
pwafAdditive = it[0].openAdditive() }
1072
1084
1 * ctx.reportEvents(_ as Collection<AppSecEvent>)
1085
+ 1 * ctx.isAdditiveClosed()
1086
+ 1 * ctx.getWafMetrics()
1087
+ 1 * ctx.isThrottled(null)
1088
+ 1 * ctx.closeAdditive()
1089
+ 2 * tracer.activeSpan()
1090
+ 1 * wafMetricCollector.wafInit(Powerwaf.LIB_VERSION, _, true)
1073
1091
1 * reconf.reloadSubscriptions()
1092
+ 0 * _
1074
1093
}
1075
1094
1076
1095
void ' rule data given through configuration' () {
@@ -1102,6 +1121,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1102
1121
ctx.closeAdditive()
1103
1122
1104
1123
then:
1124
+ 1 * wafMetricCollector.wafUpdates(_, true)
1105
1125
1 * reconf.reloadSubscriptions()
1106
1126
1 * ctx.getOrCreateAdditive(_, true, false) >> { pwafAdditive = it[0].openAdditive() }
1107
1127
2 * tracer.activeSpan()
@@ -1159,6 +1179,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1159
1179
ctx.closeAdditive()
1160
1180
1161
1181
then: ' no match; rule is disabled'
1182
+ 1 * wafMetricCollector.wafUpdates(_, true)
1162
1183
1 * reconf.reloadSubscriptions()
1163
1184
1 * ctx.getOrCreateAdditive(_, true, false) >> {
1164
1185
pwafAdditive = it[0].openAdditive() }
@@ -1189,6 +1210,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1189
1210
1 * ctx.getWafMetrics()
1190
1211
1 * ctx.isAdditiveClosed() >> false
1191
1212
1 * ctx.closeAdditive() >> {pwafAdditive.close()}
1213
+ 1 * wafMetricCollector.wafUpdates(_, true)
1192
1214
1 * reconf.reloadSubscriptions()
1193
1215
_ * ctx.increaseWafTimeouts()
1194
1216
_ * ctx.increaseRaspTimeouts()
@@ -1206,6 +1228,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1206
1228
ctx.closeAdditive()
1207
1229
1208
1230
then: ' now we have match'
1231
+ 1 * wafMetricCollector.wafUpdates(_, true)
1209
1232
1 * reconf.reloadSubscriptions()
1210
1233
1 * ctx.getOrCreateAdditive(_, true, false) >> {
1211
1234
pwafAdditive = it[0].openAdditive() }
@@ -1235,6 +1258,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1235
1258
ctx.closeAdditive()
1236
1259
1237
1260
then: ' nothing again; we disabled the rule'
1261
+ 1 * wafMetricCollector.wafUpdates(_, true)
1238
1262
1 * reconf.reloadSubscriptions()
1239
1263
1 * ctx.getOrCreateAdditive(_, true, false) >> { pwafAdditive = it[0].openAdditive() }
1240
1264
1 * ctx.getWafMetrics()
@@ -1265,6 +1289,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1265
1289
ctx.closeAdditive()
1266
1290
1267
1291
then:
1292
+ 1 * wafMetricCollector.wafUpdates(_, true)
1268
1293
1 * reconf.reloadSubscriptions()
1269
1294
// no attack
1270
1295
1 * ctx.getOrCreateAdditive(_, true, false) >> { pwafAdditive = it[0].openAdditive() }
@@ -1289,6 +1314,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1289
1314
ctx.closeAdditive()
1290
1315
1291
1316
then:
1317
+ 1 * wafMetricCollector.wafUpdates(_, true)
1292
1318
1 * reconf.reloadSubscriptions()
1293
1319
// no attack
1294
1320
1 * ctx.getOrCreateAdditive(_, true, false) >> {
@@ -1314,6 +1340,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1314
1340
ctx.closeAdditive()
1315
1341
1316
1342
then:
1343
+ 1 * wafMetricCollector.wafUpdates(_, true)
1317
1344
1 * reconf.reloadSubscriptions()
1318
1345
// attack found
1319
1346
1 * ctx.getOrCreateAdditive(_, true, false) >> {
@@ -1342,6 +1369,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1342
1369
ctx.closeAdditive()
1343
1370
1344
1371
then:
1372
+ 1 * wafMetricCollector.wafUpdates(_, true)
1345
1373
1 * reconf.reloadSubscriptions()
1346
1374
// no attack
1347
1375
1 * ctx.getOrCreateAdditive(_, true, false) >> {
@@ -1390,7 +1418,9 @@ class PowerWAFModuleSpecification extends DDSpecification {
1390
1418
pwafModule.config(cfgService)
1391
1419
1392
1420
then:
1421
+ 1 * wafMetricCollector.wafInit(Powerwaf.LIB_VERSION, _, true)
1393
1422
!pwafModule.dataSubscriptions.first().subscribedAddresses.contains(doesNotExistAddress)
1423
+ 0 * _
1394
1424
}
1395
1425
1396
1426
void ' bad initial configuration is given results in no subscriptions' () {
@@ -1403,6 +1433,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1403
1433
then:
1404
1434
thrown AppSecModule.AppSecModuleActivationException
1405
1435
pwafModule.dataSubscriptions.empty
1436
+ 0 * _
1406
1437
}
1407
1438
1408
1439
void ' rule data not a config' () {
@@ -1414,9 +1445,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
1414
1445
1415
1446
then:
1416
1447
thrown AppSecModule.AppSecModuleActivationException
1417
-
1418
- then:
1419
1448
pwafModule.ctxAndAddresses.get() == null
1449
+ 0 * _
1420
1450
}
1421
1451
1422
1452
void ' bad ResultWithData - empty list' () {
@@ -1554,7 +1584,18 @@ class PowerWAFModuleSpecification extends DDSpecification {
1554
1584
ctx. closeAdditive()
1555
1585
1556
1586
then :
1587
+ 1 * ctx. isAdditiveClosed()
1588
+ 1 * ctx. getOrCreateAdditive(_ as PowerwafContext , true , false ) >> {
1589
+ pwafAdditive = it[0 ]. openAdditive()
1590
+ }
1591
+ 1 * ctx. getWafMetrics()
1592
+ 1 * ctx. isThrottled(null )
1593
+ 1 * ctx. reportEvents(_ as Collection<AppSecEvent > )
1594
+ 1 * ctx. closeAdditive()
1595
+ 2 * tracer. activeSpan()
1596
+ 1 * flow. isBlocking()
1557
1597
0 * flow. setAction(_)
1598
+ 0 * _
1558
1599
1559
1600
when :
1560
1601
final ipData = new AppSecData (exclusion : [
@@ -1576,11 +1617,22 @@ class PowerWAFModuleSpecification extends DDSpecification {
1576
1617
ctx. closeAdditive()
1577
1618
1578
1619
then :
1620
+ 1 * wafMetricCollector. wafUpdates(_, true )
1579
1621
1 * reconf. reloadSubscriptions()
1580
1622
1 * flow. setAction({ Flow.Action.RequestBlockingAction rba ->
1581
1623
rba. statusCode == 402 && rba. blockingContentType == BlockingContentType . AUTO
1582
1624
})
1625
+ 1 * flow. isBlocking()
1583
1626
1 * ctx. isAdditiveClosed() >> false
1627
+ 1 * ctx. getOrCreateAdditive(_ as PowerwafContext , true , false ) >> {
1628
+ pwafAdditive = it[0 ]. openAdditive()
1629
+ }
1630
+ 1 * ctx. getWafMetrics()
1631
+ 1 * ctx. isThrottled(null )
1632
+ 1 * ctx. reportEvents(_ as Collection<AppSecEvent > )
1633
+ 1 * ctx. closeAdditive()
1634
+ 2 * tracer. activeSpan()
1635
+ 0 * _
1584
1636
}
1585
1637
1586
1638
void ' http endpoint fingerprint support' () {
@@ -1668,6 +1720,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
1668
1720
then :
1669
1721
1 * ctx. closeAdditive()
1670
1722
1 * ctx. isAdditiveClosed() >> true
1723
+ 1 * wafMetricCollector. wafInit(Powerwaf . LIB_VERSION , _, true )
1671
1724
0 * _
1672
1725
}
1673
1726
0 commit comments