forked from mtusi2026/mtusi2026lab2
fix whitespace and NULL validation
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user