@@ -5,7 +5,17 @@ import androidx.test.filters.SmallTest
55import com.salesforce.androidsdk.accounts.UserAccountManager
66import com.salesforce.androidsdk.accounts.UserAccountTest
77import com.salesforce.androidsdk.app.SalesforceSDKManager
8+ import com.salesforce.androidsdk.rest.RestClient
9+ import com.salesforce.androidsdk.rest.RestResponse
810import com.salesforce.androidsdk.security.BiometricAuthenticationManager
11+ import io.mockk.coEvery
12+ import io.mockk.every
13+ import io.mockk.mockk
14+ import io.mockk.verify
15+ import kotlinx.coroutines.ExperimentalCoroutinesApi
16+ import kotlinx.coroutines.test.advanceUntilIdle
17+ import kotlinx.coroutines.test.runTest
18+ import okhttp3.Call
919import org.junit.After
1020import org.junit.Assert
1121import org.junit.Assert.assertEquals
@@ -99,6 +109,50 @@ class NativeLoginManagerTest {
99109 assertEquals(" key1=value1" , buffer.readUtf8())
100110 }
101111
112+ // TODO: This test will need additional review. ECJ20260416
113+ @OptIn(ExperimentalCoroutinesApi ::class )
114+ @Test
115+ fun nativeLoginManager_login_collectsAppAttestation () = runTest {
116+
117+ val appAttestationClient = mockk<AppAttestationClient >(relaxed = true )
118+ coEvery { appAttestationClient.createSalesforceOAuthAuthorizationAppAttestation() } returns " __TEST_APP_ATTESTATION__"
119+
120+ val salesforceSdkManager = SalesforceSDKManager .getInstance()
121+ salesforceSdkManager.appAttestationClient = appAttestationClient
122+
123+ val restClient = mockk<RestClient >(relaxed = true )
124+ val mockResponse = mockk<RestResponse >(relaxed = true )
125+ every { mockResponse.isSuccess } returns false
126+ every {
127+ restClient.sendAsync(any(), any())
128+ } answers {
129+ val callback = secondArg<RestClient .AsyncRequestCallback >()
130+ callback.onSuccess(firstArg(), mockResponse)
131+ mockk<Call >(relaxed = true )
132+ }
133+
134+ mgr = NativeLoginManager (
135+ clientId = " clientId" ,
136+ redirectUri = " redirect" ,
137+ loginUrl = " loginUrl" ,
138+ restClient = restClient,
139+ )
140+
141+ mgr.login(" TestUser@Example.com" , " test123456" )
142+
143+ advanceUntilIdle()
144+
145+ verify (exactly = 1 ) {
146+ restClient.sendAsync(match {
147+ runCatching {
148+ val buffer = okio.Buffer ()
149+ it.requestBody?.writeTo(buffer)
150+ buffer.readUtf8().contains(" attestation=__TEST_APP_ATTESTATION__" )
151+ }.getOrDefault(false )
152+ }, any())
153+ }
154+ }
155+
102156 private fun addUserAccount () {
103157 UserAccountManager .getInstance().createAccount(UserAccountTest .createTestAccount())
104158 }
0 commit comments