This commit is contained in:
prajwal-3-14159 2026-09-23 14:51:45 +00:00 • committed by GitHub
commit fb57791dd7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 0 deletions

View file

@ -4080,6 +4080,8 @@ async def delete_key_fn(
return {"deleted_keys": deleted_keys}
except Exception as e:
if isinstance(e, HTTPException):
raise handle_exception_on_proxy(e)
verbose_proxy_logger.exception("litellm.proxy.proxy_server.delete_key_fn(): Exception occured - %s", e)
raise handle_exception_on_proxy(e)
@ -4974,6 +4976,8 @@ async def delete_verification_tokens(
else:
raise Exception("DB not connected. prisma_client is None")
except Exception as e:
if isinstance(e, HTTPException):
raise
verbose_proxy_logger.exception(
"litellm.proxy.proxy_server.delete_verification_tokens(): Exception occured - %s", e
)

View file

@ -5675,6 +5675,42 @@ async def test_delete_key_fn_persists_deleted_keys(monkeypatch):
assert result["deleted_keys"] == ["sk-token-1"]
@pytest.mark.asyncio
async def test_delete_key_fn_404_not_found(monkeypatch):
"""Test that deleting a non-existent key raises a 404 cleanly."""
from litellm.proxy._types import KeyRequest, ProxyException
from litellm.proxy.management_endpoints.key_management_endpoints import delete_key_fn
from fastapi import HTTPException
mock_prisma_client = AsyncMock()
mock_user_api_key_cache = MagicMock()
user_api_key_dict = UserAPIKeyAuth(
user_id="admin-user",
api_key="sk-admin",
user_role=LitellmUserRoles.PROXY_ADMIN.value,
)
# Mock find_many to return an empty list, simulating a key that isn't found
mock_prisma_client.verificationtoken.find_many.return_value = []
monkeypatch.setattr(
"litellm.proxy.proxy_server.prisma_client",
mock_prisma_client,
)
data = KeyRequest(keys=["sk-nonexistent-key"])
with pytest.raises(ProxyException) as excinfo:
await delete_key_fn(
data=data,
user_api_key_dict=user_api_key_dict,
litellm_changed_by="admin-user",
)
assert "No keys found" in str(excinfo.value)
@pytest.mark.asyncio
async def test_can_delete_verification_token_proxy_admin_team_key(monkeypatch):
"""Test that team admin can delete team keys from their own team."""