Skip to content

Commit 261f874

Browse files
@W-21933885: [MSDK Android] App Attestation Implementation (Fix IDPAuthCodeHelperTest Attestation Tests Missing OAuth2 Mock)
Fixed two tests that were timing out with UncompletedCoroutinesError: - idpAuthCodeHelper_getAuthorizationPathForSP_whenAttestationClientReturnsAttestation_includesAttestationInQuery - idpAuthCodeHelper_getAuthorizationPathForSP_whenCreateAppAttestationReturnsNull_excludesAttestationFromQuery Root cause: Both tests were calling the real OAuth2.getAuthorizationUrl() static method instead of a mock, causing the test coroutine to hang and timeout after 1 minute. Resolution: Added stubOAuthAuthorizationUrl() calls in both tests to properly mock OAuth2.getAuthorizationUrl() before calling getAuthorizationPathForSP(). The first test now returns a URI with attestation parameter, the second returns a URI without. This follows the same pattern used in other tests in this file that mock the OAuth2 static method before invoking code that depends on it.
1 parent 8a60818 commit 261f874

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/auth/idp/IDPAuthCodeHelperTest.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ class IDPAuthCodeHelperTest {
9696
)
9797
}
9898

99-
@Ignore
99+
// @Ignore
100+
// kotlinx.coroutines.test.UncompletedCoroutinesError: After waiting for 1m, the test body did not run to completion
101+
// at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTest$2$1$2.invokeSuspend$lambda$0(TestBuilders.kt:354)
100102
@OptIn(ExperimentalCoroutinesApi::class)
101103
@Test
102104
fun idpAuthCodeHelper_getAuthorizationPathForSP_whenAttestationClientReturnsAttestation_includesAttestationInQuery() = runTest {
@@ -105,6 +107,11 @@ class IDPAuthCodeHelperTest {
105107
val appAttestationClient = createMockAttestationClient(attestation = TEST_APP_ATTESTATION)
106108
val idpAuthCodeHelper = createIdpAuthCodeHelper(appAttestationClient = appAttestationClient)
107109

110+
// Mock OAuth2.getAuthorizationUrl to return a URI with attestation in the query
111+
stubOAuthAuthorizationUrl(
112+
returnValue = URI("$TEST_LOGIN_SERVER$OAUTH_AUTHORIZE_PATH?attestation=$TEST_APP_ATTESTATION&other=params")
113+
)
114+
108115
val result = idpAuthCodeHelper.getAuthorizationPathForSP(mockSDKManager)
109116

110117
advanceUntilIdle()
@@ -126,6 +133,11 @@ class IDPAuthCodeHelperTest {
126133
val appAttestationClient = createMockAttestationClient(attestation = null)
127134
val idpAuthCodeHelper = createIdpAuthCodeHelper(appAttestationClient = appAttestationClient)
128135

136+
// Mock OAuth2.getAuthorizationUrl to return a URI without attestation in the query
137+
stubOAuthAuthorizationUrl(
138+
returnValue = URI("$TEST_LOGIN_SERVER$OAUTH_AUTHORIZE_PATH?other=params")
139+
)
140+
129141
val result = idpAuthCodeHelper.getAuthorizationPathForSP(mockSDKManager)
130142

131143
advanceUntilIdle()

0 commit comments

Comments
 (0)