Steuere das Herunterladen von Originalen je Rolle, benenne Dateien richtig und zeige HTML-Mails gesichert im Sandbox-Rahmen.
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Successful in 5m35s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 22s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
StommerandClaude Sonnet 5.5 committed 2026-10-22 14:22:35 +02:00
1 parent 0a5daf6713
commit 075525ee17
26 files changed
+494 -71

No files matched your search

+48
View File
@@ -223,3 +223,51 @@ def test_unlinking_keeps_the_matter_and_its_other_cases(world):
assert opened["title"] == "Nebenkosten"
assert matter in {item["id"] for item in ada.request("GET", "/api/v1/matters")["items"]}
ada.request("DELETE", f"/api/v1/matter-case-links/{link['id']}", status=404)
def test_download_policy_follows_the_room_role(world):
ada, ben, cem, dan, room = world["ada"], world["ben"], world["cem"], world["dan"], world["room"]
matter = matter_of(ada, "Nebenkosten")["id"]
file = ada.request(
"POST",
"/api/v1/files",
data={"title": "Vertrag", "context_kind": "matter", "context_id": matter},
files={"upload": ("vertrag.pdf", b"%PDF-1.4\n1 0 obj<<>>endobj\ntrailer<<>>\n%%EOF\n", "application/pdf")},
status=201,
)["id"]
_share(ada, "matters", matter, room)
path = f"/api/v1/files/{file}/content"
query = {"context_kind": "matter", "context_id": matter}
def fetch(person, **extra):
from tests.support import ORIGIN
headers = {"Origin": ORIGIN, "X-CSRF-Token": person.csrf}
if person.scope is not None:
headers["X-Scope-Kind"], headers["X-Scope-Id"] = person.scope["kind"], person.scope["id"]
return person.client.get(path, params={**query, **extra}, headers=headers)
# By default every role may save the original.
for person in (ben, cem):
assert fetch(person, save="true").status_code == 200
seen = ben.request("GET", f"/api/v1/matters/{matter}")
assert seen["rights"]["download"] is True
# The owner turns it off for readers. Reading stays possible, saving does not.
assert cem.request("GET", f"/api/v1/rooms/{room}/download-policy")["can_change"] is False
cem.request("PUT", f"/api/v1/rooms/{room}/download-policy", json={"manager": True, "member": True, "reader": False}, status=403)
ada.request("PUT", f"/api/v1/rooms/{room}/download-policy", json={"manager": True, "member": True, "reader": False})
assert fetch(cem).status_code == 200
refused = fetch(cem, save="true")
assert refused.status_code == 403
assert "freigegeben" in refused.json()["detail"]
assert cem.request("GET", f"/api/v1/matters/{matter}")["rights"]["download"] is False
assert fetch(ben, save="true").status_code == 200
# A stranger learns nothing about the policy of the room.
dan.request("GET", f"/api/v1/rooms/{room}/download-policy", status=404)
# The owner's default is copied into a new room.
ada.request("PUT", "/api/v1/auth/download-defaults", json={"manager": True, "member": False, "reader": False, "direct": True})
fresh = ada.request("POST", "/api/v1/rooms", json={"name": "Neu", "default_visibility": "private"}, status=201)["id"]
assert ada.request("GET", f"/api/v1/rooms/{fresh}/download-policy")["roles"] == {"manager": True, "member": False, "reader": False}
assert ada.request("GET", f"/api/v1/rooms/{room}/download-policy")["roles"]["member"] is True
+38
View File
@@ -0,0 +1,38 @@
"""HTML mail: formatting stays, everything active or loading from outside is removed."""
from __future__ import annotations
from app.mailpack import sanitize_html
def test_formatting_stays_and_active_content_goes():
cleaned = sanitize_html(
'<div style="color:#333;font-size:14px" onclick="steal()"><font color="red" size="3">Hallo</font>'
'<table bgcolor="#eee" width="100%"><tr><td align="center">x</td></tr></table><hr>'
'<script>alert(1)</script><iframe src="http://x"></iframe><form action="http://x"><input></form></div>'
)
assert 'style="color: #333; font-size: 14px"' in cleaned
assert '<font color="red" size="3">' in cleaned
assert 'bgcolor="#eee"' in cleaned and "<hr>" in cleaned
for forbidden in ("onclick", "script", "iframe", "<form", "<input", "alert"):
assert forbidden not in cleaned
def test_styles_cannot_load_or_position():
cleaned = sanitize_html(
'<p style="background:url(http://track/p.png);position:fixed;width:expression(alert(1));'
'color:red;behavior:url(x.htc);margin:4px">Text</p>'
)
assert "url" not in cleaned and "position" not in cleaned and "expression" not in cleaned and "behavior" not in cleaned
assert "color: red" in cleaned and "margin: 4px" in cleaned
def test_links_and_images_are_limited():
cleaned = sanitize_html(
'<a href="javascript:alert(1)">a</a><a href="https://ok.example/x">b</a><a href="data:text/html,x">c</a>'
'<img src="http://track/p.gif"><img src="data:image/png;base64,AAAA" alt="logo"><img src="data:image/svg+xml;base64,AAAA">'
)
assert "javascript" not in cleaned and "data:text" not in cleaned and "track" not in cleaned and "svg" not in cleaned
assert 'href="https://ok.example/x"' in cleaned
assert 'rel="noreferrer noopener"' in cleaned and 'target="_blank"' in cleaned
assert 'src="data:image/png;base64,AAAA"' in cleaned
+3 -3
View File
@@ -68,10 +68,10 @@ def test_a_new_entry_follows_the_room_preset_and_rights_follow_the_role(world, d
assert [(s["room_name"], s["access"]) for s in view["shares"]] == [("Werkstatt", "edit")]
assert ben.request("GET", f"/api/v1/cases/{shared['id']}")["rights"] == {
"read": True, "edit": True, "share": False, "delete": False,
"read": True, "edit": True, "share": False, "delete": False, "download": True,
}
assert cem.request("GET", f"/api/v1/cases/{shared['id']}")["rights"] == {
"read": True, "edit": False, "share": False, "delete": False,
"read": True, "edit": False, "share": False, "delete": False, "download": True,
}
dan.request("GET", f"/api/v1/cases/{shared['id']}", status=404)
assert "Gemeinsame Akte" in {item["title"] for item in ben.request("GET", "/api/v1/cases")["items"]}
@@ -180,7 +180,7 @@ def test_a_standalone_matter_is_shared_like_a_case(world, db):
matter = matter_of(ada, "Eigener Vorgang")
assert ben.request("GET", f"/api/v1/matters/{matter['id']}")["rights"]["edit"] is True
assert cem.request("GET", f"/api/v1/matters/{matter['id']}")["rights"] == {
"read": True, "edit": False, "share": False, "delete": False,
"read": True, "edit": False, "share": False, "delete": False, "download": True,
}
ben.request("POST", f"/api/v1/matters/{matter['id']}/delete", json={"expected_version": matter["version"]}, status=403)
_unshare(ada, "matters", matter["id"], room)