aboutsummaryrefslogtreecommitdiff
path: root/tests/test_received_failure.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-17 22:10:40 +0100
committerDennis Fink2026-11-17 22:10:40 +0100
commit63af533d98aac82b6d4f069b217d3e837285508d (patch)
tree4ac11960f9676d3bb5a6f62204ef139862734209 /tests/test_received_failure.py
parentacd1f42847786963fc4aaeed884c3091700c9e35 (diff)
downloadwebmentions-ssg-63af533d98aac82b6d4f069b217d3e837285508d.tar.gz
webmentions-ssg-63af533d98aac82b6d4f069b217d3e837285508d.zip
feat(receiver): explain received Webmention failures
Map known verification failures to human-readable explanations and show suggested next steps only for receiver-controlled problems while retaining raw reasons. Return a specific validation error when targets are outside `ALLOWED_TARGET_HOSTNAMES` and reuse the guidance for status history.
Diffstat (limited to '')
-rw-r--r--tests/test_received_failure.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/test_received_failure.py b/tests/test_received_failure.py
new file mode 100644
index 0000000..095d7e1
--- /dev/null
+++ b/tests/test_received_failure.py
@@ -0,0 +1,53 @@
+# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+import pytest
+
+from webmentions_ssg.received_failure import describe_received_failure
+
+
+@pytest.mark.parametrize(
+ ("reason", "expected_fragment", "local_step"),
+ [
+ ("Source does not mention target", "link to the target URL", False),
+ ("Source returned HTTP 410", "permanently gone", False),
+ ("Source document is too large", "maximum response size", False),
+ ("Source resolves to a non-public address", "non-public address", False),
+ ("Source hostname could not be resolved", "DNS", False),
+ ("Source could not be fetched", "could not fetch", False),
+ ("Invalid source hostname", "valid hostname", False),
+ ("Source domain is blocked", "blocklist", True),
+ ("Source domain is not allowlisted", "allowed source-domain", True),
+ ("Verification recovery limit reached", "automatic recovery stopped", True),
+ ("Target hostname is not in ALLOWED_TARGET_HOSTNAMES", "target hostname", True),
+ (
+ "Target hostname is not in ALLOWED_TARGET_HOSTNAMES.",
+ "target hostname",
+ True,
+ ),
+ ("Source returned HTTP 404", "not found", False),
+ ("Source returned HTTP 401", "denied access", False),
+ ("Source returned HTTP 403", "denied access", False),
+ ("Source returned HTTP 429", "limiting requests", False),
+ ("Source returned HTTP 503", "server error", False),
+ ("Source returned HTTP 400", "returned HTTP 400", False),
+ (
+ "Unsupported source content type: application/json",
+ "application/json",
+ False,
+ ),
+ ],
+)
+def test_only_receiver_controlled_failures_suggest_steps(
+ reason: str, expected_fragment: str, local_step: bool
+) -> None:
+ guidance = describe_received_failure(reason)
+ assert guidance is not None
+ assert expected_fragment in guidance.explanation
+ assert bool(guidance.next_step) is local_step
+
+
+@pytest.mark.parametrize("reason", ["unknown failure", "", "Source returned HTTP 999"])
+def test_unknown_received_failures_are_not_misclassified(reason: str) -> None:
+ assert describe_received_failure(reason) is None