167 lines
4.7 KiB
Python
Raw Normal View History

# retoor <retoor@molodetz.nl>
import os
import sys
import time
import socket
import subprocess
import xmlrpc.client
import pytest
import requests
from tests.conftest import BASE_URL, PROJECT_ROOT
from devplacepy.database import get_table, refresh_snapshot, set_setting
BRIDGE_PORT = 10566
_counter_rpc = [0]
def _port_open(port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.settimeout(0.5)
return sock.connect_ex(("127.0.0.1", port)) == 0
@pytest.fixture(scope="module", autouse=True)
def _rpc_settings(app_server):
set_setting("rate_limit_per_minute", "1000000")
set_setting("registration_open", "1")
yield
@pytest.fixture(scope="module")
def bridge(app_server):
"""Run the XML-RPC bridge against the test server on a dedicated free port.
The proxy route (``/xmlrpc``) targets the default bridge port (10550), which a
locally-running dev server may already occupy and forward to its own DB. Driving
a dedicated bridge directly keeps this test hermetic: the bridge still forwards to
the live test REST server, so method dispatch, auth and faults are exercised end
to end regardless of the host environment.
"""
env = os.environ.copy()
env["DEVPLACE_INTERNAL_BASE_URL"] = BASE_URL
env["DEVPLACE_XMLRPC_BIND"] = "127.0.0.1"
env["DEVPLACE_XMLRPC_PORT"] = str(BRIDGE_PORT)
env["PYTHONUNBUFFERED"] = "1"
proc = subprocess.Popen(
[sys.executable, "-m", "devplacepy.services.xmlrpc.server"],
cwd=str(PROJECT_ROOT),
env=env,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
)
deadline = time.time() + 20
while time.time() < deadline:
if _port_open(BRIDGE_PORT):
break
if proc.poll() is not None:
raise RuntimeError("XML-RPC bridge process died during startup")
time.sleep(0.3)
else:
proc.terminate()
raise RuntimeError("XML-RPC bridge did not start")
yield proc
proc.terminate()
try:
proc.wait(timeout=5)
except Exception:
proc.kill()
def _proxy():
return xmlrpc.client.ServerProxy(
f"http://127.0.0.1:{BRIDGE_PORT}/", allow_none=True
)
def _api_key():
_counter_rpc[0] += 1
name = f"rpc{int(time.time() * 1000)}{_counter_rpc[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",
},
allow_redirects=True,
)
refresh_snapshot()
user = get_table("users").find_one(username=name)
return name, user["uid"], user["api_key"]
def test_get_usage_text(app_server):
r = requests.get(f"{BASE_URL}/xmlrpc")
assert r.status_code == 200
assert "system.listMethods" in r.text
assert "XML-RPC" in r.text
def test_get_usage_on_subpath(app_server):
r = requests.get(f"{BASE_URL}/xmlrpc/anything")
assert r.status_code == 200
assert "system.listMethods" in r.text
def test_list_methods(bridge):
methods = _proxy().system.listMethods()
assert isinstance(methods, list)
assert "system.listMethods" in methods
assert "posts.create" in methods
assert "feed.list" in methods
def test_method_help_introspection(bridge):
help_text = _proxy().system.methodHelp("posts.create")
assert isinstance(help_text, str) and help_text
def test_read_method_forwarded(bridge):
result = _proxy().feed.list({})
assert result is not None
def test_authenticated_write_creates_post(bridge):
name, uid, key = _api_key()
_proxy().posts.create(
{
"title": "rpc title",
"content": "created via the xml-rpc bridge end to end",
"topic": "devlog",
"api_key": key,
}
)
refresh_snapshot()
assert get_table("posts").count(user_uid=uid, deleted_at=None) == 1
def test_unauthenticated_write_creates_nothing(bridge):
name, uid, key = _api_key()
try:
_proxy().posts.create(
{"title": "no auth", "content": "no api key supplied here", "topic": "devlog"}
)
except xmlrpc.client.Fault:
pass
refresh_snapshot()
assert get_table("posts").count(user_uid=uid, deleted_at=None) == 0
def test_missing_required_param_raises_fault(bridge):
with pytest.raises(xmlrpc.client.Fault):
_proxy().posts.create({})
def test_multicall(bridge):
multi = xmlrpc.client.MultiCall(_proxy())
multi.system.listMethods()
multi.system.listMethods()
results = list(multi())
assert len(results) == 2
assert "system.listMethods" in results[0]