mirror of
https://github.com/bitwarden/android.git
synced 2025-12-10 09:56:45 -06:00
[PM-23608] Add SDK method for generating TOTP for CipherListView (#5519)
This commit is contained in:
parent
8f783a43e4
commit
811f0f2757
@ -35,6 +35,7 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.model.DeriveKeyConnectorRes
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.InitializeCryptoResult
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.RegisterFido2CredentialRequest
|
||||
import java.io.File
|
||||
import java.time.Instant
|
||||
|
||||
/**
|
||||
* Source of vault information and functionality from the Bitwarden SDK.
|
||||
@ -405,6 +406,15 @@ interface VaultSdkSource {
|
||||
time: DateTime,
|
||||
): Result<TotpResponse>
|
||||
|
||||
/**
|
||||
* Generate a verification code for the given [cipherListView] and [time].
|
||||
*/
|
||||
suspend fun generateTotpForCipherListView(
|
||||
userId: String,
|
||||
cipherListView: CipherListView,
|
||||
time: Instant?,
|
||||
): Result<TotpResponse>
|
||||
|
||||
/**
|
||||
* Re-encrypts the [cipherView] with the organizations encryption key.
|
||||
*/
|
||||
|
||||
@ -48,6 +48,7 @@ import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import java.time.Instant
|
||||
|
||||
/**
|
||||
* Primary implementation of [VaultSdkSource] that serves as a convenience wrapper around a
|
||||
@ -451,6 +452,19 @@ class VaultSdkSourceImpl(
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun generateTotpForCipherListView(
|
||||
userId: String,
|
||||
cipherListView: CipherListView,
|
||||
time: Instant?,
|
||||
): Result<TotpResponse> = runCatchingWithLogs {
|
||||
getClient(userId = userId)
|
||||
.vault()
|
||||
.generateTotpCipherView(
|
||||
view = cipherListView,
|
||||
time = time,
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun moveToOrganization(
|
||||
userId: String,
|
||||
organizationId: String,
|
||||
|
||||
@ -1048,6 +1048,36 @@ class VaultSdkSourceTest {
|
||||
coVerify { sdkClientManager.getOrCreateClient(userId = userId) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `generateTotpForCipherListView should call SDK and return a Result with correct data`() =
|
||||
runTest {
|
||||
val userId = "userId"
|
||||
val totpResponse = TotpResponse("TestCode", 30u)
|
||||
|
||||
coEvery {
|
||||
clientVault.generateTotpCipherView(
|
||||
view = any(),
|
||||
time = any(),
|
||||
)
|
||||
} returns totpResponse
|
||||
|
||||
val result = vaultSdkSource.generateTotpForCipherListView(
|
||||
userId = userId,
|
||||
cipherListView = mockk(),
|
||||
time = mockk(),
|
||||
)
|
||||
|
||||
assertEquals(totpResponse.asSuccess(), result)
|
||||
coVerify {
|
||||
clientVault.generateTotpCipherView(
|
||||
view = any(),
|
||||
time = any(),
|
||||
)
|
||||
}
|
||||
|
||||
coVerify { sdkClientManager.getOrCreateClient(userId = userId) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `moveToOrganization should call SDK and a Result with correct data`() = runTest {
|
||||
val userId = "userId"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user