diff --git a/app/api/schemas.py b/app/api/schemas.py index 145b0c0..6b3752b 100644 --- a/app/api/schemas.py +++ b/app/api/schemas.py @@ -34,9 +34,9 @@ class CreateUser(Strict): display_name: str = Field(min_length=1, max_length=NAME_MAX) password: str = Field(min_length=12, max_length=128) - @field_validator('display_name') + @field_validator('display_name', 'password') @classmethod - def _display_name(cls, value: str) -> str: + def _not_blank(cls, value: str) -> str: return not_blank(value) diff --git a/tests/test_validation.py b/tests/test_validation.py index 5c02c4a..85c9865 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -10,6 +10,14 @@ def test_rejects_duplicate_username(actors): client.call('POST', '/api/v1/users', 409, body=alice['registration']) +def test_rejects_blank_password(client): + response = client.call( + 'POST', '/api/v1/users', 400, + body={'username': 'blank_password', 'display_name': 'Blank password', 'password': ' ' * 12}, + ) + assert response['json']['error']['code'] == 'invalid_request' + + def test_hides_chat_from_outsider(actors): client, _, _, eve, chat = actors client.call('GET', '/api/v1/chats/' + chat['id'], 404, actor=eve)