mirror of
https://github.com/bitwarden/android.git
synced 2026-06-02 02:36:58 -05:00
BIT-765: Add additional properties to GetTokenResponseJson.Success (#136)
This commit is contained in:
@@ -2,6 +2,11 @@ package com.x8bit.bitwarden.data.auth.datasource.network.service
|
||||
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.api.IdentityApi
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.GetTokenResponseJson
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.KdfTypeJson
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.KeyConnectorUserDecryptionOptionsJson
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.MasterPasswordPolicyOptionsJson
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.TrustedDeviceUserDecryptionOptionsJson
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.UserDecryptionOptionsJson
|
||||
import com.x8bit.bitwarden.data.platform.base.BaseServiceTest
|
||||
import com.x8bit.bitwarden.data.platform.util.DeviceModelProvider
|
||||
import io.mockk.every
|
||||
@@ -87,10 +92,79 @@ private val CAPTCHA_BODY = GetTokenResponseJson.CaptchaRequired("123")
|
||||
|
||||
private const val LOGIN_SUCCESS_JSON = """
|
||||
{
|
||||
"access_token": "123"
|
||||
"access_token": "accessToken",
|
||||
"expires_in": 3600,
|
||||
"token_type": "Bearer",
|
||||
"refresh_token": "refreshToken",
|
||||
"PrivateKey": "privateKey",
|
||||
"Key": "key",
|
||||
"MasterPasswordPolicy": {
|
||||
"MinComplexity": 10,
|
||||
"MinLength": 100,
|
||||
"RequireUpper": true,
|
||||
"RequireLower": true,
|
||||
"RequireNumbers": true,
|
||||
"RequireSpecial": true,
|
||||
"EnforceOnLogin": true
|
||||
},
|
||||
"ForcePasswordReset": true,
|
||||
"ResetMasterPassword": true,
|
||||
"Kdf": 1,
|
||||
"KdfIterations": 600000,
|
||||
"KdfMemory": 16,
|
||||
"KdfParallelism": 4,
|
||||
"UserDecryptionOptions": {
|
||||
"HasMasterPassword": true,
|
||||
"TrustedDeviceOption": {
|
||||
"EncryptedPrivateKey": "encryptedPrivateKey",
|
||||
"EncryptedUserKey": "encryptedUserKey",
|
||||
"HasAdminApproval": true,
|
||||
"HasLoginApprovingDevice": true,
|
||||
"HasManageResetPasswordPermission": true
|
||||
},
|
||||
"KeyConnectorOption": {
|
||||
"KeyConnectorUrl": "keyConnectorUrl"
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
private val LOGIN_SUCCESS = GetTokenResponseJson.Success("123")
|
||||
|
||||
private val LOGIN_SUCCESS = GetTokenResponseJson.Success(
|
||||
accessToken = "accessToken",
|
||||
refreshToken = "refreshToken",
|
||||
tokenType = "Bearer",
|
||||
expiresInSeconds = 3600,
|
||||
key = "key",
|
||||
kdfType = KdfTypeJson.ARGON2_ID,
|
||||
kdfIterations = 600000,
|
||||
kdfMemory = 16,
|
||||
kdfParallelism = 4,
|
||||
privateKey = "privateKey",
|
||||
shouldForcePasswordReset = true,
|
||||
shouldResetMasterPassword = true,
|
||||
masterPasswordPolicyOptions = MasterPasswordPolicyOptionsJson(
|
||||
minimumComplexity = 10,
|
||||
minimumLength = 100,
|
||||
shouldRequireUppercase = true,
|
||||
shouldRequireLowercase = true,
|
||||
shouldRequireNumbers = true,
|
||||
shouldRequireSpecialCharacters = true,
|
||||
shouldEnforceOnLogin = true,
|
||||
),
|
||||
userDecryptionOptions = UserDecryptionOptionsJson(
|
||||
hasMasterPassword = true,
|
||||
trustedDeviceUserDecryptionOptions = TrustedDeviceUserDecryptionOptionsJson(
|
||||
encryptedPrivateKey = "encryptedPrivateKey",
|
||||
encryptedUserKey = "encryptedUserKey",
|
||||
hasAdminApproval = true,
|
||||
hasLoginApprovingDevice = true,
|
||||
hasManageResetPasswordPermission = true,
|
||||
),
|
||||
keyConnectorUserDecryptionOptions = KeyConnectorUserDecryptionOptionsJson(
|
||||
keyConnectorUrl = "keyConnectorUrl",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
private const val INVALID_LOGIN_JSON = """
|
||||
{
|
||||
|
||||
@@ -141,6 +141,9 @@ class AuthRepositoryTest {
|
||||
|
||||
@Test
|
||||
fun `login get token succeeds should return Success and update AuthState`() = runTest {
|
||||
val successResponse = mockk<GetTokenResponseJson.Success> {
|
||||
every { accessToken } returns ACCESS_TOKEN
|
||||
}
|
||||
coEvery {
|
||||
accountsService.preLogin(email = EMAIL)
|
||||
} returns Result.success(PRE_LOGIN_SUCCESS)
|
||||
@@ -151,7 +154,7 @@ class AuthRepositoryTest {
|
||||
captchaToken = null,
|
||||
)
|
||||
}
|
||||
.returns(Result.success(GetTokenResponseJson.Success(accessToken = ACCESS_TOKEN)))
|
||||
.returns(Result.success(successResponse))
|
||||
every { authInterceptor.authToken = ACCESS_TOKEN } returns Unit
|
||||
val result = repository.login(email = EMAIL, password = PASSWORD, captchaToken = null)
|
||||
assertEquals(LoginResult.Success, result)
|
||||
@@ -205,6 +208,9 @@ class AuthRepositoryTest {
|
||||
@Test
|
||||
fun `logout should change AuthState to be Unauthenticated`() = runTest {
|
||||
// First login:
|
||||
val successResponse = mockk<GetTokenResponseJson.Success> {
|
||||
every { accessToken } returns ACCESS_TOKEN
|
||||
}
|
||||
coEvery {
|
||||
accountsService.preLogin(email = EMAIL)
|
||||
} returns Result.success(PRE_LOGIN_SUCCESS)
|
||||
@@ -215,7 +221,8 @@ class AuthRepositoryTest {
|
||||
captchaToken = null,
|
||||
)
|
||||
}
|
||||
.returns(Result.success(GetTokenResponseJson.Success(accessToken = ACCESS_TOKEN)))
|
||||
.returns(Result.success(successResponse))
|
||||
|
||||
every { authInterceptor.authToken = ACCESS_TOKEN } returns Unit
|
||||
repository.login(email = EMAIL, password = PASSWORD, captchaToken = null)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user