@@ -32,11 +32,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
3232import com.salesforce.androidsdk.accounts.UserAccount
3333import com.salesforce.androidsdk.app.SalesforceSDKManager
3434import com.salesforce.androidsdk.auth.AppAttestationClient
35- import com.salesforce.androidsdk.auth.OAuth2
3635import io.mockk.coEvery
3736import io.mockk.every
3837import io.mockk.mockk
39- import io.mockk.mockkStatic
4038import io.mockk.unmockkAll
4139import kotlinx.coroutines.ExperimentalCoroutinesApi
4240import kotlinx.coroutines.test.advanceUntilIdle
@@ -60,15 +58,19 @@ class IDPAuthCodeHelperTest {
6058 unmockkAll()
6159 }
6260
63- @Ignore
6461 @OptIn(ExperimentalCoroutinesApi ::class )
6562 @Test
6663 fun idpAuthCodeHelper_getAuthorizationPathForSP_whenNoAttestationClient_returnsPathAndQueryWithoutAttestation () = runTest {
6764
6865 val mockSDKManager = createMockSalesforceSDKManager()
6966 val idpAuthCodeHelper = createIdpAuthCodeHelper(appAttestationClient = null )
7067
71- val result = idpAuthCodeHelper.getAuthorizationPathForSP(mockSDKManager)
68+ val result = idpAuthCodeHelper.getAuthorizationPathForSP(
69+ getAuthorizationUrl = { _, _, _, _, _, _, _, _, _, _, _ ->
70+ URI (" http://www.example.com" )
71+ },
72+ salesforceSdkManager = mockSDKManager
73+ )
7274
7375 advanceUntilIdle()
7476
@@ -97,39 +99,31 @@ class IDPAuthCodeHelperTest {
9799 )
98100 }
99101
100- // TODO: Prototype test. ECJ20260424
101- // @Ignore
102- // kotlinx.coroutines.test.UncompletedCoroutinesError: After waiting for 1m, the test body did not run to completion
103- // at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTest$2$1$2.invokeSuspend$lambda$0(TestBuilders.kt:354)
104- @OptIn(ExperimentalCoroutinesApi ::class )
102+ // TODO: PROTOTYPE TEST FOR GOOGLE FIREBASE TEST LAB. ECJ20260424
105103 @Test
106104 fun idpAuthCodeHelper_getAuthorizationPathForSP_whenAttestationClientReturnsAttestation_includesAttestationInQuery () = runTest {
107105
108- val mockSDKManager = createMockSalesforceSDKManager()
106+ val sdkManager = createMockSalesforceSDKManager()
109107 val appAttestationClient = createMockAttestationClient(attestation = TEST_APP_ATTESTATION )
110108 val idpAuthCodeHelper = createIdpAuthCodeHelper(appAttestationClient = appAttestationClient)
111109
112110 // Mock OAuth2.getAuthorizationUrl to return a URI with attestation in the query
113- stubOAuthAuthorizationUrl(
114- returnValue = URI (" $TEST_LOGIN_SERVER$OAUTH_AUTHORIZE_PATH ?attestation=$TEST_APP_ATTESTATION &other=params" ),
115- )
116-
117111 val result = idpAuthCodeHelper.getAuthorizationPathForSP(
118- salesforceSDKManager = mockSDKManager,
119- limitTest = true ,
112+ getAuthorizationUrl = { _, _, _, _, _, _, _, _, _, _, _ ->
113+ URI (" $TEST_LOGIN_SERVER$OAUTH_AUTHORIZE_PATH ?attestation=$TEST_APP_ATTESTATION &other=params" )
114+ },
115+ salesforceSdkManager = sdkManager
120116 )
121117
122- // advanceUntilIdle() // Limit Test 1.2
123-
124- // val nonNullResult = requireNotNull(result) {
125- // "Result should be non-null for a valid login server."
126- // }
127- // assertTrue(
128- // "Result should contain 'attestation=$TEST_APP_ATTESTATION' but was '$nonNullResult'.",
129- // nonNullResult.contains("attestation=$TEST_APP_ATTESTATION"),
130- // )
131- assertTrue(true )
118+ advanceUntilIdle()
132119
120+ val nonNullResult = requireNotNull(result) {
121+ " Result should be non-null for a valid login server."
122+ }
123+ assertTrue(
124+ " Result should contain 'attestation=$TEST_APP_ATTESTATION ' but was '$nonNullResult '." ,
125+ nonNullResult.contains(" attestation=$TEST_APP_ATTESTATION " ),
126+ )
133127 }
134128
135129 // Your app crashed due to an ANR. Take a look at your logs to dig deeper.
@@ -138,17 +132,18 @@ class IDPAuthCodeHelperTest {
138132 @Test
139133 fun idpAuthCodeHelper_getAuthorizationPathForSP_whenCreateAppAttestationReturnsNull_excludesAttestationFromQuery () = runTest {
140134
141- val mockSDKManager = createMockSalesforceSDKManager()
135+ val sdkManager = createMockSalesforceSDKManager()
142136 val appAttestationClient = createMockAttestationClient(attestation = null )
143137 val idpAuthCodeHelper = createIdpAuthCodeHelper(appAttestationClient = appAttestationClient)
144138
145139 // Mock OAuth2.getAuthorizationUrl to return a URI without attestation in the query
146- stubOAuthAuthorizationUrl(
147- returnValue = URI (" $TEST_LOGIN_SERVER$OAUTH_AUTHORIZE_PATH ?other=params" )
140+ val result = idpAuthCodeHelper.getAuthorizationPathForSP(
141+ getAuthorizationUrl = { _, _, _, _, _, _, _, _, _, _, _ ->
142+ URI (" $TEST_LOGIN_SERVER$OAUTH_AUTHORIZE_PATH ?other=params" )
143+ },
144+ salesforceSdkManager = sdkManager
148145 )
149146
150- val result = idpAuthCodeHelper.getAuthorizationPathForSP(mockSDKManager)
151-
152147 advanceUntilIdle()
153148
154149 val nonNullResult = requireNotNull(result) {
@@ -166,11 +161,15 @@ class IDPAuthCodeHelperTest {
166161 @Test
167162 fun idpAuthCodeHelper_getAuthorizationPathForSP_whenAuthorizationUrlIsNull_returnsNull () = runTest {
168163
169- val mockSDKManager = createMockSalesforceSDKManager()
170- stubOAuthAuthorizationUrl(returnValue = null )
164+ val sdkManager = createMockSalesforceSDKManager()
171165 val idpAuthCodeHelper = createIdpAuthCodeHelper(appAttestationClient = null )
172166
173- val result = idpAuthCodeHelper.getAuthorizationPathForSP(mockSDKManager)
167+ val result = idpAuthCodeHelper.getAuthorizationPathForSP(
168+ getAuthorizationUrl = { _, _, _, _, _, _, _, _, _, _, _ ->
169+ null
170+ },
171+ salesforceSdkManager = sdkManager
172+ )
174173
175174 advanceUntilIdle()
176175
@@ -183,11 +182,15 @@ class IDPAuthCodeHelperTest {
183182 @Test
184183 fun idpAuthCodeHelper_getAuthorizationPathForSP_whenAuthorizationUrlHasNoQuery_returnsPathOnly () = runTest {
185184
186- val mockSDKManager = createMockSalesforceSDKManager()
187- stubOAuthAuthorizationUrl(returnValue = URI (" $TEST_LOGIN_SERVER$OAUTH_AUTHORIZE_PATH " ))
185+ val sdkManager = createMockSalesforceSDKManager()
188186 val idpAuthCodeHelper = createIdpAuthCodeHelper(appAttestationClient = null )
189187
190- val result = idpAuthCodeHelper.getAuthorizationPathForSP(mockSDKManager)
188+ val result = idpAuthCodeHelper.getAuthorizationPathForSP(
189+ getAuthorizationUrl = { _, _, _, _, _, _, _, _, _, _, _ ->
190+ URI (" $TEST_LOGIN_SERVER$OAUTH_AUTHORIZE_PATH " )
191+ },
192+ salesforceSdkManager = sdkManager
193+ )
191194
192195 advanceUntilIdle()
193196
@@ -233,17 +236,6 @@ class IDPAuthCodeHelperTest {
233236 appAttestationClient = appAttestationClient,
234237 )
235238
236- private fun stubOAuthAuthorizationUrl (returnValue : URI ? ) {
237- // Force OAuth2 class initialization before mocking to avoid ExceptionInInitializerError
238- OAuth2 .TIMESTAMP_FORMAT
239- mockkStatic(OAuth2 ::class )
240- every {
241- OAuth2 .getAuthorizationUrl(
242- any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(),
243- )
244- } returns returnValue
245- }
246-
247239 // endregion Helpers
248240
249241 private companion object {
0 commit comments