2026-06-23 02:47:40 +02:00
|
|
|
# retoor <retoor@molodetz.nl>
|
|
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
import pytest
|
|
|
|
|
import requests
|
|
|
|
|
from tests.conftest import BASE_URL
|
|
|
|
|
from devplacepy.database import get_table, refresh_snapshot, set_setting
|
|
|
|
|
|
|
|
|
|
_counter_uu = [0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
|
|
|
def _upload_settings(app_server):
|
|
|
|
|
for key, value in {
|
|
|
|
|
"rate_limit_per_minute": "1000000",
|
|
|
|
|
"rate_limit_window_seconds": "60",
|
|
|
|
|
"registration_open": "1",
|
|
|
|
|
"maintenance_mode": "0",
|
|
|
|
|
"max_upload_size_mb": "10",
|
|
|
|
|
"allowed_file_types": "",
|
|
|
|
|
}.items():
|
|
|
|
|
set_setting(key, value)
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _key():
|
|
|
|
|
_counter_uu[0] += 1
|
|
|
|
|
name = f"uu{int(time.time() * 1000)}{_counter_uu[0]}"
|
|
|
|
|
requests.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-23 02:47:40 +02:00
|
|
|
},
|
|
|
|
|
allow_redirects=True,
|
|
|
|
|
)
|
|
|
|
|
refresh_snapshot()
|
|
|
|
|
return get_table("users").find_one(username=name)["api_key"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _post(url, key, filename=None):
|
|
|
|
|
headers = {"X-API-KEY": key} if key else {}
|
|
|
|
|
data = {"url": url}
|
|
|
|
|
if filename:
|
|
|
|
|
data["filename"] = filename
|
|
|
|
|
return requests.post(f"{BASE_URL}/uploads/upload-url", headers=headers, data=data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_upload_url_requires_auth(app_server):
|
|
|
|
|
r = _post("http://example.com/x.png", None)
|
|
|
|
|
assert r.status_code == 401
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_upload_url_invalid_key(app_server):
|
|
|
|
|
r = _post("http://example.com/x.png", "not-a-real-key")
|
|
|
|
|
assert r.status_code == 401
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_upload_url_empty_url_validation(app_server):
|
|
|
|
|
r = requests.post(
|
|
|
|
|
f"{BASE_URL}/uploads/upload-url",
|
|
|
|
|
headers={"X-API-KEY": _key(), "Accept": "application/json"},
|
|
|
|
|
data={"url": ""},
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code == 422
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_upload_url_rejects_loopback_ssrf(app_server):
|
|
|
|
|
r = _post("http://127.0.0.1/payload.png", _key())
|
|
|
|
|
assert r.status_code == 400
|
|
|
|
|
assert "private or local" in r.json()["error"].lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_upload_url_rejects_private_range_ssrf(app_server):
|
|
|
|
|
r = _post("http://10.0.0.1/payload.png", _key())
|
|
|
|
|
assert r.status_code == 400
|
|
|
|
|
assert "private or local" in r.json()["error"].lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_upload_url_rejects_non_http_scheme(app_server):
|
|
|
|
|
r = _post("ftp://example.com/payload.png", _key())
|
|
|
|
|
assert r.status_code == 400
|
|
|
|
|
assert "http" in r.json()["error"].lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_upload_url_unresolvable_host(app_server):
|
|
|
|
|
r = _post("http://nonexistent.invalid.zzz/payload.png", _key())
|
|
|
|
|
assert r.status_code == 400
|
|
|
|
|
assert "resolve" in r.json()["error"].lower()
|