Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions api/v1/schemas/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
List, Annotated, Dict,
Literal)

from pydantic import (BaseModel, EmailStr,
field_validator, ConfigDict,
StringConstraints,
model_validator)

from pydantic import Field # Added this import
from pydantic import (
BaseModel,
EmailStr,
field_validator,
ConfigDict,
StringConstraints,
model_validator,
Field
)

def validate_mx_record(domain: str):
"""
Expand Down Expand Up @@ -252,6 +255,9 @@ def validate_password(cls, values: dict):
email = values.get("email")
totp_code = values.get("totp_code")

if not password:
return values

# constraints for password
if not any(c.islower() for c in password):
raise ValueError("password must include at least one lowercase character")
Expand Down
17 changes: 17 additions & 0 deletions tests/v1/auth/test_signin.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,23 @@ def test_swagger_ui_auth_form_handling(self):
assert response_json.get("status_code") == 422
assert response_json.get("message") == "Invalid input" or "Invalid" in response_json.get("message", "")

def test_user_login_failure_without_password(self, monkeypatch):
"""Test login failure when password is not provided"""

monkeypatch.setattr(
user_service,
"authenticate_user",
lambda db, email, password: self.mock_user
)

response = self.client.post(
"/api/v1/auth/login",
json={"email": "[email protected]"},
)
response_json = response.json()

assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert response_json.get("message") == "Invalid input"

# Mock the database dependency
@pytest.fixture
Expand Down