feat: add password login and bearer sessions

- Argon2id password hashes, KDF in a thread with its own limit
- POST /auth/sessions with Basic, DELETE /auth/sessions/current
- Bearer sessions in PostgreSQL, X-User-Id ignored
- migration drops lab 1 data without passwords
- student-tests on tokens, sessions spec and synced specs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 18:50:42 +03:00
co-authored by Claude Opus 5.5
parent ee2643d21e
commit ae4154eaf5
68 changed files with 2946 additions and 314 deletions
+24 -6
View File
@@ -5,8 +5,13 @@ from typing import Any
import pytest
from api_client import API, Actor, Api, order_key
from contract import assert_error
from api_client import API, Actor, Api, order_key, registration
from contract import (
BASIC_CHALLENGE,
BEARER_CHALLENGE,
assert_error,
assert_unauthorized,
)
@pytest.mark.spec("api-conventions", "Битый JSON")
@@ -75,14 +80,27 @@ def test_duplicate_username(api: Api, alice: Actor) -> None:
resp = api.request(
"POST",
f"{API}/users",
json={
"username": alice.user["username"],
"display_name": "Другая Алиса",
},
json=registration(alice.username, "Другая Алиса"),
)
assert_error(resp, 409)
@pytest.mark.spec("sessions", "Неверный пароль")
def test_wrong_password(api: Api, alice: Actor) -> None:
resp = api.login_response(alice.username, alice.password + "-wrong")
assert_unauthorized(resp, BASIC_CHALLENGE)
assert "token" not in resp.json()
@pytest.mark.spec("sessions", "Выход")
def test_logout(api: Api, alice: Actor) -> None:
resp = api.logout(alice)
assert resp.status_code == 204, resp.text
assert resp.content == b""
after = api.request("GET", f"{API}/users/me", actor=alice)
assert_unauthorized(after, BEARER_CHALLENGE)
def test_history_walk_across_pages(
api: Api,
alice: Actor,