mirror of
https://github.com/bitwarden/android.git
synced 2025-12-11 04:39:19 -06:00
PM-19498: Update cipher migration logic (#4921)
This commit is contained in:
parent
94a91702cc
commit
693d9f18db
@ -474,15 +474,17 @@ class CipherManagerImpl(
|
||||
userId: String,
|
||||
cipherId: String,
|
||||
): Result<Cipher> =
|
||||
if (this.key == null) {
|
||||
vaultSdkSource
|
||||
.encryptCipher(userId = userId, cipherView = this)
|
||||
.flatMap {
|
||||
ciphersService.updateCipher(
|
||||
// We only migrate the cipher if the original cipher did not have a key and the
|
||||
// new cipher does. This means the SDK created the key and migration is required.
|
||||
if (it.key != null && this.key == null) {
|
||||
ciphersService
|
||||
.updateCipher(
|
||||
cipherId = cipherId,
|
||||
body = it.toEncryptedNetworkCipher(),
|
||||
)
|
||||
}
|
||||
.flatMap { response ->
|
||||
when (response) {
|
||||
is UpdateCipherResponseJson.Invalid -> {
|
||||
@ -490,13 +492,17 @@ class CipherManagerImpl(
|
||||
}
|
||||
|
||||
is UpdateCipherResponseJson.Success -> {
|
||||
vaultDiskSource.saveCipher(userId = userId, cipher = response.cipher)
|
||||
vaultDiskSource.saveCipher(
|
||||
userId = userId,
|
||||
cipher = response.cipher,
|
||||
)
|
||||
response.cipher.toEncryptedSdkCipher().asSuccess()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vaultSdkSource.encryptCipher(userId = userId, cipherView = this)
|
||||
it.asSuccess()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun migrateAttachments(
|
||||
|
||||
@ -1707,6 +1707,7 @@ class CipherManagerTest {
|
||||
|
||||
val attachmentId = "mockId-1"
|
||||
val cipher = mockk<Cipher> {
|
||||
every { key } returns "key"
|
||||
every { attachments } returns emptyList()
|
||||
every { id } returns "mockId-1"
|
||||
}
|
||||
@ -1747,6 +1748,7 @@ class CipherManagerTest {
|
||||
every { id } returns attachmentId
|
||||
}
|
||||
val cipher = mockk<Cipher> {
|
||||
every { key } returns "key"
|
||||
every { attachments } returns listOf(attachment)
|
||||
every { id } returns "mockId-1"
|
||||
}
|
||||
@ -1792,6 +1794,7 @@ class CipherManagerTest {
|
||||
every { id } returns attachmentId
|
||||
}
|
||||
val cipher = mockk<Cipher> {
|
||||
every { key } returns "key"
|
||||
every { attachments } returns listOf(attachment)
|
||||
every { id } returns "mockId-1"
|
||||
}
|
||||
@ -1839,6 +1842,7 @@ class CipherManagerTest {
|
||||
every { id } returns attachmentId
|
||||
}
|
||||
val cipher = mockk<Cipher> {
|
||||
every { key } returns "key"
|
||||
every { attachments } returns listOf(attachment)
|
||||
every { id } returns "mockId-1"
|
||||
}
|
||||
@ -1892,6 +1896,7 @@ class CipherManagerTest {
|
||||
every { id } returns attachmentId
|
||||
}
|
||||
val cipher = mockk<Cipher> {
|
||||
every { key } returns "key"
|
||||
every { attachments } returns listOf(attachment)
|
||||
every { id } returns "mockId-1"
|
||||
}
|
||||
@ -1967,6 +1972,7 @@ class CipherManagerTest {
|
||||
every { id } returns attachmentId
|
||||
}
|
||||
val cipher = mockk<Cipher> {
|
||||
every { key } returns "key"
|
||||
every { attachments } returns listOf(attachment)
|
||||
every { id } returns "mockId-1"
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user