From 6064cfd5c132ab256c3ae83ea6d0ad7d05c93a55 Mon Sep 17 00:00:00 2001 From: valere Date: Tue, 7 Feb 2023 12:58:31 +0100 Subject: [PATCH] Fix tests --- .../verification/SasTransactionState.kt | 46 +++++++ .../verification/VerificationTxState.kt | 118 ------------------ .../devices/v2/DevicesViewModelTest.kt | 9 +- 3 files changed, 51 insertions(+), 122 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/SasTransactionState.kt delete mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/VerificationTxState.kt diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/SasTransactionState.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/SasTransactionState.kt new file mode 100644 index 0000000000..f13b114516 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/SasTransactionState.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2023 The Matrix.org Foundation C.I.C. + * + * 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.api.session.crypto.verification + +sealed class SasTransactionState { + + object None : SasTransactionState() + + // I wend a start + object SasStarted : SasTransactionState() + + // I received a start and it was accepted + object SasAccepted : SasTransactionState() + + // I received an accept and sent my key + object SasKeySent : SasTransactionState() + + // Keys exchanged and code ready to be shared + object SasShortCodeReady : SasTransactionState() + + // I received the other Mac, but might have not yet confirmed the short code + // at that time (other side already confirmed) + data class SasMacReceived(val codeConfirmed: Boolean) : SasTransactionState() + + // I confirmed the code and sent my mac + object SasMacSent : SasTransactionState() + + // I am done, waiting for other Done + data class Done(val otherDone: Boolean) : SasTransactionState() + + data class Cancelled(val cancelCode: CancelCode, val byMe: Boolean) : SasTransactionState() +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/VerificationTxState.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/VerificationTxState.kt deleted file mode 100644 index 39ab125b5f..0000000000 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/VerificationTxState.kt +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2020 The Matrix.org Foundation C.I.C. - * - * 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.api.session.crypto.verification - -sealed class SasTransactionState { - - object None : SasTransactionState() - - // I wend a start - object SasStarted : SasTransactionState() - - // I received a start and it was accepted - object SasAccepted : SasTransactionState() - - // I received an accept and sent my key - object SasKeySent : SasTransactionState() - - // Keys exchanged and code ready to be shared - object SasShortCodeReady : SasTransactionState() - - // I received the other Mac, but might have not yet confirmed the short code - // at that time (other side already confirmed) - data class SasMacReceived(val codeConfirmed: Boolean) : SasTransactionState() - - // I confirmed the code and sent my mac - object SasMacSent : SasTransactionState() - - // I am done, waiting for other Done - data class Done(val otherDone: Boolean) : SasTransactionState() - - data class Cancelled(val cancelCode: CancelCode, val byMe: Boolean) : SasTransactionState() -} - -sealed class VerificationTxState { - /** - * Uninitialized state. - */ - object None : VerificationTxState() - - /** - * Specific for SAS. - */ - abstract class VerificationSasTxState : VerificationTxState() - -// object SendingStart : VerificationSasTxState() -// object Started : VerificationSasTxState() -// object OnStarted : VerificationSasTxState() -// object SendingAccept : VerificationSasTxState() -// object Accepted : VerificationSasTxState() -// object OnAccepted : VerificationSasTxState() -// object SendingKey : VerificationSasTxState() -// object KeySent : VerificationSasTxState() -// object OnKeyReceived : VerificationSasTxState() -// object ShortCodeReady : VerificationSasTxState() -// object ShortCodeAccepted : VerificationSasTxState() -// object SendingMac : VerificationSasTxState() -// object MacSent : VerificationSasTxState() -// object Verifying : VerificationSasTxState() - -// // I wend a start -// object SasStarted : VerificationSasTxState() -// -// // I received a start and it was accepted -// object SasAccepted : VerificationSasTxState() -// -// // I received an accept and sent my key -// object SasKeySent : VerificationSasTxState() -// -// // Keys exchanged and code ready to be shared -// object SasShortCodeReady : VerificationSasTxState() -// -// // I received the other Mac, but might have not yet confirmed the short code -// // at that time (other side already confirmed) -// data class SasMacReceived(val codeConfirmed: Boolean) : VerificationSasTxState() -// -// // I confirmed the code and sent my mac -// object SasMacSent : VerificationSasTxState() - - // I am done, waiting for other Done - data class Done(val otherDone: Boolean) : VerificationSasTxState() - - /** - * Specific for QR code. - */ -// abstract class VerificationQrTxState : VerificationTxState() -// -// /** -// * Will be used to ask the user if the other user has correctly scanned. -// */ -// object QrScannedByOther : VerificationQrTxState() -// object WaitingOtherReciprocateConfirm : VerificationQrTxState() - - /** - * Terminal states. - */ - abstract class TerminalTxState : VerificationTxState() - - object Verified : TerminalTxState() - - /** - * Cancelled by me or by other. - */ - data class Cancelled(val cancelCode: CancelCode, val byMe: Boolean) : TerminalTxState() -} diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt index 3d91bdd7a3..c2a14d8c39 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt @@ -42,6 +42,7 @@ import io.mockk.mockk import io.mockk.mockkStatic import io.mockk.runs import io.mockk.unmockkAll +import io.mockk.verify import io.mockk.verifyAll import kotlinx.coroutines.flow.flowOf import org.amshove.kluent.shouldBeEqualTo @@ -55,7 +56,6 @@ 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.RoomEncryptionTrustLevel import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction -import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState import org.matrix.android.sdk.api.session.uia.DefaultBaseAuth private const val A_CURRENT_DEVICE_ID = "current-device-id" @@ -78,9 +78,8 @@ class DevicesViewModelTest { private val fakeRefreshDevicesUseCase = mockk(relaxUnitFun = true) private val fakeVectorPreferences = FakeVectorPreferences() private val toggleIpAddressVisibilityUseCase = mockk() - private val verifiedTransaction = mockk().apply { - every { state } returns VerificationTxState.Verified + every { isSuccessful() } returns true } private fun createViewModel(): DevicesViewModel { @@ -115,7 +114,9 @@ class DevicesViewModelTest { return fakeActiveSessionHolder .fakeSession .fakeCryptoService - .fakeVerificationService + .fakeVerificationService.also { + it.givenEventFlow() + } } @After