Port final lab 5 validation, session and PNG recovery fixes

This commit is contained in:
Artyom
2026-11-07 02:35:40 +03:00
parent 97feb04b3f
commit bc1d7aa771
41 changed files with 4363 additions and 53 deletions
+28
View File
@@ -86,6 +86,34 @@ async def test_login_without_valid_basic(client: AsyncClient, headers: dict) ->
challenged(await client.post("/api/v1/auth/sessions", headers=headers), BASIC)
@pytest.mark.parametrize(
"raw", [b"Basic \x80", b"Basic \xff", b"Basic \xc3\xa9", b"Basic YWxpY2U6c2VjcmV0\xff"]
)
async def test_non_ascii_basic_matches_wrong_password(client: AsyncClient, raw: bytes) -> None:
alice = await register(client, "non_ascii_basic")
count = (
select(func.count()).select_from(SessionRow).where(SessionRow.user_id == UUID(alice["id"]))
)
before = await scalar(count)
wrong = await client.post(
"/api/v1/auth/sessions",
headers={**basic(alice["username"], "wrong-password"), "X-Request-Id": "non-ascii-basic"},
)
invalid = await client.post(
"/api/v1/auth/sessions",
headers={b"Authorization": raw, b"X-Request-Id": b"non-ascii-basic"},
)
for response in [wrong, invalid]:
challenged(response, BASIC)
assert response.headers["X-Instance-Id"]
assert response.headers["content-type"].startswith("application/json")
assert set(response.json()) == {"error"}
assert set(response.json()["error"]) == {"code", "message", "request_id"}
assert response.json()["error"]["message"]
assert wrong.json() == invalid.json()
assert await scalar(count) == before
async def test_password_with_colon_logs_in(client: AsyncClient) -> None:
body = new_user("colon", password="пароль:с:двоеточием")
assert (await client.post("/api/v1/users", json=body)).status_code == 201