test: assert sanitized live access errors

This commit is contained in:
jibanez-staticduo 2026-09-18 13:39:28 +02:00
parent e6ab17cc48
commit 04f0d4b545
No known key found for this signature in database
2 changed files with 8 additions and 5 deletions

View file

@ -280,8 +280,9 @@ async def test_offer_auth_enforces_session_model_policy_before_upstream(
with pytest.raises(ProxyException) as denied:
await proxy_realtime_calls(request, Response())
if policy == "personal_models":
assert "user not allowed to access model" in str(denied.value)
assert "forbidden-voice" in str(denied.value)
internal_message = getattr(denied.value, "internal_message", str(denied.value))
assert "user not allowed to access model" in internal_message
assert "forbidden-voice" in internal_message
custom.assert_awaited_once()
upstream.assert_not_awaited()
if policy == "budget":

View file

@ -17,7 +17,7 @@ from litellm.models.project import LiteLLM_ProjectTable
from litellm.models.team import LiteLLM_TeamTable
from litellm.models.team_membership import LiteLLM_TeamMembership
from litellm.models.user import LiteLLM_UserTable
from litellm.proxy._types import UserAPIKeyAuth
from litellm.proxy._types import ModelAccessDeniedProxyException, UserAPIKeyAuth
from litellm.proxy.realtime_endpoints import live
@ -1132,8 +1132,9 @@ async def test_authorize_enforces_authoritative_personal_user_models(monkeypatch
auth = UserAPIKeyAuth(api_key="owner", models=[], user_id="user-only")
await live._authorize("voice", auth)
with pytest.raises(Exception, match="user can only access"):
with pytest.raises(ModelAccessDeniedProxyException) as rejected:
await live._authorize("backend", auth)
assert "user can only access" in rejected.value.internal_message
assert user_loader.await_count == 2
@ -1153,8 +1154,9 @@ async def test_authorize_enforces_authoritative_organization_models(monkeypatch,
auth = UserAPIKeyAuth(api_key="owner", models=[], org_id="org-only")
await live._authorize("voice", auth)
with pytest.raises(Exception, match="org can only access"):
with pytest.raises(ModelAccessDeniedProxyException) as rejected:
await live._authorize("backend", auth)
assert "org can only access" in rejected.value.internal_message
assert org_loader.await_count == 2