@@ -18,6 +18,8 @@ def test_initialization(monkeypatch):
1818 assert stats .total_hits == 0
1919 assert stats .attacks_detected == 0
2020 assert stats .attacks_blocked == 0
21+ assert stats .attack_waves_detected == 0
22+ assert stats .attack_waves_blocked == 0
2123 assert stats .started_at == mock_time
2224 assert isinstance (stats .operations , Operations )
2325
@@ -33,12 +35,15 @@ def test_clear(monkeypatch):
3335 stats .total_hits = 10
3436 stats .attacks_detected = 5
3537 stats .attacks_blocked = 3
38+ stats .on_detected_attack_wave (blocked = True )
3639 stats .operations .register_call ("test" , "sql_op" )
3740 stats .clear ()
3841
3942 assert stats .total_hits == 0
4043 assert stats .attacks_detected == 0
4144 assert stats .attacks_blocked == 0
45+ assert stats .attack_waves_blocked == 0
46+ assert stats .attack_waves_detected == 0
4247 assert stats .started_at == mock_time
4348 assert stats .operations == {}
4449
@@ -59,6 +64,16 @@ def test_on_detected_attack(stats):
5964 assert stats .attacks_blocked == 1
6065
6166
67+ def test_on_detected_attack_wave (stats ):
68+ stats .on_detected_attack_wave (blocked = True )
69+ assert stats .get_record ()["requests" ]["attackWaves" ]["total" ] == 1
70+ assert stats .get_record ()["requests" ]["attackWaves" ]["blocked" ] == 1
71+
72+ stats .on_detected_attack_wave (blocked = False )
73+ assert stats .get_record ()["requests" ]["attackWaves" ]["total" ] == 2
74+ assert stats .get_record ()["requests" ]["attackWaves" ]["blocked" ] == 1
75+
76+
6277def test_get_record (monkeypatch ):
6378 # Mock the current time
6479 mock_time = 1234567890000
@@ -74,6 +89,8 @@ def test_get_record(monkeypatch):
7489 stats .on_detected_attack (blocked = True , operation = "test.test" )
7590 stats .attacks_detected = 5
7691 stats .attacks_blocked = 3
92+ stats .on_detected_attack_wave (False )
93+ stats .on_detected_attack_wave (False )
7794
7895 record = stats .get_record ()
7996 assert record ["startedAt" ] == stats .started_at
@@ -83,6 +100,8 @@ def test_get_record(monkeypatch):
83100 assert record ["requests" ]["aborted" ] == 0
84101 assert record ["requests" ]["attacksDetected" ]["total" ] == 5
85102 assert record ["requests" ]["attacksDetected" ]["blocked" ] == 3
103+ assert record ["requests" ]["attackWaves" ]["total" ] == 2
104+ assert record ["requests" ]["attackWaves" ]["blocked" ] == 0
86105 assert record ["operations" ] == {
87106 "test.test" : {
88107 "attacksDetected" : {"blocked" : 1 , "total" : 1 },
@@ -153,6 +172,12 @@ def test_empty(stats):
153172 assert stats .empty () == False
154173
155174
175+ def test_empty_with_attack_waves (stats ):
176+ assert stats .empty ()
177+ stats .on_detected_attack_wave (blocked = False )
178+ assert not stats .empty ()
179+
180+
156181def test_multiple_imports (stats ):
157182 record1 = {
158183 "requests" : {
0 commit comments