mirror of
https://github.com/bitwarden/android.git
synced 2025-12-12 00:08:00 -06:00
Add getTrustDevice API to AuthSdkSource (#1147)
This commit is contained in:
parent
058c4f0dfc
commit
2244e21e29
@ -5,12 +5,18 @@ import com.bitwarden.core.MasterPasswordPolicyOptions
|
|||||||
import com.bitwarden.core.RegisterKeyResponse
|
import com.bitwarden.core.RegisterKeyResponse
|
||||||
import com.bitwarden.crypto.HashPurpose
|
import com.bitwarden.crypto.HashPurpose
|
||||||
import com.bitwarden.crypto.Kdf
|
import com.bitwarden.crypto.Kdf
|
||||||
|
import com.bitwarden.crypto.TrustDeviceResponse
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength
|
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Source of authentication information and functionality from the Bitwarden SDK.
|
* Source of authentication information and functionality from the Bitwarden SDK.
|
||||||
*/
|
*/
|
||||||
interface AuthSdkSource {
|
interface AuthSdkSource {
|
||||||
|
/**
|
||||||
|
* Gets the data to authenticate with trusted device encryption.
|
||||||
|
*/
|
||||||
|
suspend fun getTrustDevice(): Result<TrustDeviceResponse>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the data needed to create a new auth request.
|
* Gets the data needed to create a new auth request.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.bitwarden.core.MasterPasswordPolicyOptions
|
|||||||
import com.bitwarden.core.RegisterKeyResponse
|
import com.bitwarden.core.RegisterKeyResponse
|
||||||
import com.bitwarden.crypto.HashPurpose
|
import com.bitwarden.crypto.HashPurpose
|
||||||
import com.bitwarden.crypto.Kdf
|
import com.bitwarden.crypto.Kdf
|
||||||
|
import com.bitwarden.crypto.TrustDeviceResponse
|
||||||
import com.bitwarden.sdk.ClientAuth
|
import com.bitwarden.sdk.ClientAuth
|
||||||
import com.bitwarden.sdk.ClientPlatform
|
import com.bitwarden.sdk.ClientPlatform
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength
|
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength
|
||||||
@ -21,6 +22,10 @@ class AuthSdkSourceImpl(
|
|||||||
private val clientPlatform: ClientPlatform,
|
private val clientPlatform: ClientPlatform,
|
||||||
) : AuthSdkSource {
|
) : AuthSdkSource {
|
||||||
|
|
||||||
|
override suspend fun getTrustDevice(): Result<TrustDeviceResponse> = runCatching {
|
||||||
|
clientAuth.trustDevice()
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getNewAuthRequest(
|
override suspend fun getNewAuthRequest(
|
||||||
email: String,
|
email: String,
|
||||||
): Result<AuthRequestResponse> = runCatching {
|
): Result<AuthRequestResponse> = runCatching {
|
||||||
|
|||||||
@ -6,9 +6,11 @@ import com.bitwarden.core.MasterPasswordPolicyOptions
|
|||||||
import com.bitwarden.core.RegisterKeyResponse
|
import com.bitwarden.core.RegisterKeyResponse
|
||||||
import com.bitwarden.crypto.HashPurpose
|
import com.bitwarden.crypto.HashPurpose
|
||||||
import com.bitwarden.crypto.Kdf
|
import com.bitwarden.crypto.Kdf
|
||||||
|
import com.bitwarden.crypto.TrustDeviceResponse
|
||||||
import com.bitwarden.sdk.ClientAuth
|
import com.bitwarden.sdk.ClientAuth
|
||||||
import com.bitwarden.sdk.ClientPlatform
|
import com.bitwarden.sdk.ClientPlatform
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength
|
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength
|
||||||
|
import com.x8bit.bitwarden.data.platform.util.asFailure
|
||||||
import com.x8bit.bitwarden.data.platform.util.asSuccess
|
import com.x8bit.bitwarden.data.platform.util.asSuccess
|
||||||
import io.mockk.coEvery
|
import io.mockk.coEvery
|
||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
@ -27,6 +29,33 @@ class AuthSdkSourceTest {
|
|||||||
clientPlatform = clientPlatform,
|
clientPlatform = clientPlatform,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `getTrustDevice with trustDevice success should return success with correct data`() =
|
||||||
|
runBlocking {
|
||||||
|
val expectedResult = mockk<TrustDeviceResponse>()
|
||||||
|
coEvery { clientAuth.trustDevice() } returns expectedResult
|
||||||
|
|
||||||
|
val result = authSkdSource.getTrustDevice()
|
||||||
|
|
||||||
|
assertEquals(expectedResult.asSuccess(), result)
|
||||||
|
coVerify(exactly = 1) {
|
||||||
|
clientAuth.trustDevice()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `getTrustDevice with trustDevice exception should return a failure`() = runBlocking {
|
||||||
|
val error = Throwable("Fail")
|
||||||
|
coEvery { clientAuth.trustDevice() } throws error
|
||||||
|
|
||||||
|
val result = authSkdSource.getTrustDevice()
|
||||||
|
|
||||||
|
assertEquals(error.asFailure(), result)
|
||||||
|
coVerify(exactly = 1) {
|
||||||
|
clientAuth.trustDevice()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `getNewAuthRequest should call SDK and return a Result with correct data`() = runBlocking {
|
fun `getNewAuthRequest should call SDK and return a Result with correct data`() = runBlocking {
|
||||||
val email = "test@gmail.com"
|
val email = "test@gmail.com"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user