2026-06-19 10:06:09 +02:00
|
|
|
# retoor <retoor@molodetz.nl>
|
|
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
import requests
|
|
|
|
|
from tests.conftest import BASE_URL
|
|
|
|
|
from devplacepy.database import get_table
|
|
|
|
|
|
|
|
|
|
JSON = {"Accept": "application/json"}
|
|
|
|
|
_counter = [0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _signup():
|
|
|
|
|
_counter[0] += 1
|
|
|
|
|
name = f"blk{int(time.time() * 1000)}{_counter[0]}"
|
|
|
|
|
session = requests.Session()
|
|
|
|
|
session.post(
|
|
|
|
|
f"{BASE_URL}/auth/signup",
|
|
|
|
|
data={
|
|
|
|
|
"username": name,
|
|
|
|
|
"email": f"{name}@t.dev",
|
|
|
|
|
"password": "secret123",
|
|
|
|
|
"confirm_password": "secret123",
|
Add the trust and safety subsystem and the App Store compliance work
Implements the moderation and consent obligations a social platform carries,
so the web version and any client that speaks to it enforce the same rules.
Moderation core (services/moderation/, database/moderation.py): a reportable
target registry, the content filter and its choke points, the report queue with
atomic resolution, enforcement actions, consent tracking, maturity gating, and
account deletion with a grace window.
Surfaces: POST /reports plus the member report list, /admin/moderation and the
per-report admin view, /workspaces, terms acceptance at /auth/terms, consent and
account deletion under /profile, the report button and dialog partials, the
maturity gate, and the moderation stylesheet and ReportDialog client.
Every user-generated surface stays reportable by construction: new content tables
are registered in REPORTABLE_TARGETS or listed in UNREPORTABLE_TABLES with a
reason, and the registry test fails the suite on anything left unclassified.
Docs: community guidelines, content moderation, intellectual property, privacy,
terms, contact, and the admin-only moderation operations page, plus the
moderation API group and the Devii moderation actions.
Compliance record: applecomp.md is the requirement register, applechanges.md the
gap analysis against this codebase, and appleimpl.md the implementation design
they resolve to.
Tests cover the report flow, admin moderation, consent, account deletion, terms
acceptance, workspaces, and the registry invariant across the unit, api, and e2e
tiers.
2026-08-09 00:18:20 +02:00
|
|
|
"birth_date": "1990-01-01",
|
|
|
|
|
"accept_terms": "1",
|
2026-06-19 10:06:09 +02:00
|
|
|
},
|
|
|
|
|
allow_redirects=True,
|
|
|
|
|
)
|
|
|
|
|
return session, name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _uid(name):
|
|
|
|
|
return get_table("users").find_one(username=name)["uid"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _key(name):
|
|
|
|
|
return get_table("users").find_one(username=name)["api_key"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _relation(actor_uid, target_uid, kind):
|
|
|
|
|
return get_table("user_relations").count(
|
|
|
|
|
user_uid=actor_uid, target_uid=target_uid, kind=kind, deleted_at=None
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_block_creates_relation(app_server):
|
|
|
|
|
blocker_session, blocker = _signup()
|
|
|
|
|
_, target = _signup()
|
|
|
|
|
r = blocker_session.post(
|
|
|
|
|
f"{BASE_URL}/block/{target}", allow_redirects=False
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code in (302, 200)
|
|
|
|
|
assert _relation(_uid(blocker), _uid(target), "block") == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_block_via_api_key_header(app_server):
|
|
|
|
|
blocker_session, blocker = _signup()
|
|
|
|
|
_, target = _signup()
|
|
|
|
|
r = requests.post(
|
|
|
|
|
f"{BASE_URL}/block/{target}",
|
|
|
|
|
headers={"X-API-KEY": _key(blocker)},
|
|
|
|
|
allow_redirects=False,
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code in (302, 200)
|
|
|
|
|
assert _relation(_uid(blocker), _uid(target), "block") == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_block_is_idempotent(app_server):
|
|
|
|
|
blocker_session, blocker = _signup()
|
|
|
|
|
_, target = _signup()
|
|
|
|
|
blocker_session.post(f"{BASE_URL}/block/{target}", allow_redirects=False)
|
|
|
|
|
blocker_session.post(f"{BASE_URL}/block/{target}", allow_redirects=False)
|
|
|
|
|
assert _relation(_uid(blocker), _uid(target), "block") == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_self_block_rejected(app_server):
|
|
|
|
|
blocker_session, blocker = _signup()
|
|
|
|
|
blocker_session.post(f"{BASE_URL}/block/{blocker}", allow_redirects=False)
|
|
|
|
|
assert _relation(_uid(blocker), _uid(blocker), "block") == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_block_nonexistent_user_redirects(app_server):
|
|
|
|
|
blocker_session, _ = _signup()
|
|
|
|
|
r = blocker_session.post(
|
|
|
|
|
f"{BASE_URL}/block/no_such_user_zzz", allow_redirects=False
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code == 302
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_block_no_credentials_redirects(app_server):
|
|
|
|
|
_, target = _signup()
|
|
|
|
|
r = requests.post(f"{BASE_URL}/block/{target}", allow_redirects=False)
|
|
|
|
|
assert r.status_code == 303
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_block_invalid_api_key_returns_401(app_server):
|
|
|
|
|
_, target = _signup()
|
|
|
|
|
r = requests.post(
|
|
|
|
|
f"{BASE_URL}/block/{target}",
|
|
|
|
|
headers={"X-API-KEY": "not-a-real-key"},
|
|
|
|
|
allow_redirects=False,
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code == 401
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_block_recorded_in_audit(seeded_db):
|
|
|
|
|
blocker_session, blocker = _signup()
|
|
|
|
|
blocker_session.post(
|
|
|
|
|
f"{BASE_URL}/block/bob_test", headers=JSON, allow_redirects=False
|
|
|
|
|
)
|
|
|
|
|
admin = requests.Session()
|
|
|
|
|
admin.headers.update({"X-API-KEY": _key("alice_test")})
|
|
|
|
|
data = admin.get(
|
|
|
|
|
f"{BASE_URL}/admin/audit-log",
|
|
|
|
|
headers=JSON,
|
|
|
|
|
params={"event_key": "relation.block"},
|
|
|
|
|
).json()
|
|
|
|
|
assert any(
|
|
|
|
|
e.get("target_label") == "bob_test" and blocker in (e.get("summary") or "")
|
|
|
|
|
for e in data["entries"]
|
|
|
|
|
)
|