Skip to content

Commit

Permalink
Commit with unresolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina authored and github-actions[bot] committed Nov 28, 2024
1 parent b60e679 commit 7e20484
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
}
}

Expand All @@ -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<String>())
.thenReturn("passphrase")
>>>>>>> c5c2468502 (chore: bulletproofing crypto box to cc migration (WPB-14250) (🍒4.6) (#3136))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 7e20484

Please sign in to comment.