From 489670cf6b04f4532c36032bbf7ba21b56e43f7a Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Fri, 4 Mar 2022 21:07:12 +0100 Subject: [PATCH] Adds validation failed test for SessionParamsCreator --- .../auth/DefaultSessionParamsCreatorTest.kt | 11 +++++++++++ .../auth/DefaultSessionParamsCreatorTestBase.kt | 16 ++++++++-------- .../auth/FakeIsValidClientServerApiTask.kt | 4 ++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/DefaultSessionParamsCreatorTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/DefaultSessionParamsCreatorTest.kt index 35693748ef..b303df4d9b 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/DefaultSessionParamsCreatorTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/DefaultSessionParamsCreatorTest.kt @@ -47,6 +47,7 @@ class DefaultSessionParamsCreatorTest : DefaultSessionParamsCreatorTestBase() { @Test fun `given credentials homeServerUri is equal to homeServerConnectionConfig, when create, then do not validate`() = runBlockingTest { val homeServerConnectionConfigWithCredentialsUri = homeServerConnectionConfig.copy(homeServerUriBase = discoveryWithHomeServer.getHomeServerUri()) + val output = sessionParamsCreator.create(credentialsWithHomeServer, homeServerConnectionConfigWithCredentialsUri, LoginType.UNKNOWN) fakeIsValidClientServerApiTask.verifyNoExecution() @@ -59,4 +60,14 @@ class DefaultSessionParamsCreatorTest : DefaultSessionParamsCreatorTestBase() { 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) + } } diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/DefaultSessionParamsCreatorTestBase.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/DefaultSessionParamsCreatorTestBase.kt index 385b03b061..61b808dd1a 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/DefaultSessionParamsCreatorTestBase.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/DefaultSessionParamsCreatorTestBase.kt @@ -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.SessionParams import org.matrix.android.sdk.internal.auth.login.LoginType -import org.matrix.android.sdk.test.fixtures.CredentialsFixture -import org.matrix.android.sdk.test.fixtures.DiscoveryInformationFixture +import org.matrix.android.sdk.test.fixtures.CredentialsFixture.aCredentials +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.WellKnownBaseConfigFixture +import org.matrix.android.sdk.test.fixtures.WellKnownBaseConfigFixture.aWellKnownBaseConfig abstract class DefaultSessionParamsCreatorTestBase { - protected val discoveryWithHomeServer = DiscoveryInformationFixture.aDiscoveryInformation(homeServer = WellKnownBaseConfigFixture.aWellKnownBaseConfig("http://homeserver_url/")) - private val discoveryWithIdentityServer = DiscoveryInformationFixture.aDiscoveryInformation(identityServer = WellKnownBaseConfigFixture.aWellKnownBaseConfig("http://identity_server_url/")) - protected val credentials = CredentialsFixture.aCredentials() - protected val credentialsWithHomeServer = CredentialsFixture.aCredentials(discoveryInformation = discoveryWithHomeServer) - protected val credentialsWithIdentityServer = CredentialsFixture.aCredentials(discoveryInformation = discoveryWithIdentityServer) + protected val discoveryWithHomeServer = aDiscoveryInformation(homeServer = aWellKnownBaseConfig("http://homeserver_url/")) + private val discoveryWithIdentityServer = aDiscoveryInformation(identityServer = aWellKnownBaseConfig("http://identity_server_url/")) + protected val credentials = aCredentials() + protected val credentialsWithHomeServer = aCredentials(discoveryInformation = discoveryWithHomeServer) + protected val credentialsWithIdentityServer = aCredentials(discoveryInformation = discoveryWithIdentityServer) protected val homeServerConnectionConfig = aHomeServerConnectionConfig() protected fun assertExpectedSessionParams(sessionParams: SessionParams) { diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/internal/auth/FakeIsValidClientServerApiTask.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/internal/auth/FakeIsValidClientServerApiTask.kt index 3eeda6db65..f8018e7b7e 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/internal/auth/FakeIsValidClientServerApiTask.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/internal/auth/FakeIsValidClientServerApiTask.kt @@ -31,6 +31,10 @@ internal class FakeIsValidClientServerApiTask { val instance: IsValidClientServerApiTask = mockk() + fun givenValidationFails() { + coEvery { instance.execute(any()) } returns false + } + fun verifyExecutionWithConfig(config: HomeServerConnectionConfig) { coVerify { instance.execute(Params(config)) } }