-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: bulletproofing crypto box to cc migration (WPB-14250) (#3123)
* feat: cleaning all data if failure * feat: cleaning all data if failure * feat: clean up code * feat: clean up code * chore: add plan b, logout user * chore: add plan b, logout user, cleanup code * chore: cleanup code * chore: cleanup code * chore: cleanup code detekt * chore: cleanup code detekt * chore: remove exception for testing * chore: tests for new branches * chore: tests for new branches * chore: solve layer issue * chore: more test covereage * chore: layering * chore: solve missing reference * fix: deadlock while cleanup * fix: tests * fix: tests detekt
- Loading branch information
1 parent
7440f44
commit a307ae3
Showing
15 changed files
with
340 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...rc/commonMain/kotlin/com/wire/kalium/logic/data/client/ProteusMigrationRecoveryHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.data.client | ||
|
||
import com.wire.kalium.logic.data.logout.LogoutReason | ||
|
||
/** | ||
* Handles the migration error of a proteus client storage from CryptoBox to CoreCrypto. | ||
* It will perform a logout, using [LogoutReason.MIGRATION_TO_CC_FAILED] as the reason. | ||
* | ||
* This achieves that the client data is cleared and the user is logged out without losing content. | ||
*/ | ||
interface ProteusMigrationRecoveryHandler { | ||
suspend fun clearClientData(clearLocalFiles: suspend () -> Unit) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...onMain/kotlin/com/wire/kalium/logic/feature/client/ProteusMigrationRecoveryHandlerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.feature.client | ||
|
||
import com.wire.kalium.logic.data.client.ProteusMigrationRecoveryHandler | ||
import com.wire.kalium.logic.data.logout.LogoutReason | ||
import com.wire.kalium.logic.feature.auth.LogoutUseCase | ||
import com.wire.kalium.logic.kaliumLogger | ||
|
||
internal class ProteusMigrationRecoveryHandlerImpl( | ||
private val logoutUseCase: Lazy<LogoutUseCase> | ||
) : ProteusMigrationRecoveryHandler { | ||
|
||
/** | ||
* Handles the migration error of a proteus client storage from CryptoBox to CoreCrypto. | ||
* It will perform a logout, using [LogoutReason.MIGRATION_TO_CC_FAILED] as the reason. | ||
* | ||
* This achieves that the client data is cleared and the user is logged out without losing content. | ||
*/ | ||
@Suppress("TooGenericExceptionCaught") | ||
override suspend fun clearClientData(clearLocalFiles: suspend () -> Unit) { | ||
try { | ||
kaliumLogger.withTextTag(TAG).i("Starting the recovery from failed Proteus storage migration") | ||
clearLocalFiles() | ||
logoutUseCase.value(LogoutReason.MIGRATION_TO_CC_FAILED, true) | ||
} catch (e: Exception) { | ||
kaliumLogger.withTextTag(TAG).e("Fatal, error while clearing client data: $e") | ||
throw e | ||
} finally { | ||
kaliumLogger.withTextTag(TAG).i("Finished the recovery from failed Proteus storage migration") | ||
} | ||
} | ||
|
||
private companion object { | ||
const val TAG = "ProteusMigrationRecoveryHandler" | ||
} | ||
} |
Oops, something went wrong.