litellm/tests/unit/proxy/management_helpers
mrinal-berri 85c3478b33
feat(proxy): sync LDAP groups to team memberships (#50130)
* feat(proxy): synchronize LDAP groups to teams

* chore(ui): regenerate LDAP sync API types

* fix(proxy): stop LDAP reads when sync jobs time out

* refactor(proxy): validate LDAP startup boundaries

* refactor(proxy): use a read-only team defaults type

* refactor(proxy): preserve team defaults validation behavior

* fix(proxy): skip only the LDAP group with a deleted member entry

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): harden LDAP snapshots, TLS, and team defaults

* fix(proxy): hide LDAP credentials in validation errors

* fix(ldap): accept only user members, guard emptied teams, stop between teams on timeout

- Member entries must carry a person object class; nested groups of any class skip their group
- A group resolving to no LiteLLM users no longer empties a populated team unless allow_empty_groups is set
- The run timeout cancels only the directory read; writes stop between teams instead of mid-transaction
- Revert the post-commit cache-eviction shield to the plain await used by other key-deletion paths

* fix(ldap): require interval_minutes >= 5 so the job lock outlasts a run

The lease is interval - 1s and a run can exceed its time budget by one roster transaction (60s timeout), so sub-2-minute intervals let a second replica start while the first is still writing.

* perf(ldap): resolve each member once per directory snapshot

Users in many groups were looked up once per group; the load test made 2000 lookups for 494 distinct users at 100 groups. Results, including missing-entry errors, are reused within a snapshot only.

* refactor(ldap): validate sync settings once and type the job initializer

- ldap_sync_settings() validates general_settings.ldap_sync once; both startup sites use it instead of peeking at the raw dict
- initialize_ldap_sync takes the validated settings, a typed scheduler Protocol and a non-optional PrismaClient
- Drop the runtime scheduler isinstance check and the unreachable database check

* fix(ldap): release the job lock when a run finishes; cover configurable match fields

- Release cronjob_lock:ldap_team_sync in finally, matching key rotation and budget reset, so a restart right after a run (dry_run -> apply) syncs immediately
- Tests: lock held during a run blocks other workers, released after success and failure
- Tests: entryUUID/description group attributes, uid user_match_attribute, uniqueMember/roleOccupant, and an end-to-end uid -> sso_user_id sync

* fix(ldap): let the job lock expire so one replica syncs per interval

Matches the spend capture rate check: the lease (interval - 1s) is not released, so replicas firing later in the interval skip. A restart within the interval applies config changes at the next interval; documented.

* fix(ldap): no team write after the run budget; skip validating disabled blocks

- Check the run budget after user and team lookups, before any team write, so a slow read never starts a write past the budget (spend log cleanup precedent)
- Read only enabled before validating ldap_sync, so a disabled block cannot fail startup
- Drop a comment that restated the code

* fix(ldap): freeze the enabled-flag settings model

* refactor(ldap): build the member lookup map once instead of mutating it

Fixes the type discipline gate (LIT001 mutable dict parameter, LIT011 parameter mutation). Lookups and their order are unchanged.

* test(ldap): drive time-budget tests with a controlled loop clock and mark test locals Final

Replace the real asyncio.sleep calls in the two time-budget tests with a
loop clock the stubs skip forward, so worker speed cannot change the
outcome (tests/unit/AGENTS.md). Annotate single-assignment locals in the
new LDAP tests, and the PR-added ones in test_team_roster_sync.py, with
Final (LIT010).

* docs(ldap): drop root docs/ldap_sync.md; LDAP sync docs live in litellm-docs

main removed the repo-root docs/ directory (#50992), and re-adding it
pushes the root past the root-entry-limit check.

* test(proxy): fix LDAP sync lint and CI fixtures

* test(proxy): exercise LDAP sync at service boundaries

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-24 11:13:49 -08:00
..
__init__.py ci: move tests/proxy_unit_tests to tests/unit/proxy and run the proxy-db shards from litellm-tests (#42903) 2026-09-24 22:59:11 +00:00
team_metadata_validator_impls.py test(proxy): move management_endpoints, management_helpers and guardrails tests into tests/unit/proxy (#44003) 2026-10-01 10:52:03 -07:00
test_access_group_key_sync.py fix(proxy): preserve concurrent access group assignments (#53840) 2026-11-23 16:27:41 -08:00
test_access_group_model_sync.py fix(proxy): preserve concurrent access group assignments (#53840) 2026-11-23 16:27:41 -08:00
test_access_group_team_sync.py test(proxy): move management_endpoints, management_helpers and guardrails tests into tests/unit/proxy (#44003) 2026-10-01 10:52:03 -07:00
test_app_groups.py feat(proxy): add app groups with shared budgets and usage (#53232) 2026-11-21 12:50:58 -08:00
test_apps.py feat(proxy): add app groups with shared budgets and usage (#53232) 2026-11-21 12:50:58 -08:00
test_audit_log_callbacks.py refactor(s3-log): move the rust-backed s3 logger from s3_v3 to s3_v2 (#51893) 2026-11-14 22:24:23 -08:00
test_audit_logs_proxy.py feat(db): insert audit logs through the rust repository (#52779) 2026-11-20 14:53:02 +09:00
test_auto_router_availability.py refactor(router): fence the router surface and document the router-core boundary (#48839) 2026-10-29 00:01:52 +00:00
test_auto_router_permissions.py fix(databricks): call the ai_decide AI Function route for decisions and the auto-router (#45722) 2026-10-10 23:58:16 -07:00
test_bulk_user_creation.py feat(caching): configure semantic cache params per key, user and team (#53905) 2026-11-23 13:55:45 -08:00
test_bulk_user_deletion.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_customer_budget_usage.py fix(budgets): match window starts to stored millisecond precision (#51921) 2026-11-16 04:02:44 +08:00
test_customer_hierarchy.py fix(proxy): preserve budget window edits during resets (#53064) 2026-11-20 10:50:27 -08:00
test_management_helpers_utils.py test(proxy): expect the rollover guard in the budget update test (#53575) 2026-11-22 18:16:45 +00:00
test_object_permission_utils.py feat(proxy): app-scoped read access to Customer Management through object permissions (#52781) 2026-11-19 10:43:41 -08:00
test_resource_display_names.py feat(access-groups): name group vector stores and list them on team info (#51484) 2026-11-13 07:53:04 -08:00
test_team_list_sorting.py feat(ui): sort every teams table data column (#48109) 2026-10-23 16:21:36 -07:00
test_team_member_permission_checks.py fix(proxy): align ownership and scope handling (#50600) 2026-11-08 07:03:36 +00:00
test_team_metadata_validation.py feat(lens): add key and team tracing controls (#53191) 2026-11-23 17:59:37 +00:00
test_team_roster_sync.py feat(proxy): sync LDAP groups to team memberships (#50130) 2026-11-24 11:13:49 -08:00
test_user_list_sorting.py feat(ui): sort every users table data column (#48105) 2026-10-23 16:12:51 -07:00