fix: 会话改为可吊销,退出不再踢掉其他设备
This commit is contained in:
@@ -122,7 +122,10 @@ def test_legacy_default_password_is_replaced_and_failures_are_limited() -> None:
|
||||
client = TestClient(api.app)
|
||||
assert client.post("/api/login", json={"employee_id": "admin", "password": "242520"}).status_code == 400
|
||||
assert client.post("/api/login", json={"employee_id": "admin", "password": INITIAL_PASSWORD}).status_code == 200
|
||||
short = client.put("/api/admin/settings", json=_settings_body(admin_password="short"))
|
||||
short = client.put(
|
||||
"/api/admin/settings",
|
||||
json=_settings_body(admin_password="short", admin_password_current=INITIAL_PASSWORD),
|
||||
)
|
||||
assert short.status_code == 400
|
||||
|
||||
locked = TestClient(api.app)
|
||||
@@ -171,7 +174,12 @@ def test_seed_does_not_reset_saved_admin() -> None:
|
||||
assert client.post("/api/login", json={"employee_id": "admin", "password": INITIAL_PASSWORD}).status_code == 200
|
||||
saved = client.put(
|
||||
"/api/admin/settings",
|
||||
json=_settings_body(admin_username="ops", admin_password="next-secret", refresh_interval_minutes=15),
|
||||
json=_settings_body(
|
||||
admin_username="ops",
|
||||
admin_password="next-secret",
|
||||
admin_password_current=INITIAL_PASSWORD,
|
||||
refresh_interval_minutes=15,
|
||||
),
|
||||
)
|
||||
assert saved.status_code == 200
|
||||
assert saved.json()["admin_username"] == "ops"
|
||||
@@ -561,8 +569,10 @@ def test_credentials_and_delete_user() -> None:
|
||||
assert missing.json()["password"] == "secret-pass"
|
||||
assert missing.json()["yxt_token"] == ""
|
||||
|
||||
from euniv.session import seal
|
||||
|
||||
user = TestClient(api.app)
|
||||
user.cookies.set(COOKIE_NAME, encrypt_secret("6650000146"))
|
||||
user.cookies.set(COOKIE_NAME, seal("user", "6650000146"))
|
||||
assert user.get("/api/session").json() == {"role": "user", "employee_id": "6650000146"}
|
||||
removed = admin.delete("/api/admin/users/6650000146")
|
||||
assert removed.status_code == 200
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user