mirror of
https://github.com/bitwarden/android.git
synced 2026-11-20 11:37:52 -06:00
Move the sdk trustDevice API to the VaultSdkSource (#1184)
This commit is contained in:
committed by
Álison Fernandes
parent
de6f31775b
commit
ed8dfa841e
@@ -6,12 +6,10 @@ import com.bitwarden.core.MasterPasswordPolicyOptions
|
||||
import com.bitwarden.core.RegisterKeyResponse
|
||||
import com.bitwarden.crypto.HashPurpose
|
||||
import com.bitwarden.crypto.Kdf
|
||||
import com.bitwarden.crypto.TrustDeviceResponse
|
||||
import com.bitwarden.sdk.ClientAuth
|
||||
import com.bitwarden.sdk.ClientPlatform
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength
|
||||
import com.x8bit.bitwarden.data.platform.base.FakeDispatcherManager
|
||||
import com.x8bit.bitwarden.data.platform.util.asFailure
|
||||
import com.x8bit.bitwarden.data.platform.util.asSuccess
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.BitwardenFeatureFlagManager
|
||||
import io.mockk.coEvery
|
||||
@@ -50,33 +48,6 @@ class AuthSdkSourceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
fun `getNewAuthRequest should call SDK and return a Result with correct data`() = runBlocking {
|
||||
val email = "test@gmail.com"
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.bitwarden.core.Send
|
||||
import com.bitwarden.core.SendView
|
||||
import com.bitwarden.core.TotpResponse
|
||||
import com.bitwarden.core.UpdatePasswordResponse
|
||||
import com.bitwarden.crypto.TrustDeviceResponse
|
||||
import com.bitwarden.sdk.BitwardenException
|
||||
import com.bitwarden.sdk.Client
|
||||
import com.bitwarden.sdk.ClientAuth
|
||||
@@ -83,6 +84,35 @@ class VaultSdkSourceTest {
|
||||
verify { sdkClientManager.destroyClient(userId = userId) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getTrustDevice with trustDevice success should return success with correct data`() =
|
||||
runBlocking {
|
||||
val userId = "userId"
|
||||
val expectedResult = mockk<TrustDeviceResponse>()
|
||||
coEvery { clientAuth.trustDevice() } returns expectedResult
|
||||
|
||||
val result = vaultSdkSource.getTrustDevice(userId = userId)
|
||||
|
||||
assertEquals(expectedResult.asSuccess(), result)
|
||||
coVerify(exactly = 1) {
|
||||
clientAuth.trustDevice()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getTrustDevice with trustDevice exception should return a failure`() = runBlocking {
|
||||
val userId = "userId"
|
||||
val error = Throwable("Fail")
|
||||
coEvery { clientAuth.trustDevice() } throws error
|
||||
|
||||
val result = vaultSdkSource.getTrustDevice(userId = userId)
|
||||
|
||||
assertEquals(error.asFailure(), result)
|
||||
coVerify(exactly = 1) {
|
||||
clientAuth.trustDevice()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `derivePinKey should call SDK and return a Result with the correct data`() = runBlocking {
|
||||
val userId = "userId"
|
||||
|
||||
Reference in New Issue
Block a user