Recover apiRootUrl on app password callback cache miss#22771
Conversation
The in-memory ApiRootUrlCache can be empty at the auth callback if the process was killed between discovery and the redirect, causing a spurious "bad_data" failure. Fall back to re-running api discovery when apiRootUrl is missing but siteUrl is present, and normalize the cache's malformed-URL fallback so put/get keys stay consistent. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Generated by 🚫 Danger |
|
|
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #22771 +/- ##
=======================================
Coverage 37.41% 37.42%
=======================================
Files 2321 2321
Lines 123775 123796 +21
Branches 16804 16809 +5
=======================================
+ Hits 46312 46332 +20
+ Misses 73747 73745 -2
- Partials 3716 3719 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Claude finished @adalpari's task in 1m 46s —— View job Code Review
OverviewThe fix addresses a real bug — the in-memory
|
Cover the malformed-URL key consistency fix in ApiRootUrlCache and the fallback discovery recovery path in ApplicationPasswordLoginHelper, including a guard against double discovery on the happy path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>


Description
The in-memory
ApiRootUrlCacheis populated during the initial sitediscovery step and read again when the application-password auth
callback comes back. If the app process is killed between those two
moments (or discovery never ran for that exact URL), the cache is empty
on the callback and
storeApplicationPasswordCredentialsfails with aspurious
BadDataerror, blocking login.This PR makes that path recoverable:
ApplicationPasswordLoginHelper, whenapiRootUrlis missing butsiteUrlis present on the callback, re-runwpLoginClient.apiDiscoveryas a fallback, repopulate the cache, and continue the login flow.
ApiRootUrlCache, normalize the malformed-URL fallback through thesame
stripToDomainhelper used by the happy path soputandgetalways derive the same key for the same input (previously a malformed
write and a later read could end up under different keys).
Testing instructions
This is fixing and edge case, so it's not easily reproduceable.