litellm/tests/test_litellm/proxy/management_endpoints
milan-berri 97d0a99c74
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:53:31 +00:00
..
policy_endpoints style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
scim Fix SCIM user lookup filters (#27308) 2026-05-06 11:58:47 -07:00
search_endpoints style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
usage_endpoints fix(proxy): reject user_id=None on non-admin analytics endpoints (cross-tenant disclosure) 2026-04-30 23:54:01 +02:00
test_access_group_endpoints.py update test cases to match new behaviour. The earlier test cases assumed the cache stores a pydantic object 2026-04-28 21:08:46 +00: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 fix(proxy): guard agent activity owned-fallback against null user_id 2026-05-01 22:04:54 +00: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 fix(audit): close NameError + mypy + asyncio-import nits 2026-05-01 01:47:11 +00: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 perf(proxy): run daily activity aggregation off the event loop (#27264) 2026-05-05 20:19:28 -07:00
test_common_utils.py fix(proxy): reject user_id=None on non-admin analytics endpoints (cross-tenant disclosure) 2026-04-30 23:54:01 +02: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 fix(audit): label vault POST as updated when DB row exists 2026-05-01 02:44:47 +00: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 fix(proxy): re-validate user_id after /user/info re-parses query (#27009) 2026-05-01 17:38:14 -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:53:31 +00:00
test_mcp_management_endpoints.py feat(mcp): add delegate_auth_to_upstream flag for PKCE passthrough (#27834) 2026-05-13 12:06:13 -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 fix(team): also gate organization-scoped endpoints behind _verify_org_access 2026-04-29 22:51:59 +00: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 fix(tests): use canonical litellm_enterprise import path (#27699) 2026-05-12 12:32:57 -07:00
test_router_settings_endpoints.py feat: routing groups ui 2026-05-04 18:09:14 -07:00
test_tag_management_endpoints.py Fix internal tag usage scoping (#27315) 2026-05-11 10:44:50 -07:00
test_team_callback_endpoints.py Merge remote-tracking branch 'origin/litellm_internal_staging' into codex/resolve-team-callback-conflicts 2026-05-01 01:35:07 -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 feat(ui): search teams by team ID alongside name (#27684) 2026-05-12 11:14:29 -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 fix(tests): use canonical litellm_enterprise import path (#27699) 2026-05-12 12:32:57 -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