Skip to content

fix(auth): guard migrateRefreshToken dispatch_async against stale sessions (W-23992574) - #4146

Merged
wmathurin merged 1 commit into
forcedotcom:devfrom
wmathurin:fix-testLogin-migrate-session-guard
Aug 26, 2026
Merged

wmathurin merged 1 commit into
forcedotcom:devfrom
wmathurin:fix-testLogin-migrate-session-guard

Conversation

@wmathurin

Copy link
Copy Markdown
Contributor

Summary

  • testDowngradeFromDPoP_* tests queue a dispatch_async(dispatch_get_main_queue(), ...) in migrateRefreshToken: then immediately clean up the auth session; the pending block fires during testLogin's waitForExpectations:timeout:20, triggering NSInternalInconsistencyException: Use SFRestAPI sharedInstance for authenticated requests (seen in Actions run 32898781351)
  • Add a session-alive guard (authSessions[authSession.sceneId]) in both the outer and inner dispatch_async block so stale sessions are silently skipped
  • Fix testLogin's empty failure block to surface errors via XCTFail — previously silent failures masked real timeouts

Test plan

  • Ran SFUserAccountManagerTests locally: 24 tests, 0 failures (including testLogin passing in ~0.9 s with a real network token refresh)
  • Validated against CI failure scenario: testDowngradeFromDPoP_* tests run before testLogin with no crash

…sions (W-23992574)

Pending main-queue blocks from testDowngradeFromDPoP_* tests fired during
testLogin's waitForExpectations, triggering NSInternalInconsistencyException
in SFRestAPI. Add session-alive check in both the outer and inner block of
the dispatch_async in migrateRefreshToken:. Also fix testLogin's empty
failure block to report errors via XCTFail.
@github-actions

Copy link
Copy Markdown
1 Warning
⚠️ Static Analysis found an issue with one or more files you modified. Please fix the issue(s).

Clang Static Analysis Issues

File Type Category Description Line Col
SFUserAccountManager Nullability Memory error Null passed to a callee that requires a non-null 2nd parameter 1748 15
SFUserAccountManager Nullability Memory error Null passed to a callee that requires a non-null 2nd parameter 1763 15
SFUserAccountManager Nullability Memory error nil passed to a callee that requires a non-null 1st parameter 2439 21
SFUserAccountManager Nullability Memory error nil passed to a callee that requires a non-null 2nd parameter 2663 13

Generated by 🚫 Danger

@github-actions

Copy link
Copy Markdown
TestsPassed ✅SkippedFailed
SalesforceSDKCore iOS ^18 Test Results1009 ran1009 ✅
TestResult
No test annotations available

@codecov

codecov Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 69.21%. Comparing base (be15ae7) to head (8e2f179).

Files with missing lines Patch % Lines
...SDKCore/Classes/UserAccount/SFUserAccountManager.m 50.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (50.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #4146      +/-   ##
==========================================
- Coverage   71.62%   69.21%   -2.41%     
==========================================
  Files         254      254              
  Lines       22837    22839       +2     
==========================================
- Hits        16356    15809     -547     
- Misses       6481     7030     +549     
Components Coverage Δ
Analytics 70.78% <ø> (ø)
Common 70.79% <ø> (-0.10%) ⬇️
Core 63.75% <50.00%> (-3.61%) ⬇️
SmartStore 73.45% <ø> (ø)
MobileSync 88.84% <ø> (ø)
Files with missing lines Coverage Δ
...SDKCore/Classes/UserAccount/SFUserAccountManager.m 60.11% <50.00%> (-6.52%) ⬇️

... and 26 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
TestsPassed ✅SkippedFailed
AuthFlowTester UI Test Results all1 ran1 ✅
TestResult
No test annotations available

@sfdctaka sfdctaka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@wmathurin
wmathurin merged commit c9c1520 into forcedotcom:dev Aug 26, 2026
22 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants