From 37bc3853dded34e3d1323874927979ce510e4910 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 30 Oct 2026 11:51:34 +0100 Subject: test: align test suite with package structure --- tests/test_views.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'tests/test_views.py') diff --git a/tests/test_views.py b/tests/test_views.py index f8dd375..8ac57b1 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1118,3 +1118,60 @@ def test_logout_ends_session(app: Flask, client: FlaskClient) -> None: protected_response = client.get("/received") assert protected_response.status_code == 302 assert "/login" in protected_response.headers["Location"] + + +def create_outgoing( + app: Flask, *, status_url: str | None = None +) -> tuple[uuid.UUID, uuid.UUID]: + now = datetime.now(UTC) + with app.app_context(): + source = Source( + path="blog/post/index.html", + url="https://source.example/blog/post", + content_hash="0" * 32, + revision=1, + last_seen_at=now, + revised_at=now, + ) + mention = SentWebmention( + target="https://example.com/article", + active=True, + desired_revision=1, + status_url=status_url, + response_status=201 if status_url is not None else None, + ) + source.sent_webmentions.append(mention) + db.session.add(source) + db.session.commit() + return source.uuid, mention.uuid + + +@pytest.mark.parametrize( + ("status_url", "safe"), + [ + ("https://example.com/status", True), + ("http://example.com/status", True), + ("javascript:alert(1)", False), + ("data:text/html,evil", False), + ("ftp://example.com/status", False), + ], +) +def test_admin_only_links_safe_existing_status_urls( + app: Flask, client: FlaskClient, status_url: str, safe: bool +) -> None: + source_identifier, _ = create_outgoing(app, status_url=status_url) + with app.app_context(): + user = User(username="admin", password="test") + db.session.add(user) + db.session.commit() + user_id = user.id + + with client.session_transaction() as session: + session["_user_id"] = str(user_id) + session["_fresh"] = True + + response = client.get(f"/sent/{source_identifier}") + assert response.status_code == 200 + html = response.get_data(as_text=True) + assert (f'href="{status_url}"' in html) is safe + assert status_url in html -- cgit v1.3.1