From 54f6df4e1860194ab16888a03f91cf691dd10bcb Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Sat, 21 Nov 2026 17:19:45 -0500 Subject: [PATCH] test(CR-13): assert exact rate-limit thresholds across all API endpoints - Assert 1..10 return 200 and request 11 returns 429 on /api/zoom/verify-credentials - Parametrize rate-limit threshold tests for POST /api/appointments (15), GET (20), POST /pay (10), and DELETE (10) --- tests/test_app.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/test_app.py b/tests/test_app.py index 5ceb61d..e3a6030 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -196,9 +196,32 @@ def test_rate_limiting_blocks_brute_force(tmp_path: Path, monkeypatch): with app.test_client() as test_client: statuses = [ test_client.post("/api/zoom/verify-credentials", json=SAMPLE_CREDS).status_code - for _ in range(12) + for _ in range(11) ] - assert 429 in statuses + assert statuses[:10] == [200] * 10 + assert statuses[10] == 429 + + +@pytest.mark.parametrize( + ("method", "path", "limit"), + [ + ("POST", "/api/appointments", 15), + ("GET", "/api/appointments/ses_missing123", 20), + ("POST", "/api/appointments/ses_missing123/pay", 10), + ("DELETE", "/api/appointments/ses_missing123", 10), + ], +) +def test_sibling_endpoints_enforce_rate_limits(tmp_path: Path, method, path, limit): + db_file = tmp_path / "ratelimit_siblings.db" + app = create_app({"TESTING": True, "DB_PATH": str(db_file), "RATELIMIT_ENABLED": True}) + + with app.test_client() as test_client: + statuses = [ + test_client.open(path, method=method, json={}).status_code + for _ in range(limit + 1) + ] + assert all(code != 429 for code in statuses[:limit]) + assert statuses[limit] == 429 def test_zoom_invalid_json_returns_502(client, monkeypatch):