recreating the homeserver config from the retry action when handle certificate accept action
- adds unit tests around the edit/selection cases
This commit is contained in:
parent
a6ff10cbaf
commit
e4a08d1be1
@ -63,6 +63,7 @@ import org.matrix.android.sdk.api.auth.registration.RegistrationWizard
|
|||||||
import org.matrix.android.sdk.api.failure.Failure
|
import org.matrix.android.sdk.api.failure.Failure
|
||||||
import org.matrix.android.sdk.api.failure.isHomeserverUnavailable
|
import org.matrix.android.sdk.api.failure.isHomeserverUnavailable
|
||||||
import org.matrix.android.sdk.api.failure.isUnrecognisedCertificate
|
import org.matrix.android.sdk.api.failure.isUnrecognisedCertificate
|
||||||
|
import org.matrix.android.sdk.api.network.ssl.Fingerprint
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.util.BuildVersionSdkIntProvider
|
import org.matrix.android.sdk.api.util.BuildVersionSdkIntProvider
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@ -115,8 +116,6 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var currentHomeServerConnectionConfig: HomeServerConnectionConfig? = null
|
|
||||||
|
|
||||||
private val matrixOrgUrl = stringProvider.getString(R.string.matrix_org_server_url).ensureTrailingSlash()
|
private val matrixOrgUrl = stringProvider.getString(R.string.matrix_org_server_url).ensureTrailingSlash()
|
||||||
private val defaultHomeserverUrl = matrixOrgUrl
|
private val defaultHomeserverUrl = matrixOrgUrl
|
||||||
|
|
||||||
@ -272,11 +271,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||||||
// It happens when we get the login flow, or during direct authentication.
|
// It happens when we get the login flow, or during direct authentication.
|
||||||
// So alter the homeserver config and retrieve again the login flow
|
// So alter the homeserver config and retrieve again the login flow
|
||||||
when (action.retryAction) {
|
when (action.retryAction) {
|
||||||
is OnboardingAction.HomeServerChange -> {
|
is OnboardingAction.HomeServerChange -> handleHomeserverChange(action.retryAction, fingerprint = action.fingerprint)
|
||||||
currentHomeServerConnectionConfig
|
|
||||||
?.let { it.copy(allowedFingerprints = it.allowedFingerprints + action.fingerprint) }
|
|
||||||
?.let { startAuthenticationFlow(action.retryAction, it, serverTypeOverride = null) }
|
|
||||||
}
|
|
||||||
is AuthenticateAction.LoginDirect ->
|
is AuthenticateAction.LoginDirect ->
|
||||||
handleDirectLogin(
|
handleDirectLogin(
|
||||||
action.retryAction,
|
action.retryAction,
|
||||||
@ -684,8 +679,13 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleHomeserverChange(action: OnboardingAction.HomeServerChange, serverTypeOverride: ServerType? = null, postAction: suspend () -> Unit = {}) {
|
private fun handleHomeserverChange(
|
||||||
val homeServerConnectionConfig = homeServerConnectionConfigFactory.create(action.homeServerUrl)
|
action: OnboardingAction.HomeServerChange,
|
||||||
|
serverTypeOverride: ServerType? = null,
|
||||||
|
fingerprint: Fingerprint? = null,
|
||||||
|
postAction: suspend () -> Unit = {},
|
||||||
|
) {
|
||||||
|
val homeServerConnectionConfig = homeServerConnectionConfigFactory.create(action.homeServerUrl, fingerprint)
|
||||||
if (homeServerConnectionConfig == null) {
|
if (homeServerConnectionConfig == null) {
|
||||||
// This is invalid
|
// This is invalid
|
||||||
_viewEvents.post(OnboardingViewEvents.Failure(Throwable("Unable to create a HomeServerConnectionConfig")))
|
_viewEvents.post(OnboardingViewEvents.Failure(Throwable("Unable to create a HomeServerConnectionConfig")))
|
||||||
@ -700,8 +700,6 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||||||
serverTypeOverride: ServerType?,
|
serverTypeOverride: ServerType?,
|
||||||
postAction: suspend () -> Unit = {},
|
postAction: suspend () -> Unit = {},
|
||||||
) {
|
) {
|
||||||
currentHomeServerConnectionConfig = homeServerConnectionConfig
|
|
||||||
|
|
||||||
currentJob = viewModelScope.launch {
|
currentJob = viewModelScope.launch {
|
||||||
setState { copy(isLoading = true) }
|
setState { copy(isLoading = true) }
|
||||||
runCatching { startAuthenticationFlowUseCase.execute(homeServerConnectionConfig) }.fold(
|
runCatching { startAuthenticationFlowUseCase.execute(homeServerConnectionConfig) }.fold(
|
||||||
|
@ -725,7 +725,59 @@ class OnboardingViewModelTest {
|
|||||||
.assertEvents(OnboardingViewEvents.OnPersonalizationComplete)
|
.assertEvents(OnboardingViewEvents.OnPersonalizationComplete)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given in sign in mode, when accepting user certificate with SelectHomeserver retry action, then emits OnHomeserverEdited`() = runTest {
|
||||||
|
viewModelWith(initialState.copy(onboardingFlow = OnboardingFlow.SignIn))
|
||||||
|
val test = viewModel.test()
|
||||||
|
fakeVectorFeatures.givenCombinedLoginEnabled()
|
||||||
|
givenCanSuccessfullyUpdateHomeserver(
|
||||||
|
A_HOMESERVER_URL,
|
||||||
|
SELECTED_HOMESERVER_STATE,
|
||||||
|
config = A_HOMESERVER_CONFIG.copy(allowedFingerprints = listOf(A_FINGERPRINT)),
|
||||||
|
fingerprint = A_FINGERPRINT,
|
||||||
|
)
|
||||||
|
|
||||||
|
viewModel.handle(OnboardingAction.UserAcceptCertificate(A_FINGERPRINT, OnboardingAction.HomeServerChange.SelectHomeServer(A_HOMESERVER_URL)))
|
||||||
|
|
||||||
|
test
|
||||||
|
.assertStatesChanges(
|
||||||
|
initialState,
|
||||||
|
{ copy(isLoading = true) },
|
||||||
|
{ copy(selectedHomeserver = SELECTED_HOMESERVER_STATE) },
|
||||||
|
{ copy(signMode = SignMode.SignIn) },
|
||||||
|
{ copy(isLoading = false) }
|
||||||
|
)
|
||||||
|
.assertEvents(OnboardingViewEvents.OpenCombinedLogin)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given in sign up mode, when accepting user certificate with EditHomeserver retry action, then emits OnHomeserverEdited`() = runTest {
|
||||||
|
viewModelWith(initialState.copy(onboardingFlow = OnboardingFlow.SignUp))
|
||||||
|
givenCanSuccessfullyUpdateHomeserver(
|
||||||
|
A_HOMESERVER_URL,
|
||||||
|
SELECTED_HOMESERVER_STATE,
|
||||||
|
config = A_HOMESERVER_CONFIG.copy(allowedFingerprints = listOf(A_FINGERPRINT)),
|
||||||
|
fingerprint = A_FINGERPRINT,
|
||||||
|
)
|
||||||
|
val test = viewModel.test()
|
||||||
|
|
||||||
|
viewModel.handle(OnboardingAction.UserAcceptCertificate(A_FINGERPRINT, OnboardingAction.HomeServerChange.EditHomeServer(A_HOMESERVER_URL)))
|
||||||
|
|
||||||
|
test
|
||||||
|
.assertStatesChanges(
|
||||||
|
initialState,
|
||||||
|
{ copy(isLoading = true) },
|
||||||
|
{ copy(selectedHomeserver = SELECTED_HOMESERVER_STATE) },
|
||||||
|
{ copy(isLoading = false) }
|
||||||
|
|
||||||
|
)
|
||||||
|
.assertEvents(OnboardingViewEvents.OnHomeserverEdited)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given DirectLogin retry action, when accepting user certificate, then logs in directly`() = runTest {
|
fun `given DirectLogin retry action, when accepting user certificate, then logs in directly`() = runTest {
|
||||||
fakeHomeServerConnectionConfigFactory.givenConfigFor("https://dummy.org", A_FINGERPRINT, A_HOMESERVER_CONFIG)
|
fakeHomeServerConnectionConfigFactory.givenConfigFor("https://dummy.org", A_FINGERPRINT, A_HOMESERVER_CONFIG)
|
||||||
@ -1015,9 +1067,10 @@ class OnboardingViewModelTest {
|
|||||||
private fun givenCanSuccessfullyUpdateHomeserver(
|
private fun givenCanSuccessfullyUpdateHomeserver(
|
||||||
homeserverUrl: String,
|
homeserverUrl: String,
|
||||||
resultingState: SelectedHomeserverState,
|
resultingState: SelectedHomeserverState,
|
||||||
config: HomeServerConnectionConfig = A_HOMESERVER_CONFIG
|
config: HomeServerConnectionConfig = A_HOMESERVER_CONFIG,
|
||||||
|
fingerprint: Fingerprint? = null,
|
||||||
) {
|
) {
|
||||||
fakeHomeServerConnectionConfigFactory.givenConfigFor(homeserverUrl, fingerprint = null, config)
|
fakeHomeServerConnectionConfigFactory.givenConfigFor(homeserverUrl, fingerprint, config)
|
||||||
fakeStartAuthenticationFlowUseCase.givenResult(config, StartAuthenticationResult(isHomeserverOutdated = false, resultingState))
|
fakeStartAuthenticationFlowUseCase.givenResult(config, StartAuthenticationResult(isHomeserverOutdated = false, resultingState))
|
||||||
givenRegistrationResultFor(RegisterAction.StartRegistration, RegistrationActionHandler.Result.StartRegistration)
|
givenRegistrationResultFor(RegisterAction.StartRegistration, RegistrationActionHandler.Result.StartRegistration)
|
||||||
fakeHomeServerHistoryService.expectUrlToBeAdded(config.homeServerUri.toString())
|
fakeHomeServerHistoryService.expectUrlToBeAdded(config.homeServerUri.toString())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user