Refactors SessionCreator with added tests

This commit is contained in:
ericdecanini 2022-03-03 17:51:50 +01:00
parent 47d5d09af2
commit 40dee006dd
21 changed files with 600 additions and 61 deletions

View file

@ -175,7 +175,7 @@ dependencies {
// Note: version sticks to 1.9.2 due to https://github.com/mockk/mockk/issues/281 // Note: version sticks to 1.9.2 due to https://github.com/mockk/mockk/issues/281
testImplementation libs.mockk.mockk testImplementation libs.mockk.mockk
testImplementation libs.tests.kluent testImplementation libs.tests.kluent
implementation libs.jetbrains.coroutinesAndroid testImplementation libs.jetbrains.coroutinesTest
// Plant Timber tree for test // Plant Timber tree for test
testImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1' testImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1'
// Transitively required for mocking realm as monarchy doesn't expose Rx // Transitively required for mocking realm as monarchy doesn't expose Rx

View file

@ -81,6 +81,9 @@ internal abstract class AuthModule {
@Binds @Binds
abstract fun bindSessionCreator(creator: DefaultSessionCreator): SessionCreator abstract fun bindSessionCreator(creator: DefaultSessionCreator): SessionCreator
@Binds
abstract fun bindSessionParamsCreator(creator: DefaultSessionParamsCreator): SessionParamsCreator
@Binds @Binds
abstract fun bindDirectLoginTask(task: DefaultDirectLoginTask): DirectLoginTask abstract fun bindDirectLoginTask(task: DefaultDirectLoginTask): DirectLoginTask

View file

@ -16,69 +16,41 @@
package org.matrix.android.sdk.internal.auth package org.matrix.android.sdk.internal.auth
import android.net.Uri
import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.internal.SessionManager import org.matrix.android.sdk.internal.SessionManager
import timber.log.Timber import org.matrix.android.sdk.internal.auth.login.LoginType
import javax.inject.Inject import javax.inject.Inject
internal interface SessionCreator { internal interface SessionCreator {
suspend fun createSession(credentials: Credentials, homeServerConnectionConfig: HomeServerConnectionConfig): Session
suspend fun createSession(
credentials: Credentials,
homeServerConnectionConfig: HomeServerConnectionConfig,
loginType: LoginType,
): Session
} }
internal class DefaultSessionCreator @Inject constructor( internal class DefaultSessionCreator @Inject constructor(
private val sessionParamsStore: SessionParamsStore, private val sessionParamsStore: SessionParamsStore,
private val sessionManager: SessionManager, private val sessionManager: SessionManager,
private val pendingSessionStore: PendingSessionStore, private val pendingSessionStore: PendingSessionStore,
private val isValidClientServerApiTask: IsValidClientServerApiTask private val sessionParamsCreator: SessionParamsCreator,
) : SessionCreator { ) : SessionCreator {
/** /**
* Credentials can affect the homeServerConnectionConfig, override homeserver url and/or * Credentials can affect the homeServerConnectionConfig, override homeserver url and/or
* identity server url if provided in the credentials * identity server url if provided in the credentials
*/ */
override suspend fun createSession(credentials: Credentials, homeServerConnectionConfig: HomeServerConnectionConfig): Session { override suspend fun createSession(
credentials: Credentials,
homeServerConnectionConfig: HomeServerConnectionConfig,
loginType: LoginType,
): Session {
// We can cleanup the pending session params // We can cleanup the pending session params
pendingSessionStore.delete() pendingSessionStore.delete()
val sessionParams = sessionParamsCreator.create(credentials, homeServerConnectionConfig, loginType)
val overriddenUrl = credentials.discoveryInformation?.homeServer?.baseURL
// remove trailing "/"
?.trim { it == '/' }
?.takeIf { it.isNotBlank() }
// It can be the same value, so in this case, do not check again the validity
?.takeIf { it != homeServerConnectionConfig.homeServerUriBase.toString() }
?.also { Timber.d("Overriding homeserver url to $it (will check if valid)") }
?.let { Uri.parse(it) }
?.takeIf {
// Validate the URL, if the configuration is wrong server side, do not override
tryOrNull {
isValidClientServerApiTask.execute(
IsValidClientServerApiTask.Params(
homeServerConnectionConfig.copy(homeServerUriBase = it)
)
)
.also { Timber.d("Overriding homeserver url: $it") }
} ?: true // In case of other error (no network, etc.), consider it is valid...
}
val sessionParams = SessionParams(
credentials = credentials,
homeServerConnectionConfig = homeServerConnectionConfig.copy(
homeServerUriBase = overriddenUrl ?: homeServerConnectionConfig.homeServerUriBase,
identityServerUri = credentials.discoveryInformation?.identityServer?.baseURL
// remove trailing "/"
?.trim { it == '/' }
?.takeIf { it.isNotBlank() }
?.also { Timber.d("Overriding identity server url to $it") }
?.let { Uri.parse(it) }
?: homeServerConnectionConfig.identityServerUri
),
isTokenValid = true)
sessionParamsStore.save(sessionParams) sessionParamsStore.save(sessionParams)
return sessionManager.getOrCreateSession(sessionParams) return sessionManager.getOrCreateSession(sessionParams)
} }

View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.auth
import android.net.Uri
import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.internal.auth.login.LoginType
import timber.log.Timber
import javax.inject.Inject
internal interface SessionParamsCreator {
suspend fun create(
credentials: Credentials,
homeServerConnectionConfig: HomeServerConnectionConfig,
loginType: LoginType,
): SessionParams
}
internal class DefaultSessionParamsCreator @Inject constructor(
private val isValidClientServerApiTask: IsValidClientServerApiTask
) : SessionParamsCreator {
override suspend fun create(
credentials: Credentials,
homeServerConnectionConfig: HomeServerConnectionConfig,
loginType: LoginType,
) = SessionParams(
credentials = credentials,
homeServerConnectionConfig = homeServerConnectionConfig.overrideWithCredentials(credentials),
isTokenValid = true,
loginType = loginType,
)
private suspend fun HomeServerConnectionConfig.overrideWithCredentials(credentials: Credentials) = copy(
homeServerUriBase = credentials.getHomeServerUri(this) ?: homeServerUriBase,
identityServerUri = credentials.getIdentityServerUri() ?: identityServerUri
)
private suspend fun Credentials.getHomeServerUri(homeServerConnectionConfig: HomeServerConnectionConfig) =
discoveryInformation?.homeServer?.baseURL
?.trim { it == '/' }
?.takeIf { it.isNotBlank() }
// It can be the same value, so in this case, do not check again the validity
?.takeIf { it != homeServerConnectionConfig.homeServerUriBase.toString() }
?.also { Timber.d("Overriding homeserver url to $it (will check if valid)") }
?.let { Uri.parse(it) }
?.takeIf { validateUri(it, homeServerConnectionConfig) }
private suspend fun validateUri(uri: Uri, homeServerConnectionConfig: HomeServerConnectionConfig) =
// Validate the URL, if the configuration is wrong server side, do not override
tryOrNull {
performClientServerApiValidation(uri, homeServerConnectionConfig)
} ?: true // In case of other error (no network, etc.), consider it is valid...
private suspend fun performClientServerApiValidation(uri: Uri, homeServerConnectionConfig: HomeServerConnectionConfig) =
isValidClientServerApiTask.execute(
IsValidClientServerApiTask.Params(homeServerConnectionConfig.copy(homeServerUriBase = uri))
).also { Timber.d("Overriding homeserver url: $it") }
private fun Credentials.getIdentityServerUri() = discoveryInformation?.identityServer?.baseURL
?.trim { it == '/' }
?.takeIf { it.isNotBlank() }
?.also { Timber.d("Overriding identity server url to $it") }
?.let { Uri.parse(it) }
}

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.auth
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Test
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.internal.auth.login.LoginType
import org.matrix.android.sdk.test.fakes.internal.FakeSessionManager
import org.matrix.android.sdk.test.fakes.internal.auth.FakePendingSessionStore
import org.matrix.android.sdk.test.fakes.internal.auth.FakeSessionParamsCreator
import org.matrix.android.sdk.test.fakes.internal.auth.FakeSessionParamsStore
import org.matrix.android.sdk.test.fixtures.CredentialsFixture.aCredentials
import org.matrix.android.sdk.test.fixtures.SessionParamsFixture.aSessionParams
@ExperimentalCoroutinesApi
class DefaultSessionCreatorTest {
private val fakeSessionParamsStore = FakeSessionParamsStore()
private val fakeSessionManager = FakeSessionManager()
private val fakePendingSessionStore = FakePendingSessionStore()
private val fakeSessionParamsCreator = FakeSessionParamsCreator()
private val sessionCreator = DefaultSessionCreator(
fakeSessionParamsStore.instance,
fakeSessionManager.instance,
fakePendingSessionStore.instance,
fakeSessionParamsCreator.instance,
)
@Test
fun `when createSession, then session created`() = runBlockingTest {
val output = sessionCreator.createSession(credentials, homeServerConnectionConfig, LoginType.UNKNOWN)
fakePendingSessionStore.verifyPendingSessionDataCleared()
fakeSessionParamsCreator.verifyCreatedWithParameters(credentials, homeServerConnectionConfig, LoginType.UNKNOWN)
fakeSessionParamsStore.verifyParamsSaved(sessionParams)
fakeSessionManager.assertSessionCreatedWithParams(output, sessionParams)
}
companion object {
private val sessionParams = aSessionParams()
private val credentials = aCredentials()
private val homeServerConnectionConfig = HomeServerConnectionConfig.Builder().build()
}
}

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.auth
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Test
import org.matrix.android.sdk.internal.auth.login.LoginType
import org.matrix.android.sdk.test.fakes.internal.auth.FakeIsValidClientServerApiTask
@ExperimentalCoroutinesApi
class DefaultSessionParamsCreatorTest : DefaultSessionParamsCreatorTestBase() {
private val fakeIsValidClientServerApiTask = FakeIsValidClientServerApiTask()
private val sessionParamsCreator = DefaultSessionParamsCreator(fakeIsValidClientServerApiTask.instance)
@Test
fun `when create, then SessionParams created`() = runBlockingTest {
val output = sessionParamsCreator.create(credentials, homeServerConnectionConfig, LoginType.UNKNOWN)
assertExpectedSessionParams(output)
}
@Test
fun `given credentials contains homeServerUri, when create, then SessionParams created with validated credentials uri`() = runBlockingTest {
val output = sessionParamsCreator.create(credentialsWithHomeServer, homeServerConnectionConfig, LoginType.UNKNOWN)
fakeIsValidClientServerApiTask.verifyExecutionWithConfig(homeServerConnectionConfig.copy(homeServerUriBase = discoveryWithHomeServer.getHomeServerUri()))
assertExpectedSessionParamsWithHomeServer(output)
}
@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()
assertExpectedSessionParamsWithHomeServer(output)
}
@Test
fun `given credentials contains identityServerUri, when create, then SessionParams created with credentials uri`() = runBlockingTest {
val output = sessionParamsCreator.create(credentialsWithIdentityServer, homeServerConnectionConfig, LoginType.UNKNOWN)
assertExpectedSessionParamsWithIdentityServer(output)
}
}

View file

@ -0,0 +1,72 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.auth
import android.net.Uri
import org.amshove.kluent.shouldBeEqualTo
import org.matrix.android.sdk.api.auth.data.DiscoveryInformation
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
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.WellKnownBaseConfigFixture
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 homeServerConnectionConfig = HomeServerConnectionConfig.Builder().build()
protected fun assertExpectedSessionParams(sessionParams: SessionParams) {
sessionParams shouldBeEqualTo SessionParams(
credentials = credentials,
homeServerConnectionConfig = homeServerConnectionConfig,
isTokenValid = true,
loginType = LoginType.UNKNOWN,
)
}
protected fun assertExpectedSessionParamsWithHomeServer(sessionParams: SessionParams) {
sessionParams shouldBeEqualTo SessionParams(
credentials = credentialsWithHomeServer,
homeServerConnectionConfig = homeServerConnectionConfig.copy(homeServerUriBase = discoveryWithHomeServer.getHomeServerUri()),
isTokenValid = true,
loginType = LoginType.UNKNOWN,
)
}
protected fun assertExpectedSessionParamsWithIdentityServer(sessionParams: SessionParams) {
sessionParams shouldBeEqualTo SessionParams(
credentials = credentialsWithHomeServer,
homeServerConnectionConfig = homeServerConnectionConfig.copy(identityServerUri = discoveryWithIdentityServer.getIdentityServerUri()),
isTokenValid = true,
loginType = LoginType.UNKNOWN,
)
}
private fun DiscoveryInformation.getIdentityServerUri() = identityServer?.baseURL?.convertToUri()!!
protected fun DiscoveryInformation.getHomeServerUri() = homeServer?.baseURL?.convertToUri()!!
private fun String.convertToUri() = trim { it == '/' }
.takeIf { it.isNotBlank() }
.let { Uri.parse(it) }
}

View file

@ -17,11 +17,11 @@
package org.matrix.android.sdk.internal.auth.db package org.matrix.android.sdk.internal.auth.db
import org.junit.Test import org.junit.Test
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeSessionParamsMapperMoshi import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.nullSessionParams import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.nullSessionParams
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.nullSessionParamsEntity import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.nullSessionParamsEntity
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParams import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParams
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParamsEntity import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParamsEntity
class SessionParamsMapperTest { class SessionParamsMapperTest {

View file

@ -17,7 +17,7 @@
package org.matrix.android.sdk.internal.auth.db.migration package org.matrix.android.sdk.internal.auth.db.migration
import org.junit.Test import org.junit.Test
import org.matrix.android.sdk.test.fakes.auth.db.migration.Fake005MigrationRealm import org.matrix.android.sdk.test.fakes.internal.auth.db.migration.Fake005MigrationRealm
class MigrateAuthTo005Test { class MigrateAuthTo005Test {

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.test.fakes.api
import io.mockk.mockk
import org.matrix.android.sdk.api.session.Session
class FakeSession {
val instance: Session = mockk()
}

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.test.fakes.internal
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.amshove.kluent.shouldBeEqualTo
import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.internal.SessionManager
import org.matrix.android.sdk.test.fakes.api.FakeSession
internal class FakeSessionManager {
val instance: SessionManager = mockk()
init {
every { instance.getOrCreateSession(any()) } returns fakeSession.instance
}
fun assertSessionCreatedWithParams(session: Session, sessionParams: SessionParams) {
verify { instance.getOrCreateSession(sessionParams) }
session shouldBeEqualTo fakeSession.instance
}
companion object {
private val fakeSession = FakeSession()
}
}

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.test.fakes.internal.auth
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.internal.auth.IsValidClientServerApiTask
import org.matrix.android.sdk.internal.auth.IsValidClientServerApiTask.Params
internal class FakeIsValidClientServerApiTask {
init {
coEvery { instance.execute(any()) } returns true
}
val instance: IsValidClientServerApiTask = mockk()
fun verifyExecutionWithConfig(config: HomeServerConnectionConfig) {
coVerify { instance.execute(Params(config)) }
}
fun verifyNoExecution() {
coVerify(inverse = true) { instance.execute(any()) }
}
}

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.test.fakes.internal.auth
import io.mockk.coJustRun
import io.mockk.coVerify
import io.mockk.mockk
import org.matrix.android.sdk.internal.auth.PendingSessionStore
internal class FakePendingSessionStore {
val instance: PendingSessionStore = mockk()
init {
coJustRun { instance.delete() }
}
fun verifyPendingSessionDataCleared() {
coVerify { instance.delete() }
}
}

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.test.fakes.internal.auth
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.internal.auth.SessionParamsCreator
import org.matrix.android.sdk.internal.auth.login.LoginType
import org.matrix.android.sdk.test.fixtures.SessionParamsFixture.aSessionParams
internal class FakeSessionParamsCreator {
val instance: SessionParamsCreator = mockk()
init {
coEvery { instance.create(any(), any(), any()) } returns sessionParams
}
fun verifyCreatedWithParameters(
credentials: Credentials,
homeServerConnectionConfig: HomeServerConnectionConfig,
loginType: LoginType,
) {
coVerify { instance.create(credentials, homeServerConnectionConfig, loginType) }
}
companion object {
val sessionParams = aSessionParams()
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.test.fakes.internal.auth
import io.mockk.coJustRun
import io.mockk.coVerify
import io.mockk.mockk
import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.internal.auth.SessionParamsStore
internal class FakeSessionParamsStore {
val instance: SessionParamsStore = mockk()
init {
coJustRun { instance.save(any()) }
}
fun verifyParamsSaved(sessionParams: SessionParams) {
coVerify { instance.save(sessionParams) }
}
}

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.matrix.android.sdk.test.fakes.auth.db.migration package org.matrix.android.sdk.test.fakes.internal.auth.db.migration
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk

View file

@ -14,14 +14,14 @@
* limitations under the License. * limitations under the License.
*/ */
package org.matrix.android.sdk.test.fakes.auth.db.sessionparams package org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams
import com.squareup.moshi.JsonAdapter import com.squareup.moshi.JsonAdapter
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParams import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParams
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParamsEntity import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParamsEntity
import org.matrix.android.sdk.test.fixtures.CredentialsFixture.aCredentials import org.matrix.android.sdk.test.fixtures.CredentialsFixture.aCredentials
internal class FakeCredentialsJsonAdapter { internal class FakeCredentialsJsonAdapter {

View file

@ -14,14 +14,14 @@
* limitations under the License. * limitations under the License.
*/ */
package org.matrix.android.sdk.test.fakes.auth.db.sessionparams package org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams
import com.squareup.moshi.JsonAdapter import com.squareup.moshi.JsonAdapter
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParams import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParams
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParamsEntity import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParamsEntity
internal class FakeHomeServerConnectionConfigJsonAdapter { internal class FakeHomeServerConnectionConfigJsonAdapter {

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.matrix.android.sdk.test.fakes.auth.db.sessionparams package org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams
import com.squareup.moshi.Moshi import com.squareup.moshi.Moshi
import io.mockk.every import io.mockk.every
@ -27,10 +27,10 @@ import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.api.auth.data.sessionId import org.matrix.android.sdk.api.auth.data.sessionId
import org.matrix.android.sdk.internal.auth.db.SessionParamsEntity import org.matrix.android.sdk.internal.auth.db.SessionParamsEntity
import org.matrix.android.sdk.internal.auth.login.LoginType import org.matrix.android.sdk.internal.auth.login.LoginType
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeCredentialsJsonAdapter.Companion.CREDENTIALS_JSON import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeCredentialsJsonAdapter.Companion.CREDENTIALS_JSON
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeCredentialsJsonAdapter.Companion.credentials import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeCredentialsJsonAdapter.Companion.credentials
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeHomeServerConnectionConfigJsonAdapter.Companion.HOME_SERVER_CONNECTION_CONFIG_JSON import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeHomeServerConnectionConfigJsonAdapter.Companion.HOME_SERVER_CONNECTION_CONFIG_JSON
import org.matrix.android.sdk.test.fakes.auth.db.sessionparams.FakeHomeServerConnectionConfigJsonAdapter.Companion.homeServerConnectionConfig import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeHomeServerConnectionConfigJsonAdapter.Companion.homeServerConnectionConfig
import org.matrix.android.sdk.test.fixtures.SessionParamsEntityFixture.aSessionParamsEntity import org.matrix.android.sdk.test.fixtures.SessionParamsEntityFixture.aSessionParamsEntity
import org.matrix.android.sdk.test.fixtures.SessionParamsFixture.aSessionParams import org.matrix.android.sdk.test.fixtures.SessionParamsFixture.aSessionParams

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.test.fixtures
import org.matrix.android.sdk.api.auth.data.DiscoveryInformation
import org.matrix.android.sdk.api.auth.data.WellKnownBaseConfig
object DiscoveryInformationFixture {
fun aDiscoveryInformation(
homeServer: WellKnownBaseConfig? = null,
identityServer: WellKnownBaseConfig? = null,
) = DiscoveryInformation(
homeServer,
identityServer
)
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.test.fixtures
import org.matrix.android.sdk.api.auth.data.WellKnownBaseConfig
object WellKnownBaseConfigFixture {
fun aWellKnownBaseConfig(
baseUrl: String? = null,
) = WellKnownBaseConfig(
baseUrl,
)
}