aboutsummaryrefslogtreecommitdiff
path: root/tests/test_config.py
diff options
context:
space:
mode:
authorDennis Fink2026-10-31 17:42:00 +0100
committerDennis Fink2026-10-31 17:42:00 +0100
commit6924ad7e52033365c55d5afacdd916c502cc80cb (patch)
tree8a52b8e8fbae7a6bcc85d250cac2436a2c42e748 /tests/test_config.py
parent3494eab1208dc18478485e02c61e292556502fa6 (diff)
downloadwebmentions-ssg-6924ad7e52033365c55d5afacdd916c502cc80cb.tar.gz
webmentions-ssg-6924ad7e52033365c55d5afacdd916c502cc80cb.zip
feat(receiver): add resource limits and retention
Bound incoming request and URL sizes so untrusted Webmention submissions cannot consume unbounded application or database resources. Purge old failed and deleted received Webmentions on a schedule, and use portable SHA-256 URL fingerprints to preserve uniqueness for long URLs.
Diffstat (limited to '')
-rw-r--r--tests/test_config.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index dd02c01..933f437 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -232,3 +232,25 @@ def test_development_rejects_placeholder_even_with_debug(tmp_path: Path) -> None
with pytest.raises(RuntimeError, match="SECRET_KEY"):
create_app(LocalDevelopment)
+
+
+def test_resource_limits_have_safe_defaults() -> None:
+ assert DefaultConfig.MAX_CONTENT_LENGTH == 64 * 1024
+ assert DefaultConfig.MAX_WEBMENTION_URL_BYTES == 8192
+ assert DefaultConfig.RECEIVED_RETENTION_DAYS == 30
+ assert DefaultConfig.RECEIVED_RETENTION_SCHEDULE == "0 3 * * *"
+
+
+@pytest.mark.parametrize(
+ "key", ["MAX_CONTENT_LENGTH", "MAX_WEBMENTION_URL_BYTES", "RECEIVED_RETENTION_DAYS"]
+)
+@pytest.mark.parametrize("value", [None, "100", 0, -1, True, 1.5])
+def test_invalid_resource_limits_fail_at_startup(
+ tmp_path: Path, key: str, value: object
+) -> None:
+ class InvalidResourceLimit(TestingConfig):
+ LOG_FILE = str(tmp_path / "invalid-resource.log")
+
+ setattr(InvalidResourceLimit, key, value)
+ with pytest.raises(ValueError, match=key):
+ create_app(InvalidResourceLimit)