aboutsummaryrefslogtreecommitdiff
path: root/tests/views/test_received.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/views/test_received.py')
-rw-r--r--tests/views/test_received.py109
1 files changed, 109 insertions, 0 deletions
diff --git a/tests/views/test_received.py b/tests/views/test_received.py
index f23119d..5ae42f7 100644
--- a/tests/views/test_received.py
+++ b/tests/views/test_received.py
@@ -1122,6 +1122,115 @@ def test_received_detail_shows_full_reason_timestamps_and_public_status(
assert "No historical transitions were recorded" in html
+@pytest.mark.parametrize(
+ ("reason", "explanation", "next_step"),
+ [
+ (
+ "Source does not mention target",
+ "does not contain a recognized link",
+ None,
+ ),
+ (
+ "Source returned HTTP 404",
+ "source page was not found",
+ None,
+ ),
+ (
+ "Source returned HTTP 503",
+ "source server returned a server error",
+ None,
+ ),
+ (
+ "Source hostname could not be resolved",
+ "could not be resolved through DNS",
+ None,
+ ),
+ (
+ "Source document is too large",
+ "configured maximum response size",
+ None,
+ ),
+ (
+ "Source domain is blocked",
+ "receiver's blocklist",
+ "Review the blocklist in Moderation",
+ ),
+ (
+ "Source domain is not allowlisted",
+ "allowed source-domain list",
+ "Review the allowlist in Moderation",
+ ),
+ (
+ "Verification recovery limit reached",
+ "automatic recovery stopped",
+ "Check the verification workers",
+ ),
+ (
+ "Target hostname is not in ALLOWED_TARGET_HOSTNAMES",
+ "target hostname is not configured",
+ "Check ALLOWED_TARGET_HOSTNAMES",
+ ),
+ ],
+)
+def test_received_detail_only_suggests_receiver_controlled_steps(
+ app: Flask,
+ client: FlaskClient,
+ reason: str,
+ explanation: str,
+ next_step: str | None,
+) -> None:
+ log_in(app, client)
+ identifier = create_received_webmention(app, status="failed", failure_reason=reason)
+
+ response = client.get(f"/received/{identifier}")
+
+ assert response.status_code == HTTPStatus.OK
+ soup = BeautifulSoup(response.get_data(as_text=True), "html.parser")
+ assert explanation in soup.get_text()
+ if next_step is not None:
+ assert "Suggested next step:" in soup.get_text()
+ assert next_step in soup.get_text()
+ else:
+ assert "Suggested next step:" not in soup.get_text()
+ details = soup.find("details")
+ assert details is not None
+ assert reason in details.get_text()
+
+
+
+def test_received_detail_explains_historical_failure_and_escapes_raw_text(
+ app: Flask, client: FlaskClient
+) -> None:
+ from webmentions_ssg.models.received import (
+ ReceivedWebmentionStatus,
+ ReceivedWebmentionStatusEvent,
+ )
+
+ log_in(app, client)
+ identifier = create_received_webmention(app, status="verified")
+ raw_reason = "Unsupported source content type: text/<script>alert('x')</script>"
+ with app.app_context():
+ db.session.add(
+ ReceivedWebmentionStatusEvent(
+ webmention_uuid=identifier,
+ status=ReceivedWebmentionStatus.FAILED,
+ action="Verification completed",
+ failure_reason=raw_reason,
+ occurred_at=datetime(2026, 11, 10, tzinfo=UTC),
+ )
+ )
+ db.session.commit()
+
+ response = client.get(f"/received/{identifier}")
+ html = response.get_data(as_text=True)
+ soup = BeautifulSoup(html, "html.parser")
+ assert "unsupported content type" in soup.get_text()
+ assert "Suggested next step:" not in soup.get_text()
+ assert raw_reason in soup.get_text()
+ assert "<script>" not in html
+ assert "&lt;script&gt;" in html
+
+
def test_received_detail_keeps_filters_and_returns_after_actions(
app: Flask,
client: FlaskClient,