mirror of
https://github.com/bitwarden/android.git
synced 2025-03-16 03:08:50 +03:00
Add makeRegisterTdeKeysAndUnlockVault to authSdkSource (#1245)
This commit is contained in:
parent
de39f76627
commit
92e39f25c1
3 changed files with 56 additions and 0 deletions
|
@ -3,6 +3,7 @@ package com.x8bit.bitwarden.data.auth.datasource.sdk
|
|||
import com.bitwarden.core.AuthRequestResponse
|
||||
import com.bitwarden.core.MasterPasswordPolicyOptions
|
||||
import com.bitwarden.core.RegisterKeyResponse
|
||||
import com.bitwarden.core.RegisterTdeKeyResponse
|
||||
import com.bitwarden.crypto.HashPurpose
|
||||
import com.bitwarden.crypto.Kdf
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength
|
||||
|
@ -45,6 +46,16 @@ interface AuthSdkSource {
|
|||
kdf: Kdf,
|
||||
): Result<RegisterKeyResponse>
|
||||
|
||||
/**
|
||||
* Creates a set of encryption key information for registration of a trusted device and unlocks
|
||||
* the vault for the user.
|
||||
*/
|
||||
suspend fun makeRegisterTdeKeysAndUnlockVault(
|
||||
userId: String,
|
||||
orgPublicKey: String,
|
||||
rememberDevice: Boolean,
|
||||
): Result<RegisterTdeKeyResponse>
|
||||
|
||||
/**
|
||||
* Checks the password strength for the given [email] and [password] combination, along with
|
||||
* some [additionalInputs].
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.bitwarden.core.AuthRequestResponse
|
|||
import com.bitwarden.core.FingerprintRequest
|
||||
import com.bitwarden.core.MasterPasswordPolicyOptions
|
||||
import com.bitwarden.core.RegisterKeyResponse
|
||||
import com.bitwarden.core.RegisterTdeKeyResponse
|
||||
import com.bitwarden.crypto.HashPurpose
|
||||
import com.bitwarden.crypto.Kdf
|
||||
import com.bitwarden.sdk.Client
|
||||
|
@ -75,6 +76,19 @@ class AuthSdkSourceImpl(
|
|||
)
|
||||
}
|
||||
|
||||
override suspend fun makeRegisterTdeKeysAndUnlockVault(
|
||||
userId: String,
|
||||
orgPublicKey: String,
|
||||
rememberDevice: Boolean,
|
||||
): Result<RegisterTdeKeyResponse> = runCatching {
|
||||
getClient(userId = userId)
|
||||
.auth()
|
||||
.makeRegisterTdeKeys(
|
||||
orgPublicKey = orgPublicKey,
|
||||
rememberDevice = rememberDevice,
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun passwordStrength(
|
||||
email: String,
|
||||
password: String,
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.bitwarden.core.AuthRequestResponse
|
|||
import com.bitwarden.core.FingerprintRequest
|
||||
import com.bitwarden.core.MasterPasswordPolicyOptions
|
||||
import com.bitwarden.core.RegisterKeyResponse
|
||||
import com.bitwarden.core.RegisterTdeKeyResponse
|
||||
import com.bitwarden.crypto.HashPurpose
|
||||
import com.bitwarden.crypto.Kdf
|
||||
import com.bitwarden.sdk.Client
|
||||
|
@ -157,6 +158,36 @@ class AuthSdkSourceTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `makeRegisterTdeKeysAndUnlockVault should call SDK and return a Result with the correct data`() =
|
||||
runBlocking {
|
||||
val userId = "userId"
|
||||
val orgPublicKey = "orgPublicKey"
|
||||
val rememberDevice = true
|
||||
val expectedResult = mockk<RegisterTdeKeyResponse>()
|
||||
coEvery { sdkClientManager.getOrCreateClient(userId = userId) } returns client
|
||||
coEvery {
|
||||
clientAuth.makeRegisterTdeKeys(
|
||||
orgPublicKey = orgPublicKey,
|
||||
rememberDevice = rememberDevice,
|
||||
)
|
||||
} returns expectedResult
|
||||
|
||||
val result = authSkdSource.makeRegisterTdeKeysAndUnlockVault(
|
||||
userId = userId,
|
||||
orgPublicKey = orgPublicKey,
|
||||
rememberDevice = rememberDevice,
|
||||
)
|
||||
assertEquals(expectedResult.asSuccess(), result)
|
||||
coVerify(exactly = 1) {
|
||||
clientAuth.makeRegisterTdeKeys(
|
||||
orgPublicKey = orgPublicKey,
|
||||
rememberDevice = rememberDevice,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This test is disabled due to issue here with mocking UByte (BIT-877).
|
||||
// See: https://github.com/mockk/mockk/issues/544
|
||||
@Disabled
|
||||
|
|
Loading…
Add table
Reference in a new issue