mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 04:52:00 +03:00
Unit tests for GetCurrentSessionCrossSigningInfoUseCase
This commit is contained in:
parent
3f30cf0bee
commit
38a04c3655
4 changed files with 99 additions and 2 deletions
|
@ -19,7 +19,6 @@ package im.vector.app.features.settings.devices
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
// TODO add unit tests
|
|
||||||
class GetCurrentSessionCrossSigningInfoUseCase @Inject constructor(
|
class GetCurrentSessionCrossSigningInfoUseCase @Inject constructor(
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
private val activeSessionHolder: ActiveSessionHolder,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -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 im.vector.app.features.settings.devices
|
||||||
|
|
||||||
|
import im.vector.app.test.fakes.FakeActiveSessionHolder
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.mockk
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.amshove.kluent.shouldBeEqualTo
|
||||||
|
import org.junit.Test
|
||||||
|
import org.matrix.android.sdk.api.auth.data.SessionParams
|
||||||
|
|
||||||
|
private const val A_DEVICE_ID = "device-id"
|
||||||
|
|
||||||
|
class GetCurrentSessionCrossSigningInfoUseCaseTest {
|
||||||
|
|
||||||
|
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
|
||||||
|
|
||||||
|
private val getCurrentSessionCrossSigningInfoUseCase = GetCurrentSessionCrossSigningInfoUseCase(
|
||||||
|
activeSessionHolder = fakeActiveSessionHolder.instance
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given the active session when getting cross signing info then the result is correct`() = runTest {
|
||||||
|
val sessionParams = mockk<SessionParams>()
|
||||||
|
every { sessionParams.deviceId } returns A_DEVICE_ID
|
||||||
|
fakeActiveSessionHolder.fakeSession.givenSessionParams(sessionParams)
|
||||||
|
val isCrossSigningInitialized = true
|
||||||
|
fakeActiveSessionHolder.fakeSession
|
||||||
|
.fakeCryptoService
|
||||||
|
.fakeCrossSigningService
|
||||||
|
.givenIsCrossSigningInitializedReturns(isCrossSigningInitialized)
|
||||||
|
val isCrossSigningVerified = true
|
||||||
|
fakeActiveSessionHolder.fakeSession
|
||||||
|
.fakeCryptoService
|
||||||
|
.fakeCrossSigningService
|
||||||
|
.givenIsCrossSigningVerifiedReturns(isCrossSigningVerified)
|
||||||
|
val expectedResult = CurrentSessionCrossSigningInfo(
|
||||||
|
deviceId = A_DEVICE_ID,
|
||||||
|
isCrossSigningInitialized = isCrossSigningInitialized,
|
||||||
|
isCrossSigningVerified = isCrossSigningVerified
|
||||||
|
)
|
||||||
|
|
||||||
|
val result = getCurrentSessionCrossSigningInfoUseCase.execute()
|
||||||
|
|
||||||
|
result shouldBeEqualTo expectedResult
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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 im.vector.app.test.fakes
|
||||||
|
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.mockk
|
||||||
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.CrossSigningService
|
||||||
|
|
||||||
|
class FakeCrossSigningService : CrossSigningService by mockk() {
|
||||||
|
|
||||||
|
fun givenIsCrossSigningInitializedReturns(isInitialized: Boolean) {
|
||||||
|
every { isCrossSigningInitialized() } returns isInitialized
|
||||||
|
}
|
||||||
|
|
||||||
|
fun givenIsCrossSigningVerifiedReturns(isVerified: Boolean) {
|
||||||
|
every { isCrossSigningVerified() } returns isVerified
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,13 +23,17 @@ import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
||||||
import org.matrix.android.sdk.api.util.Optional
|
import org.matrix.android.sdk.api.util.Optional
|
||||||
|
|
||||||
class FakeCryptoService : CryptoService by mockk() {
|
class FakeCryptoService(
|
||||||
|
val fakeCrossSigningService: FakeCrossSigningService = FakeCrossSigningService()
|
||||||
|
) : CryptoService by mockk() {
|
||||||
|
|
||||||
var roomKeysExport = ByteArray(size = 1)
|
var roomKeysExport = ByteArray(size = 1)
|
||||||
var cryptoDeviceInfos = mutableMapOf<String, CryptoDeviceInfo>()
|
var cryptoDeviceInfos = mutableMapOf<String, CryptoDeviceInfo>()
|
||||||
var cryptoDeviceInfoWithIdLiveData: MutableLiveData<Optional<CryptoDeviceInfo>> = MutableLiveData()
|
var cryptoDeviceInfoWithIdLiveData: MutableLiveData<Optional<CryptoDeviceInfo>> = MutableLiveData()
|
||||||
var myDevicesInfoWithIdLiveData: MutableLiveData<Optional<DeviceInfo>> = MutableLiveData()
|
var myDevicesInfoWithIdLiveData: MutableLiveData<Optional<DeviceInfo>> = MutableLiveData()
|
||||||
|
|
||||||
|
override fun crossSigningService() = fakeCrossSigningService
|
||||||
|
|
||||||
override suspend fun exportRoomKeys(password: String) = roomKeysExport
|
override suspend fun exportRoomKeys(password: String) = roomKeysExport
|
||||||
|
|
||||||
override fun getLiveCryptoDeviceInfo() = MutableLiveData(cryptoDeviceInfos.values.toList())
|
override fun getLiveCryptoDeviceInfo() = MutableLiveData(cryptoDeviceInfos.values.toList())
|
||||||
|
|
Loading…
Reference in a new issue