aboutsummaryrefslogtreecommitdiff
path: root/tests/forms/test_validators.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/forms/test_validators.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/forms/test_validators.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/tests/forms/test_validators.py b/tests/forms/test_validators.py
index 2858b4c..10796e9 100644
--- a/tests/forms/test_validators.py
+++ b/tests/forms/test_validators.py
@@ -9,7 +9,12 @@ from flask import Flask
from werkzeug.datastructures import MultiDict
from wtforms import Form, StringField, ValidationError
-from webmentions_ssg.forms.validators import AllowedHostname, NotEqualTo, PublicURL
+from webmentions_ssg.forms.validators import (
+ AllowedHostname,
+ NotEqualTo,
+ PublicURL,
+ URLMaxBytes,
+)
from webmentions_ssg.url_security import AddressResolutionError
@@ -118,3 +123,28 @@ def test_allowed_hostname_handles_invalid_ipv6(app: Flask) -> None:
form = URLForm(MultiDict({"url": "http://[::1"}))
with app.app_context(), pytest.raises(ValidationError, match="Invalid input"):
AllowedHostname()(form, form.url)
+
+
+def test_url_max_bytes_respects_utf8_byte_length_and_current_config(app: Flask) -> None:
+ validator = URLMaxBytes()
+ form = URLForm(MultiDict({"url": "é" * 3}))
+ with app.app_context():
+ app.config["MAX_WEBMENTION_URL_BYTES"] = 6
+ validator(form, form.url)
+ app.config["MAX_WEBMENTION_URL_BYTES"] = 5
+ with pytest.raises(ValidationError, match="5 bytes"):
+ validator(form, form.url)
+
+
+def test_url_max_bytes_custom_message(app: Flask) -> None:
+ form = URLForm(MultiDict({"url": "too-long"}))
+ with app.app_context():
+ app.config["MAX_WEBMENTION_URL_BYTES"] = 2
+ with pytest.raises(ValidationError, match="URL too long"):
+ URLMaxBytes(message="URL too long")(form, form.url)
+
+
+def test_url_max_bytes_rejects_malformed_unicode(app: Flask) -> None:
+ form = URLForm(MultiDict({"url": "\ud800"}))
+ with app.app_context(), pytest.raises(ValidationError, match="valid UTF-8"):
+ URLMaxBytes()(form, form.url)