Skip to content

Commit ed82846

Browse files
committed
should_block_request count rate_limited_hits
1 parent 4e98595 commit ed82846

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

aikido_zen/middleware/init_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def test_with_context_with_cache():
6161
}
6262
assert get_current_context().executed_middleware == True
6363
assert thread_cache.middleware_installed == True
64+
assert thread_cache.stats.rate_limited_hits == 0
6465

6566
thread_cache.config.blocked_uids = []
6667
assert should_block_request() == {"block": False}
@@ -69,6 +70,7 @@ def test_with_context_with_cache():
6970
assert should_block_request() == {"block": False}
7071
assert get_current_context().executed_middleware == True
7172
assert thread_cache.middleware_installed == True
73+
assert thread_cache.stats.rate_limited_hits == 0
7274

7375

7476
def test_cache_comms_with_endpoints():
@@ -158,9 +160,11 @@ def test_cache_comms_with_endpoints():
158160
"success": True,
159161
"data": {"block": True, "trigger": "my_trigger"},
160162
}
163+
assert thread_cache.stats.rate_limited_hits == 0
161164
assert should_block_request() == {
162165
"block": True,
163166
"ip": "::1",
164167
"type": "ratelimited",
165168
"trigger": "my_trigger",
166169
}
170+
assert thread_cache.stats.rate_limited_hits == 1

aikido_zen/middleware/should_block_request.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def should_block_request():
5151
receive=True,
5252
)
5353
if ratelimit_res["success"] and ratelimit_res["data"]["block"]:
54+
cache.stats.on_rate_limit()
5455
return {
5556
"block": True,
5657
"type": "ratelimited",

0 commit comments

Comments
 (0)