From 7e20484c30e827be7a62d7a55221822851308e0a Mon Sep 17 00:00:00 2001 From: Yamil Medina Date: Thu, 28 Nov 2024 11:22:47 -0300 Subject: [PATCH] Commit with unresolved merge conflicts --- .../ProteusClientCoreCryptoImpl.kt | 23 +++++++++++++ .../exceptions/ProteusException.kt | 4 +++ .../kalium/logic/data/logout/LogoutReason.kt | 4 +++ .../logic/feature/auth/LogoutUseCaseTest.kt | 32 +++++++++++++++++++ .../data/client/ProteusClientProviderTest.kt | 26 +++++++++++++++ .../ProteusMigrationRecoveryHandlerTest.kt | 12 +++++++ .../kalium/persistence/model/LogoutReason.kt | 6 ++++ 7 files changed, 107 insertions(+) diff --git a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt index fdc9bc2b69c..1d4fa37e68a 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt @@ -191,7 +191,10 @@ class ProteusClientCoreCryptoImpl private constructor( throw ProteusException( message = e.message, code = ProteusException.fromProteusCode(coreCrypto.proteusLastErrorCode().toInt()), +<<<<<<< HEAD intCode = coreCrypto.proteusLastErrorCode().toInt(), +======= +>>>>>>> c5c2468502 (chore: bulletproofing crypto box to cc migration (WPB-14250) (🍒4.6) (#3136)) cause = e.cause ) } catch (e: Exception) { @@ -218,5 +221,25 @@ class ProteusClientCoreCryptoImpl private constructor( throw ProteusStorageMigrationException("Failed to migrate from crypto box at $rootDir", exception) } } + + @Suppress("TooGenericExceptionCaught") + private suspend fun migrateFromCryptoBoxIfNecessary(coreCrypto: CoreCrypto, rootDir: String) { + try { + if (cryptoBoxFilesExists(File(rootDir))) { + kaliumLogger.i("migrating from crypto box at: $rootDir") + coreCrypto.proteusCryptoboxMigrate(rootDir) + kaliumLogger.i("migration successful") + + if (deleteCryptoBoxFiles(rootDir)) { + kaliumLogger.i("successfully deleted old crypto box files") + } else { + kaliumLogger.e("Failed to deleted old crypto box files at $rootDir") + } + } + } catch (exception: Exception) { + kaliumLogger.e("Failed to migrate from crypto box to core crypto, exception: $exception") + throw ProteusStorageMigrationException("Failed to migrate from crypto box at $rootDir", exception) + } + } } } diff --git a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/exceptions/ProteusException.kt b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/exceptions/ProteusException.kt index 547d0deefa9..f308900bcd5 100644 --- a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/exceptions/ProteusException.kt +++ b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/exceptions/ProteusException.kt @@ -18,7 +18,11 @@ package com.wire.kalium.cryptography.exceptions +<<<<<<< HEAD open class ProteusException(message: String?, val code: Code, val intCode: Int?, cause: Throwable? = null) : Exception(message, cause) { +======= +open class ProteusException(message: String?, val code: Code, cause: Throwable? = null) : Exception(message, cause) { +>>>>>>> c5c2468502 (chore: bulletproofing crypto box to cc migration (WPB-14250) (🍒4.6) (#3136)) constructor(message: String?, code: Int, cause: Throwable? = null) : this( message, diff --git a/data/src/commonMain/kotlin/com/wire/kalium/logic/data/logout/LogoutReason.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/logout/LogoutReason.kt index 3cfd14e6525..baa1a0463de 100644 --- a/data/src/commonMain/kotlin/com/wire/kalium/logic/data/logout/LogoutReason.kt +++ b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/logout/LogoutReason.kt @@ -52,5 +52,9 @@ enum class LogoutReason { * The migration to CC failed. * This will trigger a cleanup of the local client data and prepare for a fresh start without losing data. */ +<<<<<<< HEAD:data/src/commonMain/kotlin/com/wire/kalium/logic/data/logout/LogoutReason.kt MIGRATION_TO_CC_FAILED +======= + MIGRATION_TO_CC_FAILED; +>>>>>>> c5c2468502 (chore: bulletproofing crypto box to cc migration (WPB-14250) (🍒4.6) (#3136)):logic/src/commonMain/kotlin/com/wire/kalium/logic/data/logout/LogoutReason.kt } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/auth/LogoutUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/auth/LogoutUseCaseTest.kt index f443b8a5914..7e2118ebd1f 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/auth/LogoutUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/auth/LogoutUseCaseTest.kt @@ -374,6 +374,38 @@ class LogoutUseCaseTest { }.wasInvoked(exactly = once) } + @Test + fun givenAMigrationFailedLogout_whenLoggingOut_thenExecuteAllRequiredActions() = runTest { + val reason = LogoutReason.MIGRATION_TO_CC_FAILED + val (arrangement, logoutUseCase) = Arrangement() + .withLogoutResult(Either.Right(Unit)) + .withSessionLogoutResult(Either.Right(Unit)) + .withAllValidSessionsResult(Either.Right(listOf(Arrangement.VALID_ACCOUNT_INFO))) + .withDeregisterTokenResult(DeregisterTokenUseCase.Result.Success) + .withClearCurrentClientIdResult(Either.Right(Unit)) + .withClearRetainedClientIdResult(Either.Right(Unit)) + .withUserSessionScopeGetResult(null) + .withFirebaseTokenUpdate() + .withNoOngoingCalls() + .arrange() + + logoutUseCase.invoke(reason) + arrangement.globalTestScope.advanceUntilIdle() + + verify(arrangement.clearClientDataUseCase) + .coroutine { invoke() } + .wasInvoked(exactly = once) + verify(arrangement.logoutRepository) + .coroutine { clearClientRelatedLocalMetadata() } + .wasInvoked(exactly = once) + verify(arrangement.clientRepository) + .coroutine { clearRetainedClientId() } + .wasInvoked(exactly = once) + verify(arrangement.pushTokenRepository) + .coroutine { setUpdateFirebaseTokenFlag(true) } + .wasInvoked(exactly = once) + } + private class Arrangement { @Mock val logoutRepository = mock(LogoutRepository::class) diff --git a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/data/client/ProteusClientProviderTest.kt b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/data/client/ProteusClientProviderTest.kt index 8d4c8caa2f5..452c212d908 100644 --- a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/data/client/ProteusClientProviderTest.kt +++ b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/data/client/ProteusClientProviderTest.kt @@ -8,11 +8,20 @@ import com.wire.kalium.util.FileUtil import com.wire.kalium.util.KaliumDispatcherImpl import io.mockative.Mock import io.mockative.any +<<<<<<< HEAD import io.mockative.coVerify import io.mockative.every import io.mockative.mock import io.mockative.once import kotlinx.coroutines.test.runTest +======= +import io.mockative.mock +import io.mockative.once +import io.mockative.verify +import io.mockative.given +import kotlinx.coroutines.test.runTest +import org.junit.Ignore +>>>>>>> c5c2468502 (chore: bulletproofing crypto box to cc migration (WPB-14250) (🍒4.6) (#3136)) import org.junit.Test import java.nio.file.Paths import kotlin.io.path.createDirectory @@ -21,6 +30,10 @@ import kotlin.io.path.exists class ProteusClientProviderTest { +<<<<<<< HEAD +======= + @Ignore("Old version of the testing library, wont fix") +>>>>>>> c5c2468502 (chore: bulletproofing crypto box to cc migration (WPB-14250) (🍒4.6) (#3136)) @Test fun givenGettingOrCreatingAProteusClient_whenMigrationPerformedAndFails_thenCatchErrorAndStartRecovery() = runTest { // given @@ -32,7 +45,13 @@ class ProteusClientProviderTest { try { proteusClientProvider.getOrCreate() } catch (e: ProteusStorageMigrationException) { +<<<<<<< HEAD coVerify { arrangement.proteusMigrationRecoveryHandler.clearClientData(any()) }.wasInvoked(once) +======= + verify(arrangement.proteusMigrationRecoveryHandler) + .coroutine { clearClientData({}) } + .wasInvoked(exactly = once) +>>>>>>> c5c2468502 (chore: bulletproofing crypto box to cc migration (WPB-14250) (🍒4.6) (#3136)) } } @@ -45,7 +64,14 @@ class ProteusClientProviderTest { val proteusMigrationRecoveryHandler = mock(ProteusMigrationRecoveryHandler::class) init { +<<<<<<< HEAD every { passphraseStorage.getPassphrase(any()) }.returns("passphrase") +======= + given(passphraseStorage) + .suspendFunction(passphraseStorage::getPassphrase) + .whenInvokedWith(any()) + .thenReturn("passphrase") +>>>>>>> c5c2468502 (chore: bulletproofing crypto box to cc migration (WPB-14250) (🍒4.6) (#3136)) } /** diff --git a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/client/ProteusMigrationRecoveryHandlerTest.kt b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/client/ProteusMigrationRecoveryHandlerTest.kt index 7a52607adb6..6162f50abd1 100644 --- a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/client/ProteusMigrationRecoveryHandlerTest.kt +++ b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/client/ProteusMigrationRecoveryHandlerTest.kt @@ -3,9 +3,15 @@ package com.wire.kalium.logic.feature.client import com.wire.kalium.logic.data.logout.LogoutReason import com.wire.kalium.logic.feature.auth.LogoutUseCase import io.mockative.Mock +<<<<<<< HEAD import io.mockative.coVerify import io.mockative.mock import io.mockative.once +======= +import io.mockative.mock +import io.mockative.once +import io.mockative.verify +>>>>>>> c5c2468502 (chore: bulletproofing crypto box to cc migration (WPB-14250) (🍒4.6) (#3136)) import kotlinx.coroutines.test.runTest import org.junit.Test @@ -21,7 +27,13 @@ class ProteusMigrationRecoveryHandlerTest { proteusMigrationRecoveryHandler.clearClientData(clearLocalFiles) // then +<<<<<<< HEAD coVerify { arrangement.logoutUseCase(LogoutReason.MIGRATION_TO_CC_FAILED, true) }.wasInvoked(once) +======= + verify(arrangement.logoutUseCase) + .coroutine { invoke(LogoutReason.MIGRATION_TO_CC_FAILED, true) } + .wasInvoked(exactly = once) +>>>>>>> c5c2468502 (chore: bulletproofing crypto box to cc migration (WPB-14250) (🍒4.6) (#3136)) } private class Arrangement { diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/model/LogoutReason.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/model/LogoutReason.kt index dc306760bab..dbf558d81cc 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/model/LogoutReason.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/model/LogoutReason.kt @@ -42,6 +42,12 @@ enum class LogoutReason { /** * The migration to CC failed. +<<<<<<< HEAD */ MIGRATION_TO_CC_FAILED +======= + * This will trigger a cleanup of the local client data and prepare for a fresh start without losing data. + */ + MIGRATION_TO_CC_FAILED; +>>>>>>> c5c2468502 (chore: bulletproofing crypto box to cc migration (WPB-14250) (🍒4.6) (#3136)) }