mirror of
https://github.com/bitwarden/android.git
synced 2026-03-12 13:14:35 -05:00
[PM-23605] Add decryptCipherListWithFailures to VaultSdkSource (#5505)
This commit is contained in:
@@ -23,6 +23,7 @@ import com.bitwarden.vault.CipherListView
|
||||
import com.bitwarden.vault.CipherView
|
||||
import com.bitwarden.vault.Collection
|
||||
import com.bitwarden.vault.CollectionView
|
||||
import com.bitwarden.vault.DecryptCipherListResult
|
||||
import com.bitwarden.vault.EncryptionContext
|
||||
import com.bitwarden.vault.Folder
|
||||
import com.bitwarden.vault.FolderView
|
||||
@@ -227,6 +228,17 @@ interface VaultSdkSource {
|
||||
cipherList: List<Cipher>,
|
||||
): Result<List<CipherView>>
|
||||
|
||||
/**
|
||||
* Decrypts a list of [Cipher]s for the user with the given [userId].
|
||||
*
|
||||
* @return A [DecryptCipherListResult] containing the decrypted [CipherListView]s and references
|
||||
* to [Cipher]s that cannot be decrypted.
|
||||
*/
|
||||
suspend fun decryptCipherListWithFailures(
|
||||
userId: String,
|
||||
cipherList: List<Cipher>,
|
||||
): Result<DecryptCipherListResult>
|
||||
|
||||
/**
|
||||
* Decrypts a [Collection] for the user with the given [userId], returning a [CollectionView]
|
||||
* wrapped in a [Result].
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.bitwarden.vault.CipherListView
|
||||
import com.bitwarden.vault.CipherView
|
||||
import com.bitwarden.vault.Collection
|
||||
import com.bitwarden.vault.CollectionView
|
||||
import com.bitwarden.vault.DecryptCipherListResult
|
||||
import com.bitwarden.vault.EncryptionContext
|
||||
import com.bitwarden.vault.Folder
|
||||
import com.bitwarden.vault.FolderView
|
||||
@@ -311,6 +312,17 @@ class VaultSdkSourceImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun decryptCipherListWithFailures(
|
||||
userId: String,
|
||||
cipherList: List<Cipher>,
|
||||
): Result<DecryptCipherListResult> =
|
||||
runCatchingWithLogs {
|
||||
getClient(userId = userId)
|
||||
.vault()
|
||||
.ciphers()
|
||||
.decryptListWithFailures(cipherList)
|
||||
}
|
||||
|
||||
override suspend fun decryptCollection(
|
||||
userId: String,
|
||||
collection: Collection,
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.bitwarden.vault.CipherListView
|
||||
import com.bitwarden.vault.CipherView
|
||||
import com.bitwarden.vault.Collection
|
||||
import com.bitwarden.vault.CollectionView
|
||||
import com.bitwarden.vault.DecryptCipherListResult
|
||||
import com.bitwarden.vault.EncryptionContext
|
||||
import com.bitwarden.vault.Folder
|
||||
import com.bitwarden.vault.FolderView
|
||||
@@ -1369,6 +1370,43 @@ class VaultSdkSourceTest {
|
||||
|
||||
assertTrue(result.isFailure)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `decryptCipherListWithFailures should return Success when successful`() = runTest {
|
||||
val userId = "userId"
|
||||
val mockCipherList = mockk<List<Cipher>>()
|
||||
val expectedResult = mockk<DecryptCipherListResult>()
|
||||
|
||||
coEvery {
|
||||
clientVault.ciphers().decryptListWithFailures(
|
||||
ciphers = mockCipherList,
|
||||
)
|
||||
} returns expectedResult
|
||||
|
||||
val result = vaultSdkSource.decryptCipherListWithFailures(
|
||||
userId = userId,
|
||||
cipherList = mockCipherList,
|
||||
)
|
||||
|
||||
assertTrue(result.isSuccess)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `decryptCipherListWithFailures should return Failure when Bitwarden exception is thrown`() =
|
||||
runTest {
|
||||
val userId = "userId"
|
||||
val mockCipherList = mockk<List<Cipher>>()
|
||||
coEvery {
|
||||
clientVault.ciphers().decryptListWithFailures(
|
||||
ciphers = mockCipherList,
|
||||
)
|
||||
} throws BitwardenException.E("mockException")
|
||||
val result = vaultSdkSource.decryptCipherListWithFailures(
|
||||
userId = userId,
|
||||
cipherList = mockCipherList,
|
||||
)
|
||||
assertTrue(result.isFailure)
|
||||
}
|
||||
}
|
||||
|
||||
private const val DEFAULT_SIGNATURE = "0987654321ABCDEF"
|
||||
|
||||
Reference in New Issue
Block a user