mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
Add method for encrypting an attachment (#774)
This commit is contained in:
committed by
Álison Fernandes
parent
cc7da7b8dd
commit
6f9147b2b2
@@ -1,5 +1,7 @@
|
||||
package com.x8bit.bitwarden.data.vault.datasource.sdk
|
||||
|
||||
import com.bitwarden.core.AttachmentEncryptResult
|
||||
import com.bitwarden.core.AttachmentView
|
||||
import com.bitwarden.core.Cipher
|
||||
import com.bitwarden.core.CipherListView
|
||||
import com.bitwarden.core.CipherView
|
||||
@@ -37,6 +39,7 @@ import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@Suppress("LargeClass")
|
||||
class VaultSdkSourceTest {
|
||||
private val clientCrypto = mockk<ClientCrypto>()
|
||||
private val clientPasswordHistory = mockk<ClientPasswordHistory>()
|
||||
@@ -472,6 +475,39 @@ class VaultSdkSourceTest {
|
||||
verify { sdkClientManager.getOrCreateClient(userId = userId) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `encryptAttachment should call SDK and return correct data wrapped in a Result`() =
|
||||
runBlocking {
|
||||
val userId = "userId"
|
||||
val expectedResult = mockk<AttachmentEncryptResult>()
|
||||
val mockCipher = mockk<Cipher>()
|
||||
val mockAttachmentView = mockk<AttachmentView>()
|
||||
val fileBuffer = byteArrayOf(1, 2)
|
||||
coEvery {
|
||||
clientVault.attachments().encryptBuffer(
|
||||
cipher = mockCipher,
|
||||
attachment = mockAttachmentView,
|
||||
buffer = fileBuffer,
|
||||
)
|
||||
} returns expectedResult
|
||||
|
||||
val result = vaultSdkSource.encryptAttachment(
|
||||
userId = userId,
|
||||
cipher = mockCipher,
|
||||
attachmentView = mockAttachmentView,
|
||||
fileBuffer = fileBuffer,
|
||||
)
|
||||
|
||||
assertEquals(expectedResult.asSuccess(), result)
|
||||
coVerify {
|
||||
clientVault.attachments().encryptBuffer(
|
||||
cipher = mockCipher,
|
||||
attachment = mockAttachmentView,
|
||||
buffer = fileBuffer,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `encryptSend should call SDK and return correct data wrapped in a Result`() = runBlocking {
|
||||
val userId = "userId"
|
||||
|
||||
Reference in New Issue
Block a user