feat(backend): DB sessions, login modes, single-session rules
Platform v2 step 1.6 (APPS_PLATFORM D-8, D-9, §6.2, §6.4).
- sessions table (revision 0006); every JWT carries `sid` and is accepted
only while its session is active (validated per request, 10 s cache that
is dropped the moment a session ends); the in-memory blacklist is gone, so
logout and "end session" survive restarts
- one login path, POST /api/auth/login {client, username?, user_id?, pin?,
password?}: manager mode password|pin (username-only "none" removed, D-8),
waiter mode pin|password|tap (tap answers auth.mode_needs_device until
paired devices exist), optional "waiter must type username", and the app's
access key (core.dashboard.access / waiter_app.access)
- auth.single_session_manager / _waiter: off | refuse_new | end_old
- /login without `client` = the current manager UI with v1 rules (pin or
password; refuse_new treated as end_old because its lock screen re-logs-in);
/login-by-id is a deprecated wrapper for the current waiter app;
/login-no-auth removed
- GET /api/auth/sessions, POST /api/auth/sessions/{id}/end (core.staff.manage);
blocking a user ends their sessions; refresh keeps the session; logout
takes the bearer header (or ?token= as before)
- settings API validates enum/bool/int values from the manifests;
security.login_method migrated to auth.manager_login_mode
- tests: modes, single-session rules, logout, refresh, forged token without
session, manager session list/end
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -83,6 +83,8 @@ def _venue_time():
|
||||
entitlements.reset()
|
||||
timeutil.invalidate()
|
||||
i18n.invalidate()
|
||||
from core import sessions
|
||||
sessions.clear_cache()
|
||||
from core.modules import state as module_state
|
||||
module_state.invalidate() # module enablement is cached; each test starts from the DB
|
||||
|
||||
@@ -193,12 +195,14 @@ def make_user(db):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def login():
|
||||
"""login(user) -> {"Authorization": "Bearer ..."} without calling the API (fast).
|
||||
Tests about the login flow itself should POST /api/auth/login instead."""
|
||||
def login(db):
|
||||
"""login(user, client="manager") -> {"Authorization": "Bearer ..."} with a real session row,
|
||||
without calling the login API (fast). Tests about the login flow itself POST /api/auth/login."""
|
||||
from core import sessions
|
||||
from routers.deps import make_token
|
||||
|
||||
def _login(user):
|
||||
return {"Authorization": f"Bearer {make_token(user)}"}
|
||||
def _login(user, client="manager"):
|
||||
row = sessions.start(db, user, client)
|
||||
return {"Authorization": f"Bearer {make_token(user, row.id)}"}
|
||||
|
||||
return _login
|
||||
|
||||
Reference in New Issue
Block a user