fix(exchange_server): page through Active Directory users #5081
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 418 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.361
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5081"
general
weight: 0.35
ShivamSharma43
Relates to: no issue
This is a bug I found while reading the Exchange Server connector (it is also used by the Outlook connector for Outlook Server).
ExchangeUsers._ldap_searchlooks up the mailboxes to sync with one LDAP search:The search does not send the paged results control. Active Directory answers a search like this with at most
MaxPageSizeentries (1000 by default) and the result codesizeLimitExceeded. ldap3 does not raise on that result code by default, andhas_valueisTruebecause the response is not empty, so the connector takes the first 1000 entries as the full list:get_access_controluses the same lookup, so those users get no access control documents either.The fix sends the search with
paged_size=1000and follows the paged results cookie (1.2.840.113556.1.4.319) until the server returns an empty cookie, collecting all pages. The first page still raisesUsersFetchFailedwhen it has no entries, as before. A later page that comes back empty with a non-success result also raisesUsersFetchFailed, so a failure midway does not return a partial list. Each page is a separate request on the same connection, and the connection is still unbound once at the end.Checklists
Pre-Review Checklist
config.yml.example)v7.13.2,v7.14.0,v8.0.0)Tests
In
tests/sources/test_exchange_server.py:test_ldap_search_follows_paged_results_cookie: the first page returns one user and a cookie, the second page returns another user and an empty cookie; checks that both users are returned, that the second search sends the cookie from the first, and that the connection is unbound once.test_ldap_search_raises_when_a_later_page_fails: the second page fails; checks thatUsersFetchFailedis raised.Both tests fail on
mainand pass with the fix. The existing tests, which return a single page without paging controls, pass unchanged.test_exchange_server.pyandtest_outlook.pypass, apart fromtest_outlook.py::test_get_content[attachment0-expected_content0], which also fails onmainon my Windows machine (it calls the systembase64command).ruff check,ruff format --checkand pyright on the changed files are clean, apart from the repo-wide CPY001 notice.🤖 Generated with Claude Code