From 4902fe4990d4a777d38d014b1dadf1e832a7015f Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 19 Sep 2023 18:46:21 +0200 Subject: [PATCH] feat: use the raw homeserver URL instead of manually removing the scheme On the one hand, the SDK knows what to do and will clean up the URL if needs be, guessing what the best scheme (http or https) is based on the prefix. On the other hand, trimming the scheme as done here doesn't allow for manual testing on insecure servers, which is handy in e2e testing situations. --- changelog.d/1382.feature | 1 + .../login/impl/changeserver/ChangeServerPresenter.kt | 5 +---- .../ConfirmAccountProviderPresenter.kt | 5 +---- 3 files changed, 3 insertions(+), 8 deletions(-) create mode 100644 changelog.d/1382.feature diff --git a/changelog.d/1382.feature b/changelog.d/1382.feature new file mode 100644 index 0000000000..1ccf533815 --- /dev/null +++ b/changelog.d/1382.feature @@ -0,0 +1 @@ +Let the SDK figure the best scheme given an homeserver URL (thus allowing HTTP homeservers) diff --git a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/changeserver/ChangeServerPresenter.kt b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/changeserver/ChangeServerPresenter.kt index ef9f9e2441..8813a6a037 100644 --- a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/changeserver/ChangeServerPresenter.kt +++ b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/changeserver/ChangeServerPresenter.kt @@ -27,11 +27,9 @@ import io.element.android.features.login.impl.error.ChangeServerError import io.element.android.libraries.architecture.Async import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.architecture.runCatchingUpdatingState -import io.element.android.libraries.core.data.tryOrNull import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch -import java.net.URL import javax.inject.Inject class ChangeServerPresenter @Inject constructor( @@ -65,8 +63,7 @@ class ChangeServerPresenter @Inject constructor( changeServerAction: MutableState>, ) = launch { suspend { - val domain = tryOrNull { URL(data.title) }?.host ?: data.title - authenticationService.setHomeserver(domain).map { + authenticationService.setHomeserver(data.title).map { authenticationService.getHomeserverDetails().value!! // Valid, remember user choice accountProviderDataSource.userSelection(data) diff --git a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/confirmaccountprovider/ConfirmAccountProviderPresenter.kt b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/confirmaccountprovider/ConfirmAccountProviderPresenter.kt index d5412cb139..a647441800 100644 --- a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/confirmaccountprovider/ConfirmAccountProviderPresenter.kt +++ b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/confirmaccountprovider/ConfirmAccountProviderPresenter.kt @@ -35,11 +35,9 @@ import io.element.android.features.login.impl.oidc.customtab.DefaultOidcActionFl import io.element.android.libraries.architecture.Async import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.architecture.runCatchingUpdatingState -import io.element.android.libraries.core.data.tryOrNull import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch -import java.net.URL class ConfirmAccountProviderPresenter @AssistedInject constructor( @Assisted private val params: Params, @@ -97,8 +95,7 @@ class ConfirmAccountProviderPresenter @AssistedInject constructor( loginFlowAction: MutableState>, ) = launch { suspend { - val domain = tryOrNull { URL(homeserverUrl) }?.host ?: homeserverUrl - authenticationService.setHomeserver(domain).map { + authenticationService.setHomeserver(homeserverUrl).map { val matrixHomeServerDetails = authenticationService.getHomeserverDetails().value!! if (matrixHomeServerDetails.supportsOidcLogin) { // Retrieve the details right now