Adds validation failed test for SessionParamsCreator

This commit is contained in:
ericdecanini 2022-03-04 21:07:12 +01:00
parent bcd802d335
commit 489670cf6b
3 changed files with 23 additions and 8 deletions

View file

@ -47,6 +47,7 @@ class DefaultSessionParamsCreatorTest : DefaultSessionParamsCreatorTestBase() {
@Test @Test
fun `given credentials homeServerUri is equal to homeServerConnectionConfig, when create, then do not validate`() = runBlockingTest { fun `given credentials homeServerUri is equal to homeServerConnectionConfig, when create, then do not validate`() = runBlockingTest {
val homeServerConnectionConfigWithCredentialsUri = homeServerConnectionConfig.copy(homeServerUriBase = discoveryWithHomeServer.getHomeServerUri()) val homeServerConnectionConfigWithCredentialsUri = homeServerConnectionConfig.copy(homeServerUriBase = discoveryWithHomeServer.getHomeServerUri())
val output = sessionParamsCreator.create(credentialsWithHomeServer, homeServerConnectionConfigWithCredentialsUri, LoginType.UNKNOWN) val output = sessionParamsCreator.create(credentialsWithHomeServer, homeServerConnectionConfigWithCredentialsUri, LoginType.UNKNOWN)
fakeIsValidClientServerApiTask.verifyNoExecution() fakeIsValidClientServerApiTask.verifyNoExecution()
@ -59,4 +60,14 @@ class DefaultSessionParamsCreatorTest : DefaultSessionParamsCreatorTestBase() {
assertExpectedSessionParamsWithIdentityServer(output) assertExpectedSessionParamsWithIdentityServer(output)
} }
@Test
fun `given home server validation fails, when create, then do not use home server uri from credentials`() = runBlockingTest {
fakeIsValidClientServerApiTask.givenValidationFails()
val output = sessionParamsCreator.create(credentialsWithHomeServer, homeServerConnectionConfig, LoginType.UNKNOWN)
fakeIsValidClientServerApiTask.verifyExecutionWithConfig(homeServerConnectionConfig)
assertExpectedSessionParams(output)
}
} }

View file

@ -21,18 +21,18 @@ import org.amshove.kluent.shouldBeEqualTo
import org.matrix.android.sdk.api.auth.data.DiscoveryInformation import org.matrix.android.sdk.api.auth.data.DiscoveryInformation
import org.matrix.android.sdk.api.auth.data.SessionParams import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.internal.auth.login.LoginType import org.matrix.android.sdk.internal.auth.login.LoginType
import org.matrix.android.sdk.test.fixtures.CredentialsFixture import org.matrix.android.sdk.test.fixtures.CredentialsFixture.aCredentials
import org.matrix.android.sdk.test.fixtures.DiscoveryInformationFixture import org.matrix.android.sdk.test.fixtures.DiscoveryInformationFixture.aDiscoveryInformation
import org.matrix.android.sdk.test.fixtures.HomeServerConnectionConfigFixture.aHomeServerConnectionConfig import org.matrix.android.sdk.test.fixtures.HomeServerConnectionConfigFixture.aHomeServerConnectionConfig
import org.matrix.android.sdk.test.fixtures.WellKnownBaseConfigFixture import org.matrix.android.sdk.test.fixtures.WellKnownBaseConfigFixture.aWellKnownBaseConfig
abstract class DefaultSessionParamsCreatorTestBase { abstract class DefaultSessionParamsCreatorTestBase {
protected val discoveryWithHomeServer = DiscoveryInformationFixture.aDiscoveryInformation(homeServer = WellKnownBaseConfigFixture.aWellKnownBaseConfig("http://homeserver_url/")) protected val discoveryWithHomeServer = aDiscoveryInformation(homeServer = aWellKnownBaseConfig("http://homeserver_url/"))
private val discoveryWithIdentityServer = DiscoveryInformationFixture.aDiscoveryInformation(identityServer = WellKnownBaseConfigFixture.aWellKnownBaseConfig("http://identity_server_url/")) private val discoveryWithIdentityServer = aDiscoveryInformation(identityServer = aWellKnownBaseConfig("http://identity_server_url/"))
protected val credentials = CredentialsFixture.aCredentials() protected val credentials = aCredentials()
protected val credentialsWithHomeServer = CredentialsFixture.aCredentials(discoveryInformation = discoveryWithHomeServer) protected val credentialsWithHomeServer = aCredentials(discoveryInformation = discoveryWithHomeServer)
protected val credentialsWithIdentityServer = CredentialsFixture.aCredentials(discoveryInformation = discoveryWithIdentityServer) protected val credentialsWithIdentityServer = aCredentials(discoveryInformation = discoveryWithIdentityServer)
protected val homeServerConnectionConfig = aHomeServerConnectionConfig() protected val homeServerConnectionConfig = aHomeServerConnectionConfig()
protected fun assertExpectedSessionParams(sessionParams: SessionParams) { protected fun assertExpectedSessionParams(sessionParams: SessionParams) {

View file

@ -31,6 +31,10 @@ internal class FakeIsValidClientServerApiTask {
val instance: IsValidClientServerApiTask = mockk() val instance: IsValidClientServerApiTask = mockk()
fun givenValidationFails() {
coEvery { instance.execute(any()) } returns false
}
fun verifyExecutionWithConfig(config: HomeServerConnectionConfig) { fun verifyExecutionWithConfig(config: HomeServerConnectionConfig) {
coVerify { instance.execute(Params(config)) } coVerify { instance.execute(Params(config)) }
} }