feat(manager): v2 sign-in (login modes, support access, license notice) and an unlock endpoint for the lock screen
Platform-v2 step 2.6b:
- backend: POST /api/auth/unlock {pin|password} checks the CURRENT session's
user and keeps the session (no new login/token); 5 wrong tries end it
(auth.wrong_pin with attempts_left, then auth.session_ended); bootstrap
gains `login` (manager_mode, autofill_username, support)
- manager LoginPage rewritten on @xenia/ui + i18n: client "manager", password
or PIN pad per setting, remembered/only account card, support access panel
(challenge -> code -> 4 h session, not remembered as an account), notice
when the license runs the free tier (expired/inactive/locked/clock/unverified)
- lock screen on /api/auth/unlock with the shared PinPad
- @xenia/ui PinPad: variable length (minLength/maxLength, OK key, Enter)
- e2e manager.mjs: 33 checks (+ lockout after 5 wrong PINs, PIN login mode,
support access with a wrong then right code)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
"""Lock-screen unlock (plan step 2.6b): the session's own PIN, the same session kept,
|
||||
too many wrong tries end the session; the login settings in bootstrap."""
|
||||
from routers import auth as auth_router
|
||||
|
||||
TEST_PIN = "1234"
|
||||
|
||||
|
||||
def err(r):
|
||||
return r.json()["error"]["code"]
|
||||
|
||||
|
||||
def test_right_pin_unlocks_and_keeps_the_session(client, make_user, login):
|
||||
user = make_user("store_manager")
|
||||
headers = login(user)
|
||||
r = client.post("/api/auth/unlock", json={"pin": TEST_PIN}, headers=headers)
|
||||
assert r.status_code == 200, r.text
|
||||
assert r.json()["user"]["id"] == user.id
|
||||
assert "access_token" not in r.json() # no new token, no new session
|
||||
assert client.get("/api/auth/me", headers=headers).status_code == 200
|
||||
|
||||
|
||||
def test_password_also_unlocks(client, make_user, login):
|
||||
from tests.conftest import TEST_PASSWORD
|
||||
headers = login(make_user("store_manager"))
|
||||
assert client.post("/api/auth/unlock", json={"password": TEST_PASSWORD}, headers=headers).status_code == 200
|
||||
|
||||
|
||||
def test_wrong_pin_counts_down_then_ends_the_session(client, make_user, login):
|
||||
headers = login(make_user("store_manager"))
|
||||
left = []
|
||||
for _ in range(auth_router.UNLOCK_MAX_FAILURES - 1):
|
||||
r = client.post("/api/auth/unlock", json={"pin": "0000"}, headers=headers)
|
||||
assert r.status_code == 401 and err(r) == "auth.wrong_pin"
|
||||
left.append(r.json()["error"]["params"]["attempts_left"])
|
||||
assert left == list(range(auth_router.UNLOCK_MAX_FAILURES - 1, 0, -1))
|
||||
assert client.get("/api/auth/me", headers=headers).status_code == 200, "still signed in before the last try"
|
||||
r = client.post("/api/auth/unlock", json={"pin": "0000"}, headers=headers)
|
||||
assert r.status_code == 401 and err(r) == "auth.session_ended"
|
||||
assert err(client.get("/api/auth/me", headers=headers)) == "auth.session_ended"
|
||||
|
||||
|
||||
def test_a_success_resets_the_count(client, make_user, login):
|
||||
headers = login(make_user("store_manager"))
|
||||
for _ in range(auth_router.UNLOCK_MAX_FAILURES - 1):
|
||||
client.post("/api/auth/unlock", json={"pin": "0000"}, headers=headers)
|
||||
assert client.post("/api/auth/unlock", json={"pin": TEST_PIN}, headers=headers).status_code == 200
|
||||
r = client.post("/api/auth/unlock", json={"pin": "0000"}, headers=headers)
|
||||
assert r.json()["error"]["params"]["attempts_left"] == auth_router.UNLOCK_MAX_FAILURES - 1
|
||||
|
||||
|
||||
def test_the_pin_is_the_session_owners(client, make_user, login):
|
||||
import bcrypt
|
||||
other = make_user("store_manager", pin_hash=bcrypt.hashpw(b"5678", bcrypt.gensalt(4)).decode())
|
||||
headers = login(other) # another user's PIN (1234) must not unlock it
|
||||
assert err(client.post("/api/auth/unlock", json={"pin": TEST_PIN}, headers=headers)) == "auth.wrong_pin"
|
||||
|
||||
|
||||
def test_needs_a_session(client):
|
||||
assert client.post("/api/auth/unlock", json={"pin": TEST_PIN}).status_code in (401, 403)
|
||||
|
||||
|
||||
def test_bootstrap_has_the_login_settings(client, db):
|
||||
from models.settings import PosSettings
|
||||
b = client.get("/api/platform/bootstrap").json()
|
||||
assert b["login"]["manager_mode"] == "password"
|
||||
assert b["login"]["autofill_username"] is True
|
||||
assert b["login"]["support"] in (True, False)
|
||||
row = db.query(PosSettings).filter(PosSettings.key == "auth.manager_login_mode").first()
|
||||
if row is None:
|
||||
db.add(PosSettings(key="auth.manager_login_mode", value="pin"))
|
||||
else:
|
||||
row.value = "pin"
|
||||
db.commit()
|
||||
assert client.get("/api/platform/bootstrap").json()["login"]["manager_mode"] == "pin"
|
||||
Reference in New Issue
Block a user