litellm/tests/test_litellm/proxy/management_endpoints
milan-berri 16f59f2977
fix(key_generate): allow team members to create keys on org-scoped teams (#29310)
* fix(key_generate): allow team members to create keys on org-scoped teams

When a virtual key is created for a team, enterprise logic inherits the
team's organization_id onto the key (add_team_organization_id). Since the
VERIA-55 org-IDOR fix, /key/generate then required the caller to be an
explicit LiteLLM_OrganizationMembership member of that org, returning
403 "Caller is not a member of organization_id=<uuid>". Admins normally
only add users to teams (not orgs), so self-serve key creation regressed
for any user on an org-scoped team (regression since v1.84.0-rc.1).

Skip the org-membership check when organization_id was inherited from the
key's team (organization_id == team_table.organization_id). Team-level
authorization already gates this path, so team membership is sufficient.
The membership check still runs when a caller assigns an organization_id
that did not come from the key's team, preserving the IDOR protection.

Adds regression tests covering both the team-inherited (allowed) and
foreign-org (still blocked) cases.

Co-authored-by: Cursor <cursoragent@cursor.com>

* test(key_generate): cover mismatched team org IDOR path on generate

Add test_generate_key_foreign_org_with_mismatched_team_still_enforces_membership
for the case where a team is present but request organization_id differs from
team_table.organization_id. Enterprise inheritance is no-op'd in the test so
the guard is exercised directly; membership validation must still run.

Addresses Greptile review on #29310.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
(cherry picked from commit b11833c737)
2026-06-03 22:52:22 +00:00
..
policy_endpoints style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
scim [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
search_endpoints style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
usage_endpoints [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_access_group_endpoints.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_access_group_management.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_activity_tenant_scoping.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_budget_endpoints.py [Release - 02/10/2026] v1.81.10-nightly 2026-02-10 16:26:30 -08:00
test_cache_settings_endpoints.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_callback_management_endpoints.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_common_daily_activity.py Revert "fix(proxy): restore per-entity breakdown in aggregated daily activity endpoint" 2026-03-21 21:37:29 -07:00
test_common_utils.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_compliance_endpoints.py Add compliance checker endpoints + UI panel (#21432) 2026-02-17 18:22:26 -08:00
test_config_override_endpoints.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_cost_tracking_settings.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_customer_budget.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_customer_endpoints.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_delete_callbacks_endpoint.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_delete_verification_tokens_failed.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_entraid_app_roles.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_internal_user_endpoints.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_key_management_endpoints.py fix(key_generate): allow team members to create keys on org-scoped teams (#29310) 2026-06-03 22:52:22 +00:00
test_mcp_management_endpoints.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_model_management_endpoints.py fix(model_management): refresh in-memory router after POST /model/update (#26427) 2026-04-25 14:10:23 -07:00
test_org_admin_team_access.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_organization_endpoints.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_policy_endpoints.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_project_org_authz.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_router_settings_endpoints.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_tag_management_endpoints.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_team_callback_endpoints.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_team_default_params.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_team_endpoints.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_tool_management_endpoints.py Fix tool management tests using wrong field name call_policy 2026-03-04 11:20:17 -03:00
test_ui_sso.py [Infra] Promote internal staging to main (#27245) 2026-05-05 16:15:03 -07:00
test_workflow_management_endpoints.py feat(proxy): durable agent workflow run tracking via /v1/workflows/runs (#26793) 2026-04-29 17:12:18 -07:00