Update moveToOrganization to be 1-to-1 with the SDK (#1429)

This commit is contained in:
David Perez 2024-06-06 11:11:29 -05:00 committed by Álison Fernandes
parent 3a8f3aa0f6
commit 913b53bcac
5 changed files with 13 additions and 7 deletions

View file

@ -362,7 +362,7 @@ interface VaultSdkSource {
userId: String,
organizationId: String,
cipherView: CipherView,
): Result<Cipher>
): Result<CipherView>
/**
* Validates that the given password matches the password hash.

View file

@ -25,7 +25,6 @@ import com.bitwarden.sdk.BitwardenException
import com.bitwarden.sdk.Client
import com.bitwarden.sdk.ClientVault
import com.x8bit.bitwarden.data.platform.manager.SdkClientManager
import com.x8bit.bitwarden.data.platform.util.flatMap
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.InitializeCryptoResult
import java.io.File
@ -376,13 +375,12 @@ class VaultSdkSourceImpl(
userId: String,
organizationId: String,
cipherView: CipherView,
): Result<Cipher> = runCatching {
): Result<CipherView> = runCatching {
getClient(userId = userId)
.vault()
.ciphers()
.moveToOrganization(cipher = cipherView, organizationId = organizationId)
}
.flatMap { encryptCipher(userId = userId, cipherView = it) }
override suspend fun validatePassword(
userId: String,

View file

@ -822,6 +822,7 @@ class VaultRepositoryImpl(
organizationId = organizationId,
cipherView = cipherView,
)
.flatMap { vaultSdkSource.encryptCipher(userId = userId, cipherView = it) }
.flatMap { cipher ->
ciphersService.shareCipher(
cipherId = cipherId,

View file

@ -855,12 +855,11 @@ class VaultSdkSourceTest {
val userId = "userId"
val organizationId = "organizationId"
val mockCipher = mockk<CipherView>()
val expectedResult = mockk<Cipher>()
val expectedResult = mockk<CipherView>()
val clientCipher = mockk<ClientCiphers> {
coEvery {
moveToOrganization(cipher = mockCipher, organizationId = organizationId)
} returns mockCipher
coEvery { encrypt(cipherView = mockCipher) } returns expectedResult
} returns expectedResult
}
every { clientVault.ciphers() } returns clientCipher

View file

@ -3112,12 +3112,16 @@ class VaultRepositoryTest {
fakeAuthDiskSource.userState = MOCK_USER_STATE
val userId = "mockId-1"
val organizationId = "organizationId"
val mockCipherView = createMockCipherView(number = 1)
coEvery {
vaultSdkSource.moveToOrganization(
userId = userId,
organizationId = organizationId,
cipherView = createMockCipherView(number = 1),
)
} returns mockCipherView.asSuccess()
coEvery {
vaultSdkSource.encryptCipher(userId = userId, cipherView = mockCipherView)
} returns createMockSdkCipher(number = 1, clock = clock).asSuccess()
coEvery {
ciphersService.shareCipher(
@ -3156,12 +3160,16 @@ class VaultRepositoryTest {
fakeAuthDiskSource.userState = MOCK_USER_STATE
val userId = "mockId-1"
val organizationId = "organizationId"
val mockCipherView = createMockCipherView(number = 1)
coEvery {
vaultSdkSource.moveToOrganization(
userId = userId,
organizationId = organizationId,
cipherView = createMockCipherView(number = 1),
)
} returns mockCipherView.asSuccess()
coEvery {
vaultSdkSource.encryptCipher(userId = userId, cipherView = mockCipherView)
} returns createMockSdkCipher(number = 1, clock = clock).asSuccess()
coEvery {
ciphersService.shareCipher(