forked from claw/flaskpaste
routes: skip rate limiting for trusted certificate holders
This commit is contained in:
@@ -92,44 +92,37 @@ class TestRateLimiting:
|
||||
finally:
|
||||
app.config["RATE_LIMIT_MAX"] = original_max
|
||||
|
||||
def test_rate_limit_auth_multiplier(self, client, app, auth_header):
|
||||
"""Authenticated users get higher rate limits."""
|
||||
def test_trusted_cert_exempt_from_rate_limit(self, client, app, auth_header):
|
||||
"""Trusted certificate holders are exempt from rate limiting."""
|
||||
original_max = app.config["RATE_LIMIT_MAX"]
|
||||
original_mult = app.config["RATE_LIMIT_AUTH_MULTIPLIER"]
|
||||
app.config["RATE_LIMIT_MAX"] = 2
|
||||
app.config["RATE_LIMIT_AUTH_MULTIPLIER"] = 3 # 2 * 3 = 6 for auth users
|
||||
|
||||
try:
|
||||
# Authenticated user can make more requests than base limit
|
||||
# Trusted client can exceed the base limit without being blocked
|
||||
for i in range(5):
|
||||
response = client.post(
|
||||
"/",
|
||||
data=f"auth {i}",
|
||||
data=f"trusted {i}",
|
||||
content_type="text/plain",
|
||||
headers=auth_header,
|
||||
)
|
||||
assert response.status_code == 201
|
||||
|
||||
# 6th request should succeed (limit is 2*3=6)
|
||||
# Anonymous user hits the limit
|
||||
for i in range(2):
|
||||
client.post(
|
||||
"/",
|
||||
data=f"anon {i}",
|
||||
content_type="text/plain",
|
||||
)
|
||||
response = client.post(
|
||||
"/",
|
||||
data="auth 6",
|
||||
data="anon overflow",
|
||||
content_type="text/plain",
|
||||
headers=auth_header,
|
||||
)
|
||||
assert response.status_code == 201
|
||||
|
||||
# 7th should fail
|
||||
response = client.post(
|
||||
"/",
|
||||
data="auth 7",
|
||||
content_type="text/plain",
|
||||
headers=auth_header,
|
||||
)
|
||||
assert response.status_code == 429
|
||||
finally:
|
||||
app.config["RATE_LIMIT_MAX"] = original_max
|
||||
app.config["RATE_LIMIT_AUTH_MULTIPLIER"] = original_mult
|
||||
|
||||
def test_rate_limit_can_be_disabled(self, client, app):
|
||||
"""Rate limiting can be disabled via config."""
|
||||
|
||||
Reference in New Issue
Block a user