Skip to content

Commit 30d3ca8

Browse files
@W-21933885: [MSDK Android] App Attestation Implementation (Add Comprehensive Test For NativeLoginManager Line 184 Branch Coverage)
1 parent a44d1f0 commit 30d3ca8

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,43 @@ class NativeLoginManagerTest {
433433
}
434434
}
435435

436+
@OptIn(ExperimentalCoroutinesApi::class)
437+
@Test
438+
fun nativeLoginManager_login_togglesAttestationWhenNullOrPresent() = runTest {
439+
// Branch 1: attestationValue is null
440+
val restClientNullAttestation = createRestClientStubbingFailedLoginResponse()
441+
mgr = createNativeLoginManagerForTest(restClient = restClientNullAttestation)
442+
443+
mgr.login(TEST_USERNAME, TEST_PASSWORD)
444+
advanceUntilIdle()
445+
446+
// Verify URL does NOT contain attestation parameter (elvis branch)
447+
verify(exactly = 1) {
448+
restClientNullAttestation.sendAsync(match {
449+
it.path == "$TEST_LOGIN_URL$OAUTH_AUTH_PATH" && !it.path.contains("attestation=")
450+
}, any())
451+
}
452+
453+
// Clean up
454+
tearDown()
455+
setUp()
456+
457+
// Branch 2: attestationValue is not null (let block with Uri.encode)
458+
installAppAttestationClient(attestation = TEST_APP_ATTESTATION)
459+
val restClientWithAttestation = createRestClientStubbingFailedLoginResponse()
460+
mgr = createNativeLoginManagerForTest(restClient = restClientWithAttestation)
461+
462+
mgr.login(TEST_USERNAME, TEST_PASSWORD)
463+
advanceUntilIdle()
464+
465+
// Verify URL DOES contain encoded attestation parameter (let branch)
466+
verify(exactly = 1) {
467+
restClientWithAttestation.sendAsync(match {
468+
it.path.contains("?attestation=") && it.path.contains(TEST_APP_ATTESTATION)
469+
}, any())
470+
}
471+
}
472+
436473
// region Helpers used by attestation tests
437474

438475
private fun installAppAttestationClient(attestation: String?) {

0 commit comments

Comments
 (0)