add tiered auto-expiry based on auth level

This commit is contained in:
Username
2025-12-21 21:55:30 +01:00
parent 3fe631f6b9
commit e8a99d5bdd
4 changed files with 68 additions and 10 deletions

View File

@@ -178,8 +178,8 @@ class TestCustomExpiry:
data = response.get_json()
assert "expires_at" in data
def test_invalid_expiry_ignored(self, client):
"""Invalid X-Expiry values should be ignored."""
def test_invalid_expiry_uses_default(self, client):
"""Invalid X-Expiry values should use default expiry."""
for value in ["invalid", "-100", "0", ""]:
response = client.post(
"/",
@@ -188,14 +188,16 @@ class TestCustomExpiry:
)
assert response.status_code == 201
data = response.get_json()
assert "expires_at" not in data, f"Should not have expiry for: {value}"
# Default expiry is applied for anonymous users
assert "expires_at" in data, f"Should have default expiry for: {value}"
def test_paste_without_custom_expiry(self, client):
"""Paste without X-Expiry should not have expires_at."""
"""Paste without X-Expiry should use default expiry based on auth level."""
response = client.post("/", data=b"content")
assert response.status_code == 201
data = response.get_json()
assert "expires_at" not in data
# Default expiry is now applied for all users
assert "expires_at" in data
class TestExpiryCleanup:
@@ -205,7 +207,11 @@ class TestExpiryCleanup:
def app(self):
"""Create app with very short expiry for testing."""
app = create_app("testing")
app.config["PASTE_EXPIRY_SECONDS"] = 1 # 1 second default
# Set tiered expiry to 1 second for all levels
app.config["EXPIRY_ANON"] = 1
app.config["EXPIRY_UNTRUSTED"] = 1
app.config["EXPIRY_TRUSTED"] = 1
app.config["PASTE_EXPIRY_SECONDS"] = 1 # Legacy
app.config["MAX_EXPIRY_SECONDS"] = 10
return app