Party Hardy

This commit is contained in:
2026-10-17 07:33:08 +02:00
parent d84e4cf3d3
commit 7274cc1840
51 changed files with 2738 additions and 2100 deletions
+4 -3
View File
@@ -156,18 +156,19 @@ def test_rate_limit_block_recorded(monkeypatch):
# limiter re-enabled for itself - the same approach as test_ratelimit.py - and
# asserts the block emits the security.rate_limit.block audit row.
import devplacepy.main as m
import devplacepy.middleware.state as st
from starlette.testclient import TestClient
monkeypatch.setattr(m, "RATE_LIMIT_DISABLED", False)
monkeypatch.setattr(st, "RATE_LIMIT_DISABLED", False)
monkeypatch.setattr(
m,
st,
"get_int_setting",
lambda key, default: {
"rate_limit_per_minute": 1,
"rate_limit_window_seconds": 60,
}.get(key, default),
)
m._rate_limit_store.clear()
st._rate_limit_store.clear()
ip = "203.0.113.77"
client = TestClient(m.app)
codes = [
+4 -3
View File
@@ -1,6 +1,7 @@
# retoor <retoor@molodetz.nl>
import devplacepy.main as m
import devplacepy.middleware.state as st
from starlette.testclient import TestClient
def _patch_limits(monkeypatch, limit, window=60):
def fake_get_int_setting(key, default):
@@ -9,10 +10,10 @@ def _patch_limits(monkeypatch, limit, window=60):
"rate_limit_window_seconds": window,
}.get(key, default)
monkeypatch.setattr(m, "get_int_setting", fake_get_int_setting)
monkeypatch.setattr(st, "get_int_setting", fake_get_int_setting)
# conftest disables the limiter suite-wide; re-enable it for these tests only.
monkeypatch.setattr(m, "RATE_LIMIT_DISABLED", False)
m._rate_limit_store.clear()
monkeypatch.setattr(st, "RATE_LIMIT_DISABLED", False)
st._rate_limit_store.clear()
import requests
from tests.conftest import BASE_URL
def _seed_news_seo():
+6 -5
View File
@@ -3,6 +3,7 @@
import re
import devplacepy.main as m
import devplacepy.middleware.state as st
from starlette.testclient import TestClient
def _patch_limits(monkeypatch, limit, window=60):
def fake_get_int_setting(key, default):
@@ -11,14 +12,14 @@ def _patch_limits(monkeypatch, limit, window=60):
"rate_limit_window_seconds": window,
}.get(key, default)
monkeypatch.setattr(m, "get_int_setting", fake_get_int_setting)
monkeypatch.setattr(st, "get_int_setting", fake_get_int_setting)
# conftest disables the limiter suite-wide; re-enable it for these tests only.
monkeypatch.setattr(m, "RATE_LIMIT_DISABLED", False)
m._rate_limit_store.clear()
monkeypatch.setattr(st, "RATE_LIMIT_DISABLED", False)
st._rate_limit_store.clear()
# _hot_settings caches the limit for HOT_SETTINGS_TTL; force a re-read of the
# patched get_int_setting so a stale value from a prior test cannot leak in.
m._hot_settings_value = None
m._hot_settings_at = 0.0
st._hot_settings_value = None
st._hot_settings_at = 0.0
def test_rate_limit_blocks_excess(monkeypatch):