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
+26 -1
View File
@@ -52,7 +52,9 @@ async def test_invalid_user_payloads(client: AsyncClient, body: dict):
async def test_password_length_boundaries_are_accepted(client: AsyncClient):
for index, password in enumerate(["x" * 12, "y" * 128, " " * 12, "п" * 12]):
for index, password in enumerate(
["x" * 12, "y" * 128, "п" * 12, " spaces inside "]
):
response = await client.post(
"/api/v1/users",
json={
@@ -101,3 +103,26 @@ async def test_user_exact_length_boundaries_are_accepted(client: AsyncClient):
user = await register(client, username=("a" * length), display_name="d" * 100)
assert len(user["username"]) == length
assert len(user["display_name"]) == 100
@pytest.mark.parametrize("password", [" " * 12, "\t" * 12, " \n" * 6])
async def test_whitespace_only_password_is_rejected(client: AsyncClient, password: str):
response = await client.post(
"/api/v1/users",
json={"username": "blank_pw", "display_name": "Blank", "password": password},
)
assert response.status_code == 400
assert response.json()["error"]["code"] == "invalid_request"
assert_request_id(response)
@pytest.mark.parametrize("field", ["display_name", "password"])
async def test_nul_in_user_fields_is_rejected(client: AsyncClient, field: str):
body = {"username": "nul_user", "display_name": "Nul", "password": PASSWORD}
body[field] = body[field] + "\u0000tail"
response = await client.post("/api/v1/users", json=body)
assert response.status_code == 400
assert response.json()["error"]["code"] == "invalid_request"