From 8871a5670be867c24ced2d252c40e42215975274 Mon Sep 17 00:00:00 2001 From: Haji Akhundov Date: Wed, 3 Dec 2025 14:50:03 +0100 Subject: [PATCH] Simplify SCIM tests to focus on core issue --- .../scim/test_scim_transformations.py | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-) 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.py index 3217a1c4480..be9c79911d0 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 @@ -232,13 +232,11 @@ class TestScimTransformations: @pytest.mark.asyncio async def test_transform_user_with_uuid_as_email(self, mock_prisma_client): """ - Test that users with UUID in user_email field (from old bug) - don't cause validation errors when transforming to SCIM format. + Test that users with UUID in user_email don't cause validation errors. This tests the defensive fix that validates email contains '@' before creating SCIMUserEmail. """ mock_client, mock_find_unique = mock_prisma_client - - # Create a user with UUID in user_email (simulating the bug scenario) + user_with_uuid_email = LiteLLM_UserTable( user_id="21df4e37-2f38-4f2e-a21b-c33cb939ff5b", user_email="21df4e37-2f38-4f2e-a21b-c33cb939ff5b", # UUID as email (bug scenario) @@ -248,56 +246,45 @@ class TestScimTransformations: updated_at=None, metadata={}, ) - - mock_find_unique.return_value = None # No teams to look up - + + mock_find_unique.return_value = None + with patch("litellm.proxy.proxy_server.prisma_client", mock_client): - # This should not raise a validation error scim_user = await ScimTransformations.transform_litellm_user_to_scim_user( user_with_uuid_email ) - - # Verify the user was transformed successfully + assert scim_user.id == user_with_uuid_email.user_id - # Email should not be in emails array since it's a UUID (no '@' sign) assert scim_user.emails is None or len(scim_user.emails) == 0 - # userName should fall back to default since email is invalid - assert scim_user.userName == ScimTransformations.DEFAULT_SCIM_DISPLAY_NAME @pytest.mark.asyncio async def test_transform_user_with_none_email(self, mock_prisma_client): """ - Test that users created via group membership (with user_email=None) - are transformed correctly without errors. + Test that users with user_email=None are transformed correctly. This tests the root cause fix. """ mock_client, mock_find_unique = mock_prisma_client - - # Create a user with None email (correct behavior after fix) + user_with_none_email = LiteLLM_UserTable( user_id="user-from-group", - user_email=None, # None instead of UUID (after fix) + user_email=None, user_alias=None, teams=[], created_at=None, updated_at=None, - metadata={"created_via": "scim_group_membership"}, + metadata={}, ) - - mock_find_unique.return_value = None # No teams to look up - + + mock_find_unique.return_value = None + with patch("litellm.proxy.proxy_server.prisma_client", mock_client): - # This should not raise any errors scim_user = await ScimTransformations.transform_litellm_user_to_scim_user( user_with_none_email ) - - # Verify the user was transformed successfully + assert scim_user.id == user_with_none_email.user_id - # Email should not be in emails array assert scim_user.emails is None or len(scim_user.emails) == 0 - # userName should use default since no email - assert scim_user.userName == ScimTransformations.DEFAULT_SCIM_DISPLAY_NAME + class TestSCIMPatchOperations: