Skip to content

Commit db162e1

Browse files
@W-21933885: [MSDK Android] App Attestation Implementation (Increase Test Code Coverage For NativeLoginManager.createRequestBody)
1 parent ab5adb4 commit db162e1

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

libs/SalesforceSDK/src/com/salesforce/androidsdk/auth/NativeLoginManager.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ internal class NativeLoginManager(
145145
CONTENT_TYPE_HEADER_NAME to CONTENT_TYPE_VALUE_HTTP_POST,
146146
AUTHORIZATION to "$AUTH_AUTHORIZATION_VALUE_BASIC $encodedCreds",
147147
)
148+
// TODO: Needs Coverage. ECJ20260416
148149
val attestationValue = getInstance().appAttestationClient?.createSalesforceOAuthAuthorizationAppAttestation()
149150
val authRequestBody = createRequestBody(
150151
ATTESTATION to attestationValue,
@@ -242,9 +243,10 @@ internal class NativeLoginManager(
242243
}
243244
}
244245

245-
private fun createRequestBody(vararg kvPairs: Pair<String, String?>): RequestBody {
246-
kvPairs.filter { it.second != null }
247-
val requestBodyString = kvPairs.joinToString("&") { (key, value) -> "$key=$value" }
246+
@VisibleForTesting
247+
internal fun createRequestBody(vararg kvPairs: Pair<String, String?>): RequestBody {
248+
// TODO: Needs Coverage. ECJ20260416
249+
val requestBodyString = kvPairs.filter { it.second != null }.joinToString("&") { (key, value) -> "$key=$value" }
248250
val mediaType = CONTENT_TYPE_VALUE_HTTP_POST.toMediaTypeOrNull()
249251
return requestBodyString.toRequestBody(mediaType)
250252
}

libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/auth/NativeLoginManagerTest.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import com.salesforce.androidsdk.app.SalesforceSDKManager
88
import com.salesforce.androidsdk.security.BiometricAuthenticationManager
99
import org.junit.After
1010
import org.junit.Assert
11+
import org.junit.Assert.assertEquals
1112
import org.junit.Before
12-
import org.junit.Ignore
1313
import org.junit.Test
1414
import org.junit.runner.RunWith
1515

16-
@Ignore
1716
@RunWith(AndroidJUnit4::class)
1817
@SmallTest
1918
class NativeLoginManagerTest {
@@ -90,8 +89,17 @@ class NativeLoginManagerTest {
9089
Assert.assertEquals("Should return username.", "test_username", mgr.biometricAuthenticationUsername)
9190
}
9291

92+
@Test
93+
fun nativeLoginManager_createRequestBody_filtersNullValues() {
94+
95+
val result = mgr.createRequestBody("key1" to "value1", "key2" to null)
96+
97+
val buffer = okio.Buffer()
98+
result.writeTo(buffer)
99+
assertEquals("key1=value1", buffer.readUtf8())
100+
}
93101

94102
private fun addUserAccount() {
95-
UserAccountManager.getInstance().createAccount(UserAccountTest.createTestAccount());
103+
UserAccountManager.getInstance().createAccount(UserAccountTest.createTestAccount())
96104
}
97105
}

0 commit comments

Comments
 (0)