allowing fingerprint to be passed to the config factory
- which in turn allows the android Uri to be bypassed and a unit test around the direct local certificate case added
This commit is contained in:
parent
457f7fffee
commit
a6ff10cbaf
|
@ -17,12 +17,13 @@
|
|||
package im.vector.app.features.login
|
||||
|
||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
import org.matrix.android.sdk.api.network.ssl.Fingerprint
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class HomeServerConnectionConfigFactory @Inject constructor() {
|
||||
|
||||
fun create(url: String?): HomeServerConnectionConfig? {
|
||||
fun create(url: String?, fingerprint: Fingerprint? = null): HomeServerConnectionConfig? {
|
||||
if (url == null) {
|
||||
return null
|
||||
}
|
||||
|
@ -30,6 +31,13 @@ class HomeServerConnectionConfigFactory @Inject constructor() {
|
|||
return try {
|
||||
HomeServerConnectionConfig.Builder()
|
||||
.withHomeServerUri(url)
|
||||
.run {
|
||||
if (fingerprint == null) {
|
||||
this
|
||||
} else {
|
||||
withAllowedFingerPrints(listOf(fingerprint))
|
||||
}
|
||||
}
|
||||
.build()
|
||||
} catch (t: Throwable) {
|
||||
Timber.e(t)
|
||||
|
|
|
@ -280,11 +280,8 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
is AuthenticateAction.LoginDirect ->
|
||||
handleDirectLogin(
|
||||
action.retryAction,
|
||||
HomeServerConnectionConfig.Builder()
|
||||
// Will be replaced by the task
|
||||
.withHomeServerUri("https://dummy.org")
|
||||
.withAllowedFingerPrints(listOf(action.fingerprint))
|
||||
.build()
|
||||
// Will be replaced by the task
|
||||
homeServerConnectionConfigFactory.create("https://dummy.org", action.fingerprint)
|
||||
)
|
||||
else -> Unit
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
|||
import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider
|
||||
import org.matrix.android.sdk.api.auth.registration.Stage
|
||||
import org.matrix.android.sdk.api.failure.Failure
|
||||
import org.matrix.android.sdk.api.network.ssl.Fingerprint
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
||||
|
||||
|
@ -69,6 +70,7 @@ private val A_LOADABLE_REGISTER_ACTION = RegisterAction.StartRegistration
|
|||
private val A_NON_LOADABLE_REGISTER_ACTION = RegisterAction.CheckIfEmailHasBeenValidated(delayMillis = -1L)
|
||||
private val A_RESULT_IGNORED_REGISTER_ACTION = RegisterAction.SendAgainThreePid
|
||||
private val A_HOMESERVER_CAPABILITIES = aHomeServerCapabilities(canChangeDisplayName = true, canChangeAvatar = true)
|
||||
private val A_FINGERPRINT = Fingerprint(ByteArray(1), Fingerprint.HashType.SHA1)
|
||||
private val ANY_CONTINUING_REGISTRATION_RESULT = RegistrationActionHandler.Result.NextStage(Stage.Dummy(mandatory = true))
|
||||
private val A_DIRECT_LOGIN = OnboardingAction.AuthenticateAction.LoginDirect("@a-user:id.org", "a-password", "a-device-name")
|
||||
private const val A_HOMESERVER_URL = "https://edited-homeserver.org"
|
||||
|
@ -406,7 +408,7 @@ class OnboardingViewModelTest {
|
|||
@Test
|
||||
fun `given unavailable deeplink, when selecting homeserver, then emits failure with default homeserver as retry action`() = runTest {
|
||||
fakeContext.givenHasConnection()
|
||||
fakeHomeServerConnectionConfigFactory.givenConfigFor(A_HOMESERVER_URL, A_HOMESERVER_CONFIG)
|
||||
fakeHomeServerConnectionConfigFactory.givenConfigFor(A_HOMESERVER_URL, fingerprint = null, A_HOMESERVER_CONFIG)
|
||||
fakeStartAuthenticationFlowUseCase.givenHomeserverUnavailable(A_HOMESERVER_CONFIG)
|
||||
val test = viewModel.test()
|
||||
|
||||
|
@ -723,6 +725,25 @@ class OnboardingViewModelTest {
|
|||
.assertEvents(OnboardingViewEvents.OnPersonalizationComplete)
|
||||
.finish()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given DirectLogin retry action, when accepting user certificate, then logs in directly`() = runTest {
|
||||
fakeHomeServerConnectionConfigFactory.givenConfigFor("https://dummy.org", A_FINGERPRINT, A_HOMESERVER_CONFIG)
|
||||
fakeDirectLoginUseCase.givenSuccessResult(A_DIRECT_LOGIN, config = A_HOMESERVER_CONFIG, result = fakeSession)
|
||||
givenInitialisesSession(fakeSession)
|
||||
val test = viewModel.test()
|
||||
|
||||
viewModel.handle(OnboardingAction.UserAcceptCertificate(A_FINGERPRINT, A_DIRECT_LOGIN))
|
||||
|
||||
test
|
||||
.assertStatesChanges(
|
||||
initialState,
|
||||
{ copy(isLoading = true) },
|
||||
{ copy(isLoading = false) }
|
||||
)
|
||||
.assertEvents(OnboardingViewEvents.OnAccountSignedIn)
|
||||
.finish()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given can successfully start password reset, when resetting password, then emits confirmation email sent`() = runTest {
|
||||
|
@ -991,15 +1012,19 @@ class OnboardingViewModelTest {
|
|||
fakeRegistrationActionHandler.givenResultsFor(results)
|
||||
}
|
||||
|
||||
private fun givenCanSuccessfullyUpdateHomeserver(homeserverUrl: String, resultingState: SelectedHomeserverState) {
|
||||
fakeHomeServerConnectionConfigFactory.givenConfigFor(homeserverUrl, A_HOMESERVER_CONFIG)
|
||||
fakeStartAuthenticationFlowUseCase.givenResult(A_HOMESERVER_CONFIG, StartAuthenticationResult(isHomeserverOutdated = false, resultingState))
|
||||
private fun givenCanSuccessfullyUpdateHomeserver(
|
||||
homeserverUrl: String,
|
||||
resultingState: SelectedHomeserverState,
|
||||
config: HomeServerConnectionConfig = A_HOMESERVER_CONFIG
|
||||
) {
|
||||
fakeHomeServerConnectionConfigFactory.givenConfigFor(homeserverUrl, fingerprint = null, config)
|
||||
fakeStartAuthenticationFlowUseCase.givenResult(config, StartAuthenticationResult(isHomeserverOutdated = false, resultingState))
|
||||
givenRegistrationResultFor(RegisterAction.StartRegistration, RegistrationActionHandler.Result.StartRegistration)
|
||||
fakeHomeServerHistoryService.expectUrlToBeAdded(A_HOMESERVER_CONFIG.homeServerUri.toString())
|
||||
fakeHomeServerHistoryService.expectUrlToBeAdded(config.homeServerUri.toString())
|
||||
}
|
||||
|
||||
private fun givenUpdatingHomeserverErrors(homeserverUrl: String, resultingState: SelectedHomeserverState, error: Throwable) {
|
||||
fakeHomeServerConnectionConfigFactory.givenConfigFor(homeserverUrl, A_HOMESERVER_CONFIG)
|
||||
fakeHomeServerConnectionConfigFactory.givenConfigFor(homeserverUrl, fingerprint = null, A_HOMESERVER_CONFIG)
|
||||
fakeStartAuthenticationFlowUseCase.givenResult(A_HOMESERVER_CONFIG, StartAuthenticationResult(isHomeserverOutdated = false, resultingState))
|
||||
givenRegistrationResultFor(RegisterAction.StartRegistration, RegistrationActionHandler.Result.Error(error))
|
||||
fakeHomeServerHistoryService.expectUrlToBeAdded(A_HOMESERVER_CONFIG.homeServerUri.toString())
|
||||
|
|
|
@ -20,11 +20,12 @@ import im.vector.app.features.login.HomeServerConnectionConfigFactory
|
|||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
import org.matrix.android.sdk.api.network.ssl.Fingerprint
|
||||
|
||||
class FakeHomeServerConnectionConfigFactory {
|
||||
val instance: HomeServerConnectionConfigFactory = mockk()
|
||||
|
||||
fun givenConfigFor(url: String, config: HomeServerConnectionConfig) {
|
||||
every { instance.create(url) } returns config
|
||||
fun givenConfigFor(url: String, fingerprint: Fingerprint? = null, config: HomeServerConnectionConfig) {
|
||||
every { instance.create(url, fingerprint) } returns config
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue