Skip to content

Commit 2c21ab3

Browse files
@W-20161958: [MSDK 13.1][Android] Cannot login GUS using Welcome endpoint (Correct Coverage For startBrowserCustomTabAuthorization)
1 parent 4ce2e8a commit 2c21ab3

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/LoginActivity.kt

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import android.provider.Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED
5656
import android.security.KeyChain.choosePrivateKeyAlias
5757
import android.security.KeyChain.getCertificateChain
5858
import android.security.KeyChain.getPrivateKey
59+
import android.util.Log
5960
import android.view.KeyEvent
6061
import android.view.KeyEvent.KEYCODE_BACK
6162
import android.view.ViewGroup
@@ -252,6 +253,7 @@ open class LoginActivity : FragmentActivity() {
252253
applyIntent()
253254

254255
// Don't let sharedBrowserSession org setting stop a new user from logging in.
256+
// TODO: Coverage needed? ECJ20251212
255257
if (intent.extras?.getBoolean(NEW_USER) == true) {
256258
newUserIntent = true
257259
}
@@ -292,6 +294,7 @@ open class LoginActivity : FragmentActivity() {
292294
// Take control of the back logic if the device is locked.
293295
// TODO: Remove SDK_INT check when min API > 33
294296
if (SDK_INT >= TIRAMISU && biometricAuthenticationManager?.locked == true) {
297+
// TODO: Coverage needed? ECJ20251212
295298
onBackPressedDispatcher.addCallback { handleBackBehavior() }
296299
}
297300

@@ -300,6 +303,7 @@ open class LoginActivity : FragmentActivity() {
300303
viewModel.pendingServer.observe(this, PendingServerObserver())
301304

302305
// Support magic links
306+
// TODO: Coverage needed? ECJ20251212
303307
if (viewModel.jwt != null) {
304308
swapJWTForAccessToken()
305309
}
@@ -337,6 +341,7 @@ open class LoginActivity : FragmentActivity() {
337341
// If the intent is a callback from Chrome and not another recognized intent URL, process it and do nothing else.
338342
if (isCustomTabAuthFinishedCallback(intent) && intent.data?.let { (isQrCodeLoginUrlIntent(intent) || isSalesforceWelcomeDiscoveryMobileUrl(it)) } != true) {
339343
completeAdvAuthFlow(intent)
344+
// TODO: Coverage needed? ECJ20251212
340345
return
341346
}
342347

@@ -1106,9 +1111,56 @@ open class LoginActivity : FragmentActivity() {
11061111
singleServerCustomTabActivity: Boolean = viewModel.singleServerCustomTabActivity,
11071112
) {
11081113
// Load the authorization URL in a browser custom tab if required and do nothing otherwise as the view model will load it in the web view.
1109-
// TODO: Coverage needed? ECJ20251210
1110-
if ((singleServerCustomTabActivity || isBrowserLoginEnabled) && !isUsingFrontDoorBridge /* UI front-door bridge bypasses the need for browser custom tab */) {
1114+
// TODO: Coverage needed - This one is challenging. ECJ20251210
1115+
if (singleServerCustomTabActivity) {
1116+
Log.i("WSC", "A.1")
1117+
} else {
1118+
Log.i("WSC", "A.2")
1119+
}
1120+
if (isBrowserLoginEnabled) {
1121+
Log.i("WSC", "B.1")
1122+
} else {
1123+
Log.i("WSC", "B.2")
1124+
}
1125+
1126+
if ((!singleServerCustomTabActivity).and(!isBrowserLoginEnabled)) {
1127+
Log.i("WSC", "B.X Both Sides False")
1128+
}
1129+
1130+
if (singleServerCustomTabActivity.and(!isBrowserLoginEnabled)) {
1131+
Log.i("WSC", "B.3 Right Side")
1132+
}
1133+
1134+
if ((!singleServerCustomTabActivity).and(isBrowserLoginEnabled)) {
1135+
Log.i("WSC", "B.4 Left Side")
1136+
}
1137+
1138+
val useBrowserLogin = (singleServerCustomTabActivity.or(isBrowserLoginEnabled))
1139+
1140+
if (useBrowserLogin.and(isUsingFrontDoorBridge)) {
1141+
Log.i("WSC", "B.X Both Sides False")
1142+
}
1143+
1144+
if (useBrowserLogin.and(!isUsingFrontDoorBridge)) {
1145+
Log.i("WSC", "B.X Left/!Right")
1146+
}
1147+
1148+
if (isUsingFrontDoorBridge) {
1149+
Log.i("WSC", "C.1")
1150+
} else {
1151+
Log.i("WSC", "C.2")
1152+
}
1153+
1154+
if (useBrowserLogin.and(isUsingFrontDoorBridge)) {
1155+
Log.i("WSC", "C.3 Right Side")
1156+
}
1157+
1158+
val useBrowserLoginGuardAgainstFrontDoorBridge = useBrowserLogin.and(!isUsingFrontDoorBridge) /* UI front-door bridge bypasses the need for browser custom tab */
1159+
1160+
if (useBrowserLoginGuardAgainstFrontDoorBridge) {
11111161
loadLoginPageInCustomTab(authorizationUrl, activityResultLauncher)
1162+
} else {
1163+
Log.i("WSC", "X")
11121164
}
11131165
}
11141166

libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/ui/LoginActivityScenarioTest.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,33 @@ class LoginActivityScenarioTest {
302302
}
303303
}
304304

305+
@Test
306+
fun loginActivity_startBrowserCustomTabAuthorization_returnsActivityResultLauncherWhenBothBrowserLoginDisabledAndIsUsingFrontDoorBridge() {
307+
308+
val activityScenario = launch<LoginActivity>(
309+
Intent(
310+
getApplicationContext(),
311+
LoginActivity::class.java
312+
)
313+
)
314+
315+
activityScenario.onActivity { activity ->
316+
317+
val sdkManager = mockk<SalesforceSDKManager>()
318+
every { sdkManager.isBrowserLoginEnabled } returns true
319+
val activityResultLauncher = mockk<ActivityResultLauncher<Intent>>()
320+
321+
activity.startBrowserCustomTabAuthorization(
322+
authorizationUrl = "_authorization_url_",
323+
activityResultLauncher = activityResultLauncher,
324+
isBrowserLoginEnabled = false,
325+
isUsingFrontDoorBridge = true,
326+
singleServerCustomTabActivity = false,
327+
)
328+
verify(exactly = 0) { activityResultLauncher.launch(any()) }
329+
}
330+
}
331+
305332
@Test
306333
fun loginActivity_startBrowserCustomTabAuthorization_returnsActivityResultLauncherWhenIsUsingFrontDoorBridge() {
307334

0 commit comments

Comments
 (0)