aboutsummaryrefslogtreecommitdiff
path: root/tests/test_views.py
diff options
context:
space:
mode:
authorDennis Fink2026-10-30 11:51:34 +0100
committerDennis Fink2026-10-30 11:51:34 +0100
commit37bc3853dded34e3d1323874927979ce510e4910 (patch)
tree7d6d2181d9bb05f4d4a8d00152c172cc92e7ab63 /tests/test_views.py
parent4485aeb573ceb37237ea1fbc80665ed6c4136116 (diff)
downloadwebmentions-ssg-37bc3853dded34e3d1323874927979ce510e4910.tar.gz
webmentions-ssg-37bc3853dded34e3d1323874927979ce510e4910.zip
test: align test suite with package structure
Diffstat (limited to '')
-rw-r--r--tests/test_views.py57
1 files changed, 57 insertions, 0 deletions
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