Fix tests

This commit is contained in:
valere 2023-02-07 12:58:31 +01:00
parent a70e3c2533
commit 6064cfd5c1
3 changed files with 51 additions and 122 deletions

View File

@ -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()
}

View File

@ -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()
}

View File

@ -42,6 +42,7 @@ import io.mockk.mockk
import io.mockk.mockkStatic import io.mockk.mockkStatic
import io.mockk.runs import io.mockk.runs
import io.mockk.unmockkAll import io.mockk.unmockkAll
import io.mockk.verify
import io.mockk.verifyAll import io.mockk.verifyAll
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
import org.amshove.kluent.shouldBeEqualTo 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.DeviceInfo
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel 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.VerificationTransaction
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState
import org.matrix.android.sdk.api.session.uia.DefaultBaseAuth import org.matrix.android.sdk.api.session.uia.DefaultBaseAuth
private const val A_CURRENT_DEVICE_ID = "current-device-id" private const val A_CURRENT_DEVICE_ID = "current-device-id"
@ -78,9 +78,8 @@ class DevicesViewModelTest {
private val fakeRefreshDevicesUseCase = mockk<RefreshDevicesUseCase>(relaxUnitFun = true) private val fakeRefreshDevicesUseCase = mockk<RefreshDevicesUseCase>(relaxUnitFun = true)
private val fakeVectorPreferences = FakeVectorPreferences() private val fakeVectorPreferences = FakeVectorPreferences()
private val toggleIpAddressVisibilityUseCase = mockk<ToggleIpAddressVisibilityUseCase>() private val toggleIpAddressVisibilityUseCase = mockk<ToggleIpAddressVisibilityUseCase>()
private val verifiedTransaction = mockk<VerificationTransaction>().apply { private val verifiedTransaction = mockk<VerificationTransaction>().apply {
every { state } returns VerificationTxState.Verified every { isSuccessful() } returns true
} }
private fun createViewModel(): DevicesViewModel { private fun createViewModel(): DevicesViewModel {
@ -115,7 +114,9 @@ class DevicesViewModelTest {
return fakeActiveSessionHolder return fakeActiveSessionHolder
.fakeSession .fakeSession
.fakeCryptoService .fakeCryptoService
.fakeVerificationService .fakeVerificationService.also {
it.givenEventFlow()
}
} }
@After @After