From d687c0d50d53b481d1b0abc1ca7babe4678dcf82 Mon Sep 17 00:00:00 2001 From: Ikechukwu Ugwuanyi Date: Sat, 1 Mar 2025 22:05:03 +0100 Subject: [PATCH 1/3] feat: add check for existence of password on login --- api/v1/schemas/user.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/v1/schemas/user.py b/api/v1/schemas/user.py index 095135e11..ec9aa38f4 100644 --- a/api/v1/schemas/user.py +++ b/api/v1/schemas/user.py @@ -252,6 +252,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") From d6b1b51e5ff778548328e7335ce78e066ae20026 Mon Sep 17 00:00:00 2001 From: Ikechukwu Ugwuanyi Date: Sat, 1 Mar 2025 22:06:52 +0100 Subject: [PATCH 2/3] chore: move Field import from pydantic to already existing import statement --- api/v1/schemas/user.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/api/v1/schemas/user.py b/api/v1/schemas/user.py index ec9aa38f4..f0f4702ea 100644 --- a/api/v1/schemas/user.py +++ b/api/v1/schemas/user.py @@ -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): """ From 604c27d596625ecf6714496edcbf985a93ff0919 Mon Sep 17 00:00:00 2001 From: Ikechukwu Ugwuanyi Date: Sat, 1 Mar 2025 23:24:17 +0100 Subject: [PATCH 3/3] chore: add a test for password missing in login request --- tests/v1/auth/test_signin.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/v1/auth/test_signin.py b/tests/v1/auth/test_signin.py index e940a79e7..cb2660772 100644 --- a/tests/v1/auth/test_signin.py +++ b/tests/v1/auth/test_signin.py @@ -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": "testuser1@gmail.com"}, + ) + 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