aboutsummaryrefslogtreecommitdiff
path: root/tests/forms
diff options
context:
space:
mode:
authorDennis Fink2026-10-31 19:00:17 +0100
committerDennis Fink2026-10-31 19:00:17 +0100
commitdf3b79e2c89978ec21dc2da7f90801dce33aeab2 (patch)
tree146f34d59b2b1957e53856a58777a3453960a2a5 /tests/forms
parentf7c0691e0da84644ea8b2b83ad5574fe179da59b (diff)
downloadwebmentions-ssg-df3b79e2c89978ec21dc2da7f90801dce33aeab2.tar.gz
webmentions-ssg-df3b79e2c89978ec21dc2da7f90801dce33aeab2.zip
fix(receiver): prevent endless verification recovery
Cap stale verification requeues so repeatedly lost or crashing tasks eventually become terminal failures instead of cycling indefinitely. Reject URLs that httpx cannot safely fetch before enqueueing, and persist unexpected verification errors as terminal failures.
Diffstat (limited to '')
-rw-r--r--tests/forms/test_init.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/forms/test_init.py b/tests/forms/test_init.py
index 2a68509..42e6a2c 100644
--- a/tests/forms/test_init.py
+++ b/tests/forms/test_init.py
@@ -144,7 +144,7 @@ def test_endpoint_handles_malformed_ipv6_without_crashing(app: Flask) -> None:
meta={"csrf": False},
)
assert not form.validate()
- assert "Invalid input." in form.errors["target"]
+ assert "Invalid URL." in form.errors["target"]
def test_endpoint_form_applies_configurable_url_byte_limit_to_both_fields(
@@ -168,3 +168,38 @@ def test_endpoint_form_applies_configurable_url_byte_limit_to_both_fields(
assert not form.validate()
assert "target" in form.errors
assert any("bytes" in message for message in form.errors["target"])
+
+
+@pytest.mark.parametrize("field_name", ["source", "target"])
+@pytest.mark.parametrize(
+ "invalid_url",
+ [
+ pytest.param("http://ex☃mple.test/", id="invalid-idn"),
+ pytest.param("https://example.com/a\nb", id="newline"),
+ pytest.param("https://example.com/a\rb", id="carriage-return"),
+ pytest.param("https://example.com/\x00b", id="nul"),
+ pytest.param("https://example.com/a b", id="ascii-space"),
+ pytest.param("https://example.com/a\u00a0b", id="unicode-whitespace"),
+ pytest.param("https://example.com/\x7fb", id="del"),
+ ],
+)
+def test_endpoint_rejects_invalid_httpx_urls_and_whitespace(
+ app: Flask, field_name: str, invalid_url: str
+) -> None:
+ data = {"source": VALID_SOURCE, "target": VALID_TARGET}
+ data[field_name] = invalid_url
+ with app.test_request_context("/endpoint", method="POST"):
+ form = EndpointForm(formdata=MultiDict(data), meta={"csrf": False})
+ assert not form.validate()
+ assert "Invalid URL." in form.errors[field_name]
+
+
+def test_endpoint_accepts_encoded_path_space(app: Flask) -> None:
+ with app.test_request_context("/endpoint", method="POST"):
+ form = EndpointForm(
+ formdata=MultiDict(
+ {"source": "https://source.example/a%20b", "target": VALID_TARGET}
+ ),
+ meta={"csrf": False},
+ )
+ assert form.validate()