fix whitespace and NULL validation
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-28 20:31:49 +03:00
parent 7a72faf0e9
commit f75ad8cc97
15 changed files with 248 additions and 145 deletions
+33
View File
@@ -263,3 +263,36 @@ async def test_unknown_user_takes_comparable_time_to_wrong_password(
unknown_user = await measure("no_such_user")
assert unknown_user > wrong_password * 0.5
async def test_invalid_basic_username_returns_401_not_500(client: AsyncClient):
user = await register(client)
reference = await client.post(
"/api/v1/auth/sessions",
headers=basic_header(user["username"], "wrong-password-123"),
)
for username in ("bad\u0000name", "UPPER", "no", "x" * 33, "имя", "a b c"):
response = await client.post(
"/api/v1/auth/sessions",
headers=basic_header(username, "wrong-password-123"),
)
assert response.status_code == 401, username
assert (
response.json()["error"]["message"] == reference.json()["error"]["message"]
)
assert (
response.headers["WWW-Authenticate"]
== reference.headers["WWW-Authenticate"]
)
async def test_whitespace_only_password_at_login_returns_401(client: AsyncClient):
user = await register(client)
response = await client.post(
"/api/v1/auth/sessions", headers=basic_header(user["username"], " " * 12)
)
assert response.status_code == 401
assert response.headers["WWW-Authenticate"].startswith("Basic")