litellm/tests/unit/proxy/management_endpoints
jesus-berri aa58384947
feat(usage-export): include key and user metadata objects in daily activity export rows (#49360)
* feat(usage-export): include key and user metadata objects in daily activity export rows

* fix(usage-export): only populate key and user metadata for admin view and strip credential and SCIM slots

* feat(usage-export): redact credential-named values inside exported key and user metadata

* test(usage-export): freeze e2e models, compare raw non-admin metadata, mark query locals Final

* test(usage-export): mark redaction test locals Final

* fix(usage-export): drop callback and SCIM slots from both metadata objects at any depth and mask camelCase credential names

* fix(masker): keep odd-cased plain names like sEt-CoOkIe sensitive alongside the camelCase split

* test(masker): mark new test locals Final

* fix(masker): make the camelCase split opt-in and enable it only for the usage export masker

* fix(usage-export): mask acronym-cased and unseparated credential names in exported metadata

* test(e2e): assert acronym-cased and upper-case credential names are masked in the usage export

* test(integration): cover usage export metadata across routes, callers and a worker kill

* test(integration): retry burst calls dropped by the worker kill and fail on any chat error

* fix(usage-export): redact credential-shaped metadata values whatever their key is called

The export masked key and user metadata by key name only, so secrets under
names the masker does not know (tokens, apiKeys, passphrase, database_url,
sentry_dsn, slackWebhookUrl) or under ordinary names (an sk- key in a note,
a postgres URL with a password, a Bearer header, a JWT, a Slack or Discord
webhook URL), including inside lists, were exported verbatim to admin-view
callers. redact_credentials_in_payload gains an opt-in is_credential hook,
and the export passes one that matches those key names and credential value
shapes.

* fix(usage-export): mask password-only credential URLs and bound the value scan

The URL branch required a username, so redis://:pw@host reached exports. The sk- lookahead and the URL scheme prefix scanned the rest of the string at every match attempt, which made a long metadata string quadratic (54s for 150k chars locally, 0.2s now).

* fix(usage-export): make every credential pattern linear, including JWTs

Builds on the bounded sk- and URL scan. The JWT branch still rescanned to the
end of the string at every eyJ, so eyJ- repeated 30k times took seconds. JWTs
now match on their eyJ header run, the sk- digit check moved out of the
lookahead into one pass over the sk- runs, and URL userinfo is length bounded.
The adversarial-input test covers sk-, JWT, scheme and userinfo runs.

* fix(usage-export): redact credential URLs whatever the username or password length

The 256-character userinfo bounds let a longer generated password through
unredacted. The username and password classes already stop at the next
separator, so the scan stays linear without them.

* fix(usage-export): redact credential URLs with any scheme casing and embedded Authorization headers

Postgresql:// and HTTPS:// userinfo passwords passed through because the
scheme class was lowercase only, and an Authorization: Bearer line inside a
longer string missed the anchored header pattern.

* fix(usage-export): redact quoted Authorization keys in serialized metadata strings

* fix(usage-export): redact padded Bearer values and prefixed or escaped Authorization keys

* fix(usage-export): redact prefixed key shapes and webhook URL variants

Key prefixes now only need a non-alphanumeric character before them, so
id_AKIA..., stripe_sk_live_... and my_ghp_... are redacted while risk-2024 and
disk-1234 stay intact. Slack and Discord webhooks match any scheme casing,
http, Discord subdomains and versioned /api/vN/webhooks/ paths.

* feat(usage-export): make key and user metadata opt-in with include_metadata

The export now fills key_metadata and user_metadata only when an admin-view
caller passes include_metadata=true. Without it, and for non-admins, both
columns stay '{}' so the CSV shape is unchanged. The Usage export dialog gets
an unchecked "Include key and user metadata" checkbox that sends the flag.

* test(usage-export): opt the integration and e2e export calls into metadata, regenerate API types

The integration and e2e export helpers now pass include_metadata=true, and the
admin-viewer integration test also checks that an admin export without the flag
returns empty metadata objects.

* chore(usage-export): regenerate the lazy OpenAPI snapshot for include_metadata

* fix(usage-export): keep the default export shape and gate the metadata option to admins

The key_metadata and user_metadata columns and fields now appear only when an
admin-view caller passes include_metadata=true. Every other export, CSV and
JSON, keeps the merge-base shape. The Usage export dialog shows the metadata
checkbox only to proxy admins and viewers, with a note that stored metadata may
carry credentials the redaction cannot catch.

* test(usage-export): expect no metadata fields on the owner path of the export burst test

* fix(usage-export): require the metadata fields on ExportRow instead of an unpicklable default

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-20 03:58:01 +00:00
..
management_v1 feat(proxy): link app member budgets to shared templates (#52989) 2026-11-19 17:05:05 -08:00
policy_endpoints
scim feat(auth): read virtual keys, jwt key mappings and model access groups through rust repositories (#52173) 2026-11-18 03:53:37 +00:00
search_endpoints feat(search): add Microsoft Web IQ provider (#50883) 2026-11-10 22:43:36 +00:00
sso ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
usage_endpoints
__init__.py
jwt_key_mapping_doubles.py feat(auth): read virtual keys, jwt key mappings and model access groups through rust repositories (#52173) 2026-11-18 03:53:37 +00:00
test_access_group_endpoints.py feat(access-groups): name group vector stores and list them on team info (#51484) 2026-11-13 07:53:04 -08:00
test_access_group_management.py fix(budgets): invalidate customer hierarchy caches through stored team IDs (#51654) 2026-11-13 18:43:38 +00:00
test_activity_tenant_scoping.py
test_auto_router_endpoints.py feat(auth): read teams, team memberships and organizations through rust repositories (#52176) 2026-11-18 22:32:05 +00:00
test_budget_endpoints.py feat(customer-portal): unify budget editors and usage tables (#52682) 2026-11-19 11:49:21 -08:00
test_cache_settings_endpoints.py
test_callback_management_endpoints.py
test_common_daily_activity.py feat(customer-portal): show token usage and cache costs (#52601) 2026-11-18 18:49:08 -08:00
test_common_utils.py
test_compliance_endpoints.py
test_config_override_endpoints.py
test_coordination_redis_endpoints.py
test_cost_estimate_endpoint.py refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
test_cost_tracking_settings.py fix(proxy): keep a cost settings update from being undone by an in-flight config reload (#51273) 2026-11-12 00:54:10 +00:00
test_credential_migration.py
test_customer_budget.py fix(proxy): /customer/new budgets reset on the same schedule as other budgets (#51689) 2026-11-13 19:22:14 +00:00
test_customer_endpoints.py fix(proxy-extras): make the app association budget migration re-runnable (#52909) 2026-11-19 12:35:48 -08:00
test_daily_activity_routes.py feat(usage-export): include key and user metadata objects in daily activity export rows (#49360) 2026-11-20 03:58:01 +00:00
test_delete_callbacks_endpoint.py
test_delete_verification_tokens_failed.py feat(auth): read virtual keys, jwt key mappings and model access groups through rust repositories (#52173) 2026-11-18 03:53:37 +00:00
test_encryption_endpoints.py
test_entraid_app_roles.py
test_gateway_request_endpoints.py refactor(proxy): inject gateway activity through a typed repository (#49116) 2026-10-30 16:25:11 -07:00
test_id_jag_assertion_capture.py
test_internal_user_endpoints.py feat(proxy): report current budget-window spend on /user/info, /v2/user/info and /team/info (#52673) 2026-11-18 15:43:22 -08:00
test_jwt_key_mapping.py fix(proxy): evict issuer-scoped JWT mapping misses on global mapping writes (#52350) 2026-11-17 14:38:53 -08:00
test_key_budget_change.py feat(auth): read teams, team memberships and organizations through rust repositories (#52176) 2026-11-18 22:32:05 +00:00
test_key_generate_prisma.py test(auth): use the production cache in auth fixtures (#52754) 2026-11-19 03:43:24 +00:00
test_key_management_endpoints.py fix(key-management): let a key read its own info by its plaintext key (#52925) 2026-11-19 12:42:33 -08:00
test_management_route_coverage.py
test_mcp_connector_import.py
test_mcp_management_endpoints.py feat(auth): read projects, tags, access groups and object permissions through rust repositories (#52178) 2026-11-18 22:32:06 +00:00
test_mcp_servers.py
test_model_deprecation_alerts.py feat(proxy): add model deprecation alerts with daily requests by key (#50022) 2026-11-05 04:03:42 +00:00
test_model_insights_endpoints.py feat(alerts): detect daily changes in recorded usage (#50666) 2026-11-11 18:23:02 -08:00
test_model_management_endpoints.py fix(proxy): preserve explicit model prices when metadata echoes null (#48746) 2026-11-16 08:33:45 -08:00
test_org_admin_team_access.py
test_organization_endpoints.py feat(auth): read virtual keys, jwt key mappings and model access groups through rust repositories (#52173) 2026-11-18 03:53:37 +00:00
test_password_endpoints.py feat(proxy): hash UI passwords with PBKDF2 in FIPS mode (#49874) 2026-11-06 01:31:59 -08:00
test_policy_endpoints.py fix(guardrails): log requests that a guardrail blocks on /apply_guardrail (#51014) 2026-11-16 15:18:08 -08:00
test_project_org_authz.py
test_prompt_cache_prediction.py feat(callbacks-parallel-request-limiter): port parallel request limiter v3 to a rust callback (#51537) 2026-11-16 22:56:38 -08:00
test_prompt_caching_requests.py fix(proxy): cancel the Admin UI's raw spend-log reads in Postgres after 30s (#49965) 2026-11-03 16:07:00 -08:00
test_ptu_consumption.py
test_ptu_model_settings.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_request_error_endpoints.py
test_roi_calculator_endpoints.py
test_router_settings_endpoints.py
test_saml_sso.py
test_session_endpoints.py
test_sso_helper_utils.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_subscription_accounts.py feat(auth): decide key and JWT authentication in a Rust core (#51374) 2026-11-17 14:07:47 +09:00
test_tag_management_endpoints.py feat(control_plane): dataplane registry, credential strategies and client (#49655) 2026-11-16 17:36:23 +00:00
test_team_admin_field_permissions.py feat(proxy): add team budget percentage email alerts (#52859) 2026-11-19 16:21:25 -08:00
test_team_callback_endpoints.py
test_team_default_params.py feat(team): let default_team_params attach access_group_ids to every new team (#49908) 2026-11-05 19:58:51 -08:00
test_team_endpoints.py feat(proxy): add team budget percentage email alerts (#52859) 2026-11-19 16:21:25 -08:00
test_team_model_alias_merge.py
test_tool_management_endpoints.py
test_ui_sso.py feat(db): rust repositories for user, end user and budget auth objects (#52170) 2026-11-18 22:32:05 +00:00
test_user_agent_analytics_endpoints.py refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
test_workflow_management_endpoints.py feat(control_plane): dataplane registry, credential strategies and client (#49655) 2026-11-16 17:36:23 +00:00