Compare commits

..

No commits in common. "0d9c48c6b5300daf840a55d3b378b9a6f70f5d6b" and "895342a8ba976caa41f4b5b9fdec1c684e47dc5d" have entirely different histories.

5 changed files with 1 additions and 61 deletions

View File

@ -14,7 +14,6 @@ from .errors import (
InvalidOrExpiredOtpError,
InvalidPhoneNumberError,
InvalidTokenError,
SamePasswordError,
UnauthorizedError,
UserAlreadyExistsError,
UserInactiveError,
@ -76,7 +75,6 @@ def _translate_auth_error(exc: Exception) -> HTTPException:
WeakPasswordError,
UserAlreadyExistsError,
CurrentPasswordIncorrectError,
SamePasswordError,
),
):
return HTTPException(

View File

@ -45,9 +45,5 @@ class CurrentPasswordIncorrectError(AuthError):
pass
class SamePasswordError(AuthError):
pass
class InvalidOrExpiredOtpError(AuthError):
pass

View File

@ -12,7 +12,6 @@ from .errors import (
CurrentPasswordIncorrectError,
InvalidCredentialsError,
InvalidOrExpiredOtpError,
SamePasswordError,
UnauthorizedError,
UserAlreadyExistsError,
UserInactiveError,
@ -261,14 +260,6 @@ class AuthService:
"Current password is incorrect. Please enter your valid current password."
)
if (
request.old_password == request.new_password
or verify_password(request.new_password, user.password_hash)
):
raise SamePasswordError(
"New password cannot be the same as current password."
)
validate_password_strength(request.new_password)
await self.repository.update_password_hash(

View File

@ -7,7 +7,7 @@ from httpx import AsyncClient
from app.main import app
from app.features.auth.deps import get_auth_service
from app.features.auth.errors import InvalidCredentialsError, SamePasswordError, UserAlreadyExistsError
from app.features.auth.errors import InvalidCredentialsError, UserAlreadyExistsError
from app.features.auth.schema import (
AuthTokenResponse,
AuthTokenUserResponse,
@ -169,21 +169,3 @@ async def test_forgot_password_success(async_client: AsyncClient, mock_auth_serv
assert response.status_code == 200
assert response.json()["status"] == "success"
assert mock_auth_service.send_password_reset_email.await_count == 1
@pytest.mark.asyncio
async def test_change_password_same_password_returns_400(async_client: AsyncClient, mock_auth_service: MagicMock) -> None:
mock_auth_service.change_password = AsyncMock(side_effect=SamePasswordError("New password cannot be the same as current password."))
app.dependency_overrides[get_auth_service] = lambda: mock_auth_service
payload = {
"old_password": "OldPassword123!",
"new_password": "OldPassword123!",
}
headers = {"Authorization": "Bearer sample_valid_token"}
response = await async_client.post("/api/auth/change-password", json=payload, headers=headers)
app.dependency_overrides.pop(get_auth_service, None)
assert response.status_code == 400
assert "New password cannot be the same as current password" in response.json()["detail"]

View File

@ -170,30 +170,3 @@ class TestJWTTokens:
def test_verify_password_catches_invalid_salt_format(self) -> None:
# Format passes startswith $2b$ but is invalid for bcrypt.checkpw
assert verify_password("pass", "$2b$invalid_format_hash") is False
@pytest.mark.asyncio
async def test_change_password_same_password_raises(self) -> None:
from unittest.mock import AsyncMock, MagicMock
from uuid import uuid4
from app.features.auth.service import AuthService
from app.features.auth.schema import ChangePasswordRequest
from app.features.auth.errors import SamePasswordError
mock_session = AsyncMock()
mock_repo = AsyncMock()
user = MagicMock()
user.id = uuid4()
user.password_hash = hash_password("ValidPass123!")
mock_repo.get_user_by_id = AsyncMock(return_value=user)
token = create_access_token({"sub": str(user.id)})
service = AuthService(
session=mock_session,
repository=mock_repo,
password_reset_email_sender=MagicMock(),
)
req = ChangePasswordRequest(old_password="ValidPass123!", new_password="ValidPass123!")
with pytest.raises(SamePasswordError, match="cannot be the same"):
await service.change_password(access_token=token, request=req)