Skip to content

Commit 861840e

Browse files
@W-20161958: [MSDK 13.1][Android] Cannot login GUS using Welcome endpoint (Adjust covered logic in LoginViewModel)
1 parent 095f007 commit 861840e

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ package com.salesforce.androidsdk.ui
2828

2929
import android.annotation.SuppressLint
3030
import android.net.Uri
31+
import android.util.Log
3132
import android.webkit.CookieManager
3233
import android.webkit.URLUtil
3334
import android.webkit.WebView
@@ -65,7 +66,6 @@ import com.salesforce.androidsdk.config.OAuthConfig
6566
import com.salesforce.androidsdk.security.SalesforceKeyGenerator.getRandom128ByteKey
6667
import com.salesforce.androidsdk.security.SalesforceKeyGenerator.getSHA256Hash
6768
import com.salesforce.androidsdk.ui.LoginActivity.Companion.ABOUT_BLANK
68-
import com.salesforce.androidsdk.ui.LoginActivity.Companion.isSalesforceWelcomeDiscoveryMobileUrl
6969
import com.salesforce.androidsdk.ui.LoginActivity.Companion.isSalesforceWelcomeDiscoveryUrlPath
7070
import com.salesforce.androidsdk.util.SalesforceSDKLogger.e
7171
import kotlinx.coroutines.CoroutineScope
@@ -271,6 +271,7 @@ open class LoginViewModel(val bootConfig: BootConfig) : ViewModel() {
271271
// Update the web view URL to match the OAuth authorization URL when the web view is applicable
272272
webViewUrl.addSource(loginUrl) { newLoginUrl ->
273273
// Note the web view does not reload when browser-based authentication or a UI Bridge API front door bridge URL are active.
274+
/* Coverage needed */
274275
if ((!SalesforceSDKManager.getInstance().isBrowserLoginEnabled && !isUsingFrontDoorBridge) || newLoginUrl == "about:blank" /* Blank is used during reset states such as when returning to the web view from a custom tab, so it's always eligible */) {
275276
webViewUrl.value = newLoginUrl
276277
}
@@ -436,8 +437,9 @@ open class LoginViewModel(val bootConfig: BootConfig) : ViewModel() {
436437

437438
with(SalesforceSDKManager.getInstance()) {
438439
// Check if the OAuth Config has been manually set by dev support LoginOptionsActivity.
440+
val debugOverrideAppConfig = debugOverrideAppConfig
439441
oAuthConfig = if (isDebugBuild && debugOverrideAppConfig != null) {
440-
debugOverrideAppConfig!!
442+
debugOverrideAppConfig
441443
} else {
442444
appConfigForLoginHost(server) ?: OAuthConfig(bootConfig)
443445
}
@@ -514,9 +516,23 @@ open class LoginViewModel(val bootConfig: BootConfig) : ViewModel() {
514516
* */
515517
internal fun isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin(
516518
pendingLoginServerUri: Uri
517-
) = previousPendingLoginServer?.toUri()?.let { previousPendingLoginServerUri ->
518-
isSalesforceWelcomeDiscoveryUrlPath(previousPendingLoginServerUri) && !(isSalesforceWelcomeDiscoveryMobileUrl(pendingLoginServerUri))
519-
} ?: false
519+
): Boolean {
520+
val previousPendingLoginServerUri = previousPendingLoginServer?.toUri() ?: return false
521+
val a = isSalesforceWelcomeDiscoveryUrlPath(previousPendingLoginServerUri)
522+
val b = !isSalesforceWelcomeDiscoveryUrlPath(pendingLoginServerUri)
523+
524+
if (!a && !b) {
525+
Log.i("WSC", "1")
526+
} else if (a && !b) {
527+
Log.i("WSC", "2")
528+
} else if (!a && b) {
529+
Log.i("WSC", "3")
530+
} else if (a && b) {
531+
Log.i("WSC", "4")
532+
}
533+
534+
return a && b
535+
}
520536

521537
// endregion
522538

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ class LoginViewModelTest {
657657
}
658658

659659
@Test
660-
fun loginViewModel_isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin_returnsNullOnNullPreviousPendingLoginServer() {
660+
fun loginViewModel_isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin_returnsFalseOnNullPreviousPendingLoginServer() {
661661

662662
val exampleUrl = "https://www.example.com" // IETF-Reserved Test Domain
663663

@@ -666,7 +666,7 @@ class LoginViewModelTest {
666666
}
667667

668668
@Test
669-
fun loginViewModel_isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin_returnsNullOnUnparsablePreviousPendingLoginServer() {
669+
fun loginViewModel_isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin_returnsFalseOnUnparsablePreviousPendingLoginServer() {
670670

671671
val exampleUrl = "https://www.example.com" // IETF-Reserved Test Domain
672672

@@ -675,7 +675,7 @@ class LoginViewModelTest {
675675
}
676676

677677
@Test
678-
fun loginViewModel_isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin_returnsTrueOnSwitch() {
678+
fun loginViewModel_isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin_returnsTrueOnSwitchToDefault() {
679679

680680
val exampleUrl = "https://www.example.com" // IETF-Reserved Test Domain
681681

@@ -684,14 +684,30 @@ class LoginViewModelTest {
684684
}
685685

686686
@Test
687-
fun loginViewModel_isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin_returnsFalseOtherPreviousPendingLoginServer() {
687+
fun loginViewModel_isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin_returnsFalseOnSwitchToWelcome() {
688+
689+
val exampleUrl = "https://www.example.com" // IETF-Reserved Test Domain
690+
691+
viewModel.previousPendingLoginServer = exampleUrl
692+
assertFalse(viewModel.isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin(WELCOME_LOGIN_URL.toUri()))
693+
}
694+
695+
@Test
696+
fun loginViewModel_isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin_returnsFalseSwitchBetweenDefaultLoginUrls() {
688697

689698
val exampleUrl = "https://www.example.com" // IETF-Reserved Test Domain
690699

691700
viewModel.previousPendingLoginServer = "https://other.example.com" // IETF-Reserved Test Domain
692701
assertFalse(viewModel.isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin(exampleUrl.toUri()))
693702
}
694703

704+
@Test
705+
fun loginViewModel_isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin_returnsFalseSwitchBetweenWelcomeLoginUrls() {
706+
707+
viewModel.previousPendingLoginServer = WELCOME_LOGIN_URL
708+
assertFalse(viewModel.isSwitchFromSalesforceWelcomeDiscoveryToDefaultLogin(WELCOME_LOGIN_URL.toUri()))
709+
}
710+
695711
private fun generateExpectedAuthorizationUrl(
696712
server: String,
697713
codeChallenge: String,

0 commit comments

Comments
 (0)