fix: 会话改为可吊销,退出不再踢掉其他设备

This commit is contained in:
2026-11-16 02:39:15 +08:00
parent 0fbc3146d8
commit 08e5a1b849
13 changed files with 242 additions and 62 deletions
+23
View File
@@ -153,6 +153,7 @@ def test_login_stores_password_and_credential_only() -> None:
"study_stop_month",
"study_ignore_window",
"study_schedule_enabled",
"sessions_valid_after",
}
home = client.get("/api/home")
@@ -334,6 +335,28 @@ def test_browser_session_logout_and_revoke() -> None:
assert decrypt_secret(account.password_cipher) == "secret-pass"
def test_logout_keeps_the_other_browser_until_revoke() -> None:
import euniv.api as api_module
import euniv.service as service_module
api_module.login_and_store = lambda db, employee_id, password, manual=False, auto_attempts=3: service_module.login_and_store(
db, employee_id, password, FakeClient, manual=manual, auto_attempts=auto_attempts
)
first = TestClient(api_module.app)
assert first.post("/api/login", json={"employee_id": "6650000146", "password": "secret-pass"}).status_code == 200
saved = first.cookies.get("euniv_session")
assert saved
other = TestClient(api_module.app)
other.cookies.set("euniv_session", saved)
assert first.post("/api/logout").status_code == 200
assert first.get("/api/session").status_code == 401
assert other.get("/api/session").status_code == 200
assert other.post("/api/revoke").status_code == 200
stale = TestClient(api_module.app)
stale.cookies.set("euniv_session", saved)
assert stale.get("/api/session").status_code == 401
def test_parse_training_cards_keeps_status() -> None:
from euniv.client import parse_training_cards