UI REST API: accounts, bearer auth, API apps, sessions, OpenAPI docs
CI / lint (push) Successful in 14s
CI / test (push) Successful in 28s
CI / notify (push) Successful in 5s

- flask-smorest API under /api/v1 with a uniform JSON error shape;
  spec at /api/openapi.json, Swagger UI at /api/docs, ReDoc at /api/redoc
- Register/login/logout/me with hashed, expiring bearer tokens,
  documented as an OpenAPI bearer security scheme
- API application and client-session management endpoints
- CORS restricted to the configured UI origin(s)
- Flask no longer serves static files: it is API-only
- Login and registration metrics

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Opus 5.5 committed 2026-09-25 13:59:59 +01:00
1 parent 9af8a4be8b
commit e026e56ee3
13 files changed
+626 -1

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
from conftest import signed
def test_app_crud(client, auth):
created = client.post("/api/v1/apps", json={"name": "Player"}, headers=auth)
assert created.status_code == 201
app_ = created.get_json()
assert len(app_["api_key"]) == len(app_["shared_secret"]) == 32
listed = client.get("/api/v1/apps", headers=auth).get_json()
assert [a["api_key"] for a in listed] == [app_["api_key"]]
assert client.delete(f"/api/v1/apps/{app_['api_key']}", headers=auth).status_code == 204
assert client.get("/api/v1/apps", headers=auth).get_json() == []
assert client.delete(f"/api/v1/apps/{app_['api_key']}", headers=auth).status_code == 404
def test_cannot_touch_other_users_apps(client, auth, make_user, make_app):
other = make_app(owner=make_user(username="mallory"))
assert client.delete(f"/api/v1/apps/{other.api_key}", headers=auth).status_code == 404
assert client.get("/api/v1/apps", headers=auth).get_json() == []
def test_revoked_session_key_stops_working(client, auth, api_app, session_key):
sessions = client.get("/api/v1/sessions", headers=auth).get_json()
assert [s["app_name"] for s in sessions] == [api_app.name]
assert client.delete(f"/api/v1/sessions/{sessions[0]['id']}", headers=auth).status_code == 204
params = signed(
{"method": "track.updateNowPlaying", "api_key": api_app.api_key, "sk": session_key},
api_app.shared_secret,
)
# The method is registered in a later step; the session check runs first either way.
response = client.post("/2.0/", data={**params, "format": "json"})
assert response.get_json()["error"] in (3, 9)