Merge pull request #7684 from vector-im/feature/bma/fix_onboarding_crash
Fix crash when invalid url is entered #7672
This commit is contained in:
commit
75fabb1b0d
1
changelog.d/7684.bugfix
Normal file
1
changelog.d/7684.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix crash when invalid homeserver url is entered.
|
@ -118,7 +118,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkQrCodeLoginCapability(homeServerUrl: String) {
|
private suspend fun checkQrCodeLoginCapability(config: HomeServerConnectionConfig) {
|
||||||
if (!vectorFeatures.isQrCodeLoginEnabled()) {
|
if (!vectorFeatures.isQrCodeLoginEnabled()) {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
@ -133,16 +133,12 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
viewModelScope.launch {
|
// check if selected server supports MSC3882 first
|
||||||
// check if selected server supports MSC3882 first
|
val canLoginWithQrCode = authenticationService.isQrLoginSupported(config)
|
||||||
homeServerConnectionConfigFactory.create(homeServerUrl)?.let {
|
setState {
|
||||||
val canLoginWithQrCode = authenticationService.isQrLoginSupported(it)
|
copy(
|
||||||
setState {
|
canLoginWithQrCode = canLoginWithQrCode
|
||||||
copy(
|
)
|
||||||
canLoginWithQrCode = canLoginWithQrCode
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -710,7 +706,6 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||||||
_viewEvents.post(OnboardingViewEvents.Failure(Throwable("Unable to create a HomeServerConnectionConfig")))
|
_viewEvents.post(OnboardingViewEvents.Failure(Throwable("Unable to create a HomeServerConnectionConfig")))
|
||||||
} else {
|
} else {
|
||||||
startAuthenticationFlow(action, homeServerConnectionConfig, serverTypeOverride, postAction)
|
startAuthenticationFlow(action, homeServerConnectionConfig, serverTypeOverride, postAction)
|
||||||
checkQrCodeLoginCapability(homeServerConnectionConfig.homeServerUri.toString())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -769,6 +764,8 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||||||
_viewEvents.post(OnboardingViewEvents.OutdatedHomeserver)
|
_viewEvents.post(OnboardingViewEvents.OutdatedHomeserver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkQrCodeLoginCapability(config)
|
||||||
|
|
||||||
when (trigger) {
|
when (trigger) {
|
||||||
is OnboardingAction.HomeServerChange.SelectHomeServer -> {
|
is OnboardingAction.HomeServerChange.SelectHomeServer -> {
|
||||||
onHomeServerSelected(config, serverTypeOverride, authResult)
|
onHomeServerSelected(config, serverTypeOverride, authResult)
|
||||||
|
@ -160,6 +160,28 @@ class OnboardingViewModelTest {
|
|||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given combined login enabled, when handling sign in splash action, then emits OpenCombinedLogin with default homeserver qrCode supported`() = runTest {
|
||||||
|
val test = viewModel.test()
|
||||||
|
fakeVectorFeatures.givenCombinedLoginEnabled()
|
||||||
|
givenCanSuccessfullyUpdateHomeserver(A_DEFAULT_HOMESERVER_URL, DEFAULT_SELECTED_HOMESERVER_STATE, canLoginWithQrCode = true)
|
||||||
|
|
||||||
|
viewModel.handle(OnboardingAction.SplashAction.OnIAlreadyHaveAnAccount(OnboardingFlow.SignIn))
|
||||||
|
|
||||||
|
test
|
||||||
|
.assertStatesChanges(
|
||||||
|
initialState,
|
||||||
|
{ copy(onboardingFlow = OnboardingFlow.SignIn) },
|
||||||
|
{ copy(isLoading = true) },
|
||||||
|
{ copy(canLoginWithQrCode = true) },
|
||||||
|
{ copy(selectedHomeserver = DEFAULT_SELECTED_HOMESERVER_STATE) },
|
||||||
|
{ copy(signMode = SignMode.SignIn) },
|
||||||
|
{ copy(isLoading = false) }
|
||||||
|
)
|
||||||
|
.assertEvents(OnboardingViewEvents.OpenCombinedLogin)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given can successfully login in with token, when logging in with token, then emits AccountSignedIn`() = runTest {
|
fun `given can successfully login in with token, when logging in with token, then emits AccountSignedIn`() = runTest {
|
||||||
val test = viewModel.test()
|
val test = viewModel.test()
|
||||||
@ -1152,11 +1174,13 @@ class OnboardingViewModelTest {
|
|||||||
resultingState: SelectedHomeserverState,
|
resultingState: SelectedHomeserverState,
|
||||||
config: HomeServerConnectionConfig = A_HOMESERVER_CONFIG,
|
config: HomeServerConnectionConfig = A_HOMESERVER_CONFIG,
|
||||||
fingerprint: Fingerprint? = null,
|
fingerprint: Fingerprint? = null,
|
||||||
|
canLoginWithQrCode: Boolean = false,
|
||||||
) {
|
) {
|
||||||
fakeHomeServerConnectionConfigFactory.givenConfigFor(homeserverUrl, fingerprint, 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())
|
||||||
|
fakeAuthenticationService.givenIsQrLoginSupported(config, canLoginWithQrCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun givenUpdatingHomeserverErrors(homeserverUrl: String, resultingState: SelectedHomeserverState, error: Throwable) {
|
private fun givenUpdatingHomeserverErrors(homeserverUrl: String, resultingState: SelectedHomeserverState, error: Throwable) {
|
||||||
@ -1164,6 +1188,7 @@ class OnboardingViewModelTest {
|
|||||||
fakeStartAuthenticationFlowUseCase.givenResult(A_HOMESERVER_CONFIG, StartAuthenticationResult(isHomeserverOutdated = false, resultingState))
|
fakeStartAuthenticationFlowUseCase.givenResult(A_HOMESERVER_CONFIG, StartAuthenticationResult(isHomeserverOutdated = false, resultingState))
|
||||||
givenRegistrationResultFor(RegisterAction.StartRegistration, RegistrationActionHandler.Result.Error(error))
|
givenRegistrationResultFor(RegisterAction.StartRegistration, RegistrationActionHandler.Result.Error(error))
|
||||||
fakeHomeServerHistoryService.expectUrlToBeAdded(A_HOMESERVER_CONFIG.homeServerUri.toString())
|
fakeHomeServerHistoryService.expectUrlToBeAdded(A_HOMESERVER_CONFIG.homeServerUri.toString())
|
||||||
|
fakeAuthenticationService.givenIsQrLoginSupported(A_HOMESERVER_CONFIG, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun givenUserNameIsAvailable(userName: String) {
|
private fun givenUserNameIsAvailable(userName: String) {
|
||||||
|
@ -58,6 +58,10 @@ class FakeAuthenticationService : AuthenticationService by mockk() {
|
|||||||
coEvery { getWellKnownData(matrixId, config) } returns result
|
coEvery { getWellKnownData(matrixId, config) } returns result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun givenIsQrLoginSupported(config: HomeServerConnectionConfig, result: Boolean) {
|
||||||
|
coEvery { isQrLoginSupported(config) } returns result
|
||||||
|
}
|
||||||
|
|
||||||
fun givenWellKnownThrows(matrixId: String, config: HomeServerConnectionConfig?, cause: Throwable) {
|
fun givenWellKnownThrows(matrixId: String, config: HomeServerConnectionConfig?, cause: Throwable) {
|
||||||
coEvery { getWellKnownData(matrixId, config) } throws cause
|
coEvery { getWellKnownData(matrixId, config) } throws cause
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user