SecureBackup: update matrix sdk module.

This commit is contained in:
Benoit Marty 2023-10-26 18:02:34 +02:00
parent 00d24ce4b1
commit 3a15b92eb6
17 changed files with 518 additions and 11 deletions

View file

@ -22,6 +22,7 @@ import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.core.SessionId
import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.api.createroom.CreateRoomParameters
import io.element.android.libraries.matrix.api.encryption.EncryptionService
import io.element.android.libraries.matrix.api.media.MatrixMediaLoader
import io.element.android.libraries.matrix.api.notification.NotificationService
import io.element.android.libraries.matrix.api.notificationsettings.NotificationSettingsService
@ -33,6 +34,7 @@ import io.element.android.libraries.matrix.api.roomlist.RoomListService
import io.element.android.libraries.matrix.api.user.MatrixSearchUserResults
import io.element.android.libraries.matrix.api.user.MatrixUser
import io.element.android.libraries.matrix.api.verification.SessionVerificationService
import io.element.android.libraries.matrix.test.encryption.FakeEncryptionService
import io.element.android.libraries.matrix.test.media.FakeMediaLoader
import io.element.android.libraries.matrix.test.notification.FakeNotificationService
import io.element.android.libraries.matrix.test.notificationsettings.FakeNotificationSettingsService
@ -55,6 +57,7 @@ class FakeMatrixClient(
private val notificationService: FakeNotificationService = FakeNotificationService(),
private val notificationSettingsService: FakeNotificationSettingsService = FakeNotificationSettingsService(),
private val syncService: FakeSyncService = FakeSyncService(),
private val encryptionService: FakeEncryptionService = FakeEncryptionService(),
private val accountManagementUrlString: Result<String?> = Result.success(null),
) : MatrixClient {
@ -124,9 +127,11 @@ class FakeMatrixClient(
override suspend fun clearCache() {
}
override suspend fun logout(): String? {
override suspend fun logout(ignoreSdkError: Boolean): String? {
delay(100)
logoutFailure?.let { throw it }
if (ignoreSdkError.not()) {
logoutFailure?.let { throw it }
}
return null
}
@ -173,6 +178,7 @@ class FakeMatrixClient(
override fun notificationService(): NotificationService = notificationService
override fun notificationSettingsService(): NotificationSettingsService = notificationSettingsService
override fun encryptionService(): EncryptionService = encryptionService
override fun roomMembershipObserver(): RoomMembershipObserver {
return RoomMembershipObserver()

View file

@ -72,3 +72,5 @@ const val A_FAILURE_REASON = "There has been a failure"
val A_THROWABLE = Throwable(A_FAILURE_REASON)
val AN_EXCEPTION = Exception(A_FAILURE_REASON)
const val A_RECOVERY_KEY = "1234 5678"

View file

@ -0,0 +1,95 @@
/*
* Copyright (c) 2023 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 io.element.android.libraries.matrix.test.encryption
import io.element.android.libraries.matrix.api.encryption.BackupState
import io.element.android.libraries.matrix.api.encryption.BackupUploadState
import io.element.android.libraries.matrix.api.encryption.EnableRecoveryProgress
import io.element.android.libraries.matrix.api.encryption.EncryptionService
import io.element.android.libraries.matrix.api.encryption.RecoveryState
import io.element.android.tests.testutils.simulateLongTask
import kotlinx.coroutines.flow.MutableStateFlow
class FakeEncryptionService : EncryptionService {
private var disableRecoveryFailure: Exception? = null
override val backupStateStateFlow: MutableStateFlow<BackupState> = MutableStateFlow(BackupState.UNKNOWN)
override val recoveryStateStateFlow: MutableStateFlow<RecoveryState> = MutableStateFlow(RecoveryState.UNKNOWN)
override val enableRecoveryProgressStateFlow: MutableStateFlow<EnableRecoveryProgress> = MutableStateFlow(EnableRecoveryProgress.Unknown)
override val backupUploadStateStateFlow: MutableStateFlow<BackupUploadState> = MutableStateFlow(BackupUploadState.Unknown)
private var fixRecoveryIssuesFailure: Exception? = null
override suspend fun enableBackups(): Result<Unit> = simulateLongTask {
return Result.success(Unit)
}
fun givenDisableRecoveryFailure(exception: Exception) {
disableRecoveryFailure = exception
}
fun givenFixRecoveryIssuesFailure(exception: Exception?) {
fixRecoveryIssuesFailure = exception
}
override suspend fun disableRecovery(): Result<Unit> = simulateLongTask {
disableRecoveryFailure?.let { return Result.failure(it) }
return Result.success(Unit)
}
override suspend fun fixRecoveryIssues(recoveryKey: String): Result<Unit> = simulateLongTask {
fixRecoveryIssuesFailure?.let { return Result.failure(it) }
return Result.success(Unit)
}
private var isLastDevice = false
fun givenIsLastDevice(isLastDevice: Boolean) {
this.isLastDevice = isLastDevice
}
override suspend fun isLastDevice(): Result<Boolean> {
return Result.success(isLastDevice)
}
override suspend fun resetRecoveryKey(): Result<String> = simulateLongTask {
return Result.success(fakeRecoveryKey)
}
override suspend fun enableRecovery(waitForBackupsToUpload: Boolean): Result<Unit> = simulateLongTask {
return Result.success(Unit)
}
override suspend fun waitForBackupUploadSteadyState(): Result<Unit> {
return Result.success(Unit)
}
suspend fun emitBackupUploadState(state: BackupUploadState) {
backupUploadStateStateFlow.emit(state)
}
suspend fun emitBackupState(state: BackupState) {
backupStateStateFlow.emit(state)
}
suspend fun emitEnableRecoveryProgress(state: EnableRecoveryProgress) {
enableRecoveryProgressStateFlow.emit(state)
}
companion object {
const val fakeRecoveryKey = "fake"
}
}