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_token = [0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
|
|
|
def _token_settings(app_server):
|
|
|
|
|
for key, value in {
|
|
|
|
|
"rate_limit_per_minute": "1000000",
|
|
|
|
|
"rate_limit_window_seconds": "60",
|
|
|
|
|
"registration_open": "1",
|
|
|
|
|
"maintenance_mode": "0",
|
|
|
|
|
"session_max_age_days": "7",
|
|
|
|
|
}.items():
|
|
|
|
|
set_setting(key, value)
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _signup(password="secret123"):
|
|
|
|
|
_counter_token[0] += 1
|
|
|
|
|
name = f"tok{int(time.time() * 1000)}{_counter_token[0]}"
|
|
|
|
|
email = f"{name}@t.dev"
|
|
|
|
|
requests.post(
|
|
|
|
|
f"{BASE_URL}/auth/signup",
|
|
|
|
|
data={
|
|
|
|
|
"username": name,
|
|
|
|
|
"email": email,
|
|
|
|
|
"password": password,
|
|
|
|
|
"confirm_password": password,
|
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,
|
|
|
|
|
)
|
|
|
|
|
return name, email, password
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_token_happy_path_with_email(app_server):
|
|
|
|
|
name, email, password = _signup()
|
|
|
|
|
r = requests.post(f"{BASE_URL}/auth/token", data={"email": email, "password": password})
|
|
|
|
|
assert r.status_code == 200, r.text[:300]
|
|
|
|
|
body = r.json()
|
|
|
|
|
assert body["access_token"] and len(body["access_token"]) >= 32
|
|
|
|
|
assert body["token_type"]
|
|
|
|
|
assert isinstance(body["expires_in"], int) and body["expires_in"] > 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_token_accepts_username_as_identifier(app_server):
|
|
|
|
|
name, email, password = _signup()
|
|
|
|
|
r = requests.post(f"{BASE_URL}/auth/token", data={"email": name, "password": password})
|
|
|
|
|
assert r.status_code == 200, r.text[:300]
|
|
|
|
|
assert r.json()["access_token"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_token_via_json_body(app_server):
|
|
|
|
|
name, email, password = _signup()
|
|
|
|
|
r = requests.post(
|
|
|
|
|
f"{BASE_URL}/auth/token",
|
|
|
|
|
json={"email": email, "password": password},
|
|
|
|
|
headers={"Content-Type": "application/json"},
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code == 200, r.text[:300]
|
|
|
|
|
assert r.json()["access_token"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_token_wrong_password_401(app_server):
|
|
|
|
|
name, email, password = _signup()
|
|
|
|
|
r = requests.post(f"{BASE_URL}/auth/token", data={"email": email, "password": "nope!!"})
|
|
|
|
|
assert r.status_code == 401
|
|
|
|
|
assert "access_token" not in r.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_token_unknown_identifier_401(app_server):
|
|
|
|
|
r = requests.post(
|
|
|
|
|
f"{BASE_URL}/auth/token",
|
|
|
|
|
data={"email": "no_such_user_zzz@t.dev", "password": "whatever"},
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code == 401
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_token_empty_password_rejected(app_server):
|
|
|
|
|
name, email, password = _signup()
|
|
|
|
|
r = requests.post(
|
|
|
|
|
f"{BASE_URL}/auth/token",
|
|
|
|
|
headers={"Accept": "application/json"},
|
|
|
|
|
data={"email": email, "password": ""},
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code in (400, 401, 422)
|
|
|
|
|
assert "access_token" not in r.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_token_inactive_account_403(app_server):
|
|
|
|
|
name, email, password = _signup()
|
|
|
|
|
users = get_table("users")
|
|
|
|
|
row = users.find_one(username=name)
|
|
|
|
|
users.update({"uid": row["uid"], "is_active": False}, ["uid"])
|
|
|
|
|
refresh_snapshot()
|
|
|
|
|
try:
|
|
|
|
|
r = requests.post(
|
|
|
|
|
f"{BASE_URL}/auth/token", data={"email": email, "password": password}
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code == 403, r.text[:300]
|
|
|
|
|
assert "access_token" not in r.json()
|
|
|
|
|
finally:
|
|
|
|
|
users.update({"uid": row["uid"], "is_active": True}, ["uid"])
|
|
|
|
|
refresh_snapshot()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_token_is_usable_as_bearer_credential(app_server):
|
|
|
|
|
name, email, password = _signup()
|
|
|
|
|
token = requests.post(
|
|
|
|
|
f"{BASE_URL}/auth/token", data={"email": email, "password": password}
|
|
|
|
|
).json()["access_token"]
|
|
|
|
|
target, _, _ = _signup()
|
|
|
|
|
r = requests.post(
|
|
|
|
|
f"{BASE_URL}/follow/{target}",
|
|
|
|
|
headers={"Authorization": f"Bearer {token}"},
|
|
|
|
|
allow_redirects=False,
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code in (200, 302), r.text[:200]
|