The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(scim): return user_id as Group members[].value on transformed group responses (#38161)
devin-ai-integration[bot]6d0cc1423ecb
diff --git a/litellm/proxy/management_endpoints/scim/scim_transformations.py b/litellm/proxy/management_endpoints/scim/scim_transformations.pyindex 2d95d0bea29..496be05b4b0 100644--- a/litellm/proxy/management_endpoints/scim/scim_transformations.py+++ b/litellm/proxy/management_endpoints/scim/scim_transformations.py@@ -198,15 +198,8 @@ class ScimTransformations:@staticmethoddef _get_scim_member_value(member: Member) -> str:- """- Get the SCIM member value. Use user_email if available, otherwise use user_id.- SCIM member value should be the unique identifier for the user.- """- if hasattr(member, "user_email") and member.user_email:- return member.user_email- elif hasattr(member, "user_id"):- return member.user_id or ScimTransformations.DEFAULT_SCIM_MEMBER_VALUE- return ScimTransformations.DEFAULT_SCIM_MEMBER_VALUE+ """The member's SCIM resource id, which LiteLLM serves as user_id (RFC 7643 §8.7.1)."""+ return member.user_id or ScimTransformations.DEFAULT_SCIM_MEMBER_VALUE@staticmethoddef _get_scim_member_display(member: Member) -> str:diff --git a/tests/test_litellm/proxy/management_endpoints/scim/test_scim_transformations.py b/tests/test_litellm/proxy/management_endpoints/scim/test_scim_transformations.pyindex 9853ce7e1cf..135175dd29d 100644--- a/tests/test_litellm/proxy/management_endpoints/scim/test_scim_transformations.py+++ b/tests/test_litellm/proxy/management_endpoints/scim/test_scim_transformations.py@@ -2,7 +2,6 @@ from unittest.mock import AsyncMock, MagicMock, patchimport pytest-from litellm.proxy._types import LiteLLM_TeamTable, LiteLLM_UserTable, Memberfrom litellm.proxy.management_endpoints.scim.scim_transformations import (ScimTransformations,@@ -95,25 +94,17 @@ def mock_prisma_client():class TestScimTransformations:@pytest.mark.asyncio- async def test_transform_litellm_user_to_scim_user(- self, mock_user, mock_prisma_client- ):+ async def test_transform_litellm_user_to_scim_user(self, mock_user, mock_prisma_client):mock_client, mock_find_unique = mock_prisma_client# Mock the team lookup- team1 = LiteLLM_TeamTable(- team_id="team-1", team_alias="Team One", members_with_roles=[]- )- team2 = LiteLLM_TeamTable(- team_id="team-2", team_alias="Team Two", members_with_roles=[]- )+ team1 = LiteLLM_TeamTable(team_id="team-1", team_alias="Team One", members_with_roles=[])+ team2 = LiteLLM_TeamTable(team_id="team-2", team_alias="Team Two", members_with_roles=[])mock_find_unique.side_effect = [team1, team2]with patch("litellm.proxy.proxy_server.prisma_client", mock_client):- scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(- mock_user- )+ scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(mock_user)assert scim_user.id == mock_user.user_idassert scim_user.userName == mock_user.user_email@@ -129,21 +120,15 @@ class TestScimTransformations:assert scim_user.groups[1].display == "Team Two"@pytest.mark.asyncio- async def test_transform_user_with_scim_metadata(- self, mock_user_with_scim_metadata, mock_prisma_client- ):+ async def test_transform_user_with_scim_metadata(self, mock_user_with_scim_metadata, mock_prisma_client):mock_client, mock_find_unique = mock_prisma_client# Mock the team lookup- team1 = LiteLLM_TeamTable(- team_id="team-1", team_alias="Team One", members_with_roles=[]- )+ team1 = LiteLLM_TeamTable(team_id="team-1", team_alias="Team One", members_with_roles=[])mock_find_unique.return_value = team1with patch("litellm.proxy.proxy_server.prisma_client", mock_client):- scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(- mock_user_with_scim_metadata- )+ scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(mock_user_with_scim_metadata)assert scim_user.name.givenName == "Test"assert scim_user.name.familyName == "User"@@ -160,15 +145,11 @@ class TestScimTransformations:teams=[],created_at=None,updated_at=None,- metadata={- "scim_enterprise": {"costCenter": "CC-42", "department": "Platform"}- },+ metadata={"scim_enterprise": {"costCenter": "CC-42", "department": "Platform"}},)with patch("litellm.proxy.proxy_server.prisma_client", mock_client):- scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(- user- )+ scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(user)assert scim_user.enterprise_user is not Noneassert scim_user.enterprise_user.costCenter == "CC-42"@@ -176,9 +157,7 @@ class TestScimTransformations:assert SCIM_ENTERPRISE_USER_SCHEMA in scim_user.schemas@pytest.mark.asyncio- async def test_transform_user_with_entitlements_and_roles_metadata(- self, mock_prisma_client- ):+ async def test_transform_user_with_entitlements_and_roles_metadata(self, mock_prisma_client):mock_client, mock_find_unique = mock_prisma_clientmock_find_unique.return_value = None@@ -190,17 +169,13 @@ class TestScimTransformations:created_at=None,updated_at=None,metadata={- "scim_entitlements": [- {"value": "jira-software", "display": "Jira Software"}- ],+ "scim_entitlements": [{"value": "jira-software", "display": "Jira Software"}],"scim_roles": [{"value": "engineering-admin", "primary": True}],},)with patch("litellm.proxy.proxy_server.prisma_client", mock_client):- scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(- user- )+ scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(user)assert scim_user.entitlements is not Noneassert scim_user.entitlements[0].value == "jira-software"@@ -210,9 +185,7 @@ class TestScimTransformations:assert scim_user.roles[0].primary is True@pytest.mark.asyncio- async def test_transform_user_with_malformed_directory_metadata_fails_soft(- self, mock_prisma_client- ):+ async def test_transform_user_with_malformed_directory_metadata_fails_soft(self, mock_prisma_client):"""Metadata is writable outside the SCIM surface; a corrupted value on oneuser must omit the attribute, not fail the whole directory response"""mock_client, mock_find_unique = mock_prisma_client@@ -233,9 +206,7 @@ class TestScimTransformations:)with patch("litellm.proxy.proxy_server.prisma_client", mock_client):- scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(- user- )+ scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(user)assert scim_user.id == "user-corrupt"assert scim_user.entitlements is None@@ -244,22 +215,14 @@ class TestScimTransformations:assert SCIM_ENTERPRISE_USER_SCHEMA not in scim_user.schemas@pytest.mark.asyncio- async def test_transform_user_without_enterprise_metadata_omits_schema(- self, mock_user, mock_prisma_client- ):+ async def test_transform_user_without_enterprise_metadata_omits_schema(self, mock_user, mock_prisma_client):mock_client, mock_find_unique = mock_prisma_client- team1 = LiteLLM_TeamTable(- team_id="team-1", team_alias="Team One", members_with_roles=[]- )- team2 = LiteLLM_TeamTable(- team_id="team-2", team_alias="Team Two", members_with_roles=[]- )+ team1 = LiteLLM_TeamTable(team_id="team-1", team_alias="Team One", members_with_roles=[])+ team2 = LiteLLM_TeamTable(team_id="team-2", team_alias="Team Two", members_with_roles=[])mock_find_unique.side_effect = [team1, team2]with patch("litellm.proxy.proxy_server.prisma_client", mock_client):- scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(- mock_user- )+ scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(mock_user)assert scim_user.enterprise_user is Noneassert SCIM_ENTERPRISE_USER_SCHEMA not in scim_user.schemas@@ -309,36 +272,28 @@ class TestScimTransformations:assert dumped_attrs["roles"][0]["value"] == "engineering-admin"@pytest.mark.asyncio- async def test_transform_litellm_team_to_scim_group(- self, mock_team, mock_prisma_client- ):+ async def test_transform_litellm_team_to_scim_group(self, mock_team, mock_prisma_client):mock_client, _ = mock_prisma_clientwith patch("litellm.proxy.proxy_server.prisma_client", mock_client):- scim_group = await ScimTransformations.transform_litellm_team_to_scim_group(- mock_team- )+ scim_group = await ScimTransformations.transform_litellm_team_to_scim_group(mock_team)assert scim_group.id == mock_team.team_idassert scim_group.displayName == mock_team.team_aliasassert len(scim_group.members) == 2- assert scim_group.members[0].value == "[email protected]"+ assert scim_group.members[0].value == "user-123"assert scim_group.members[0].display == "[email protected]"- assert scim_group.members[1].value == "[email protected]"+ assert scim_group.members[1].value == "user-456"assert scim_group.members[1].display == "[email protected]"@pytest.mark.asyncio- async def test_transform_team_marks_members_as_users(- self, mock_team, mock_prisma_client- ):+ async def test_transform_team_marks_members_as_users(self, mock_team, mock_prisma_client):"""A LiteLLM team only holds users, and stating the member type keeps theresponse from emitting a null ``type`` now that SCIMMember carries one."""mock_client, _ = mock_prisma_clientwith patch("litellm.proxy.proxy_server.prisma_client", mock_client):- scim_group = await ScimTransformations.transform_litellm_team_to_scim_group(- mock_team- )+ scim_group = await ScimTransformations.transform_litellm_team_to_scim_group(mock_team)assert [member.type for member in scim_group.members] == ["User", "User"]@@ -351,9 +306,7 @@ class TestScimTransformations:result = ScimTransformations._get_scim_user_name(mock_user_minimal)assert result == ScimTransformations.DEFAULT_SCIM_DISPLAY_NAME- def test_get_scim_family_name(- self, mock_user, mock_user_with_scim_metadata, mock_user_minimal- ):+ def test_get_scim_family_name(self, mock_user, mock_user_with_scim_metadata, mock_user_minimal):# User with aliasresult = ScimTransformations._get_scim_family_name(mock_user)assert result == mock_user.user_alias@@ -366,9 +319,7 @@ class TestScimTransformations:result = ScimTransformations._get_scim_family_name(mock_user_minimal)assert result == ScimTransformations.DEFAULT_SCIM_FAMILY_NAME- def test_get_scim_given_name(- self, mock_user, mock_user_with_scim_metadata, mock_user_minimal- ):+ def test_get_scim_given_name(self, mock_user, mock_user_with_scim_metadata, mock_user_minimal):# User with aliasresult = ScimTransformations._get_scim_given_name(mock_user)assert result == mock_user.user_alias@@ -382,14 +333,10 @@ class TestScimTransformations:assert result == ScimTransformations.DEFAULT_SCIM_NAMEdef test_get_scim_member_value(self):- # Member with email- member_with_email = Member(- user_id="user-123", user_email="[email protected]", role="admin"- )+ member_with_email = Member(user_id="user-123", user_email="[email protected]", role="admin")result = ScimTransformations._get_scim_member_value(member_with_email)- assert result == member_with_email.user_email+ assert result == member_with_email.user_id- # Member without email should fall back to user_idmember_without_email = Member(user_id="user-456", user_email=None, role="user")result = ScimTransformations._get_scim_member_value(member_without_email)assert result == member_without_email.user_id@@ -415,9 +362,7 @@ class TestScimTransformations:mock_find_unique.return_value = Nonewith patch("litellm.proxy.proxy_server.prisma_client", mock_client):- scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(- user_with_uuid_email- )+ scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(user_with_uuid_email)assert scim_user.id == user_with_uuid_email.user_idassert scim_user.emails is None or len(scim_user.emails) == 0@@ -443,9 +388,7 @@ class TestScimTransformations:mock_find_unique.return_value = Nonewith patch("litellm.proxy.proxy_server.prisma_client", mock_client):- scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(- user_with_none_email- )+ scim_user = await ScimTransformations.transform_litellm_user_to_scim_user(user_with_none_email)assert scim_user.id == user_with_none_email.user_idassert scim_user.emails is None or len(scim_user.emails) == 0