Reject non-ASCII Basic payloads before decoding
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user