test(proxy): pin JWT scope denial message shape through auth exception conversion

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
yassin 2026-09-16 00:46:59 +00:00
parent 241b177f05
commit 14d239fc84

View file

@ -36,7 +36,7 @@ from litellm.proxy._types import (
ProxyException,
UserAPIKeyAuth,
)
from litellm.proxy.auth.auth_exception_handler import UserAPIKeyAuthExceptionHandler
from litellm.proxy.auth.auth_exception_handler import UserAPIKeyAuthExceptionHandler, _as_proxy_exception
from litellm.proxy.auth.model_access_denied import ModelAccessDeniedHTTPException
@ -1053,6 +1053,21 @@ async def test_handle_authentication_error_keeps_internal_message_on_model_acces
assert [r for r in caplog.records if r.levelname == "WARNING" and "internal-models" in r.getMessage()] == []
def test_as_proxy_exception_keeps_jwt_scope_denial_message_shape():
detail = {"error": "The model `gpt-5.6` is unavailable for this API key or does not exist."}
denial = ModelAccessDeniedHTTPException(
internal_message="model=gpt-5.6 not allowed. Allowed_models=['internal-models']",
status_code=status.HTTP_403_FORBIDDEN,
detail=detail,
)
plain = _as_proxy_exception(HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=detail))
converted = _as_proxy_exception(denial)
assert converted.to_dict() == plain.to_dict()
assert converted.internal_message == denial.internal_message
@pytest.mark.asyncio
@pytest.mark.parametrize("unset_value", [None, ""])
async def test_handle_authentication_error_no_extra_denial_log_when_message_not_configured(