Apply formatter to the app (#3777)

This commit is contained in:
David Perez 2024-08-19 13:43:45 -05:00 committed by GitHub
parent 8aebd36465
commit 5f46423638
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 107 additions and 101 deletions

View file

@ -55,18 +55,18 @@ class Fido2CredentialManagerImpl(
selectedCipherView: CipherView, selectedCipherView: CipherView,
): Fido2RegisterCredentialResult { ): Fido2RegisterCredentialResult {
val clientData = if (fido2CredentialRequest.callingAppInfo.isOriginPopulated()) { val clientData = if (fido2CredentialRequest.callingAppInfo.isOriginPopulated()) {
fido2CredentialRequest fido2CredentialRequest
.callingAppInfo
.getAppSigningSignatureFingerprint()
?.let { ClientData.DefaultWithCustomHash(hash = it) }
?: return Fido2RegisterCredentialResult.Error
} else {
ClientData.DefaultWithExtraData(
androidPackageName = fido2CredentialRequest
.callingAppInfo .callingAppInfo
.getAppSigningSignatureFingerprint() .packageName,
?.let { ClientData.DefaultWithCustomHash(hash = it) } )
?: return Fido2RegisterCredentialResult.Error }
} else {
ClientData.DefaultWithExtraData(
androidPackageName = fido2CredentialRequest
.callingAppInfo
.packageName,
)
}
val origin = fido2CredentialRequest val origin = fido2CredentialRequest
.origin .origin
?: getOriginUrlFromAttestationOptionsOrNull(fido2CredentialRequest.requestJson) ?: getOriginUrlFromAttestationOptionsOrNull(fido2CredentialRequest.requestJson)

View file

@ -16,8 +16,6 @@ import com.x8bit.bitwarden.ui.auth.feature.enterprisesignon.enterpriseSignOnDest
import com.x8bit.bitwarden.ui.auth.feature.enterprisesignon.navigateToEnterpriseSignOn import com.x8bit.bitwarden.ui.auth.feature.enterprisesignon.navigateToEnterpriseSignOn
import com.x8bit.bitwarden.ui.auth.feature.environment.environmentDestination import com.x8bit.bitwarden.ui.auth.feature.environment.environmentDestination
import com.x8bit.bitwarden.ui.auth.feature.environment.navigateToEnvironment import com.x8bit.bitwarden.ui.auth.feature.environment.navigateToEnvironment
import com.x8bit.bitwarden.ui.auth.feature.masterpasswordgenerator.masterPasswordGeneratorDestination
import com.x8bit.bitwarden.ui.auth.feature.masterpasswordgenerator.navigateToMasterPasswordGenerator
import com.x8bit.bitwarden.ui.auth.feature.landing.LANDING_ROUTE import com.x8bit.bitwarden.ui.auth.feature.landing.LANDING_ROUTE
import com.x8bit.bitwarden.ui.auth.feature.landing.landingDestination import com.x8bit.bitwarden.ui.auth.feature.landing.landingDestination
import com.x8bit.bitwarden.ui.auth.feature.landing.navigateToLanding import com.x8bit.bitwarden.ui.auth.feature.landing.navigateToLanding
@ -26,6 +24,8 @@ import com.x8bit.bitwarden.ui.auth.feature.login.navigateToLogin
import com.x8bit.bitwarden.ui.auth.feature.loginwithdevice.loginWithDeviceDestination import com.x8bit.bitwarden.ui.auth.feature.loginwithdevice.loginWithDeviceDestination
import com.x8bit.bitwarden.ui.auth.feature.loginwithdevice.model.LoginWithDeviceType import com.x8bit.bitwarden.ui.auth.feature.loginwithdevice.model.LoginWithDeviceType
import com.x8bit.bitwarden.ui.auth.feature.loginwithdevice.navigateToLoginWithDevice import com.x8bit.bitwarden.ui.auth.feature.loginwithdevice.navigateToLoginWithDevice
import com.x8bit.bitwarden.ui.auth.feature.masterpasswordgenerator.masterPasswordGeneratorDestination
import com.x8bit.bitwarden.ui.auth.feature.masterpasswordgenerator.navigateToMasterPasswordGenerator
import com.x8bit.bitwarden.ui.auth.feature.masterpasswordguidance.masterPasswordGuidanceDestination import com.x8bit.bitwarden.ui.auth.feature.masterpasswordguidance.masterPasswordGuidanceDestination
import com.x8bit.bitwarden.ui.auth.feature.masterpasswordhint.masterPasswordHintDestination import com.x8bit.bitwarden.ui.auth.feature.masterpasswordhint.masterPasswordHintDestination
import com.x8bit.bitwarden.ui.auth.feature.masterpasswordhint.navigateToMasterPasswordHint import com.x8bit.bitwarden.ui.auth.feature.masterpasswordhint.navigateToMasterPasswordHint
@ -82,7 +82,8 @@ fun NavGraphBuilder.authGraph(
onNavigateBack = { navController.popBackStack() }, onNavigateBack = { navController.popBackStack() },
onNavigateBackToLanding = { onNavigateBackToLanding = {
navController.popBackStack(route = LANDING_ROUTE, inclusive = false) navController.popBackStack(route = LANDING_ROUTE, inclusive = false)
},) },
)
completeRegistrationDestination( completeRegistrationDestination(
onNavigateBack = { navController.popBackStack() }, onNavigateBack = { navController.popBackStack() },
onNavigateToLanding = { onNavigateToLanding = {

View file

@ -10,18 +10,18 @@ import com.x8bit.bitwarden.data.auth.repository.model.SendVerificationEmailResul
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
import com.x8bit.bitwarden.data.platform.repository.model.Environment import com.x8bit.bitwarden.data.platform.repository.model.Environment
import com.x8bit.bitwarden.data.platform.repository.model.Environment.Type import com.x8bit.bitwarden.data.platform.repository.model.Environment.Type
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.CloseClick
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.ContinueClick import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.ContinueClick
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.EmailInputChange import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.EmailInputChange
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.NameInputChange import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.EnvironmentTypeSelect
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.CloseClick
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.ErrorDialogDismiss import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.ErrorDialogDismiss
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.ReceiveMarketingEmailsToggle import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.Internal.ReceiveSendVerificationEmailResult
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.Internal.UpdatedEnvironmentReceive
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.NameInputChange
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.PrivacyPolicyClick import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.PrivacyPolicyClick
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.ReceiveMarketingEmailsToggle
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.TermsClick import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.TermsClick
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.UnsubscribeMarketingEmailsClick import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.UnsubscribeMarketingEmailsClick
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.EnvironmentTypeSelect
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.Internal.UpdatedEnvironmentReceive
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationAction.Internal.ReceiveSendVerificationEmailResult
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
import com.x8bit.bitwarden.ui.platform.base.util.asText import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.platform.base.util.isValidEmail import com.x8bit.bitwarden.ui.platform.base.util.isValidEmail

View file

@ -90,6 +90,7 @@ fun RootNavScreen(
is RootNavState.CompleteOngoingRegistration, is RootNavState.CompleteOngoingRegistration,
RootNavState.AuthWithWelcome, RootNavState.AuthWithWelcome,
-> AUTH_GRAPH_ROUTE -> AUTH_GRAPH_ROUTE
RootNavState.ResetPassword -> RESET_PASSWORD_ROUTE RootNavState.ResetPassword -> RESET_PASSWORD_ROUTE
RootNavState.SetPassword -> SET_PASSWORD_ROUTE RootNavState.SetPassword -> SET_PASSWORD_ROUTE
RootNavState.Splash -> SPLASH_ROUTE RootNavState.Splash -> SPLASH_ROUTE

View file

@ -16,7 +16,6 @@ import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext

View file

@ -973,6 +973,6 @@ Do you want to switch to this account?</string>
<string name="prevent_account_lockout">Prevent account lockout</string> <string name="prevent_account_lockout">Prevent account lockout</string>
<string name="generate_master_password">Generate master password</string> <string name="generate_master_password">Generate master password</string>
<string name="generate_button_label">Generate</string> <string name="generate_button_label">Generate</string>
<string name="write_this_password_down_and_keep_it_somewhere_safe">Write this password down and keep it somewhere safe.</string> <string name="write_this_password_down_and_keep_it_somewhere_safe">Write this password down and keep it somewhere safe.</string>
<string name="learn_about_other_ways_to_prevent_account_lockout">Learn about other ways to prevent account lockout</string> <string name="learn_about_other_ways_to_prevent_account_lockout">Learn about other ways to prevent account lockout</string>
</resources> </resources>

View file

@ -1961,96 +1961,101 @@ class AuthRepositoryTest {
@Test @Test
@Suppress("MaxLineLength") @Suppress("MaxLineLength")
fun `login two factor should return Error result when get token succeeds but unlock vault fails`() = runTest { fun `login two factor should return Error result when get token succeeds but unlock vault fails`() =
val twoFactorResponse = GetTokenResponseJson runTest {
.TwoFactorRequired( val twoFactorResponse = GetTokenResponseJson.TwoFactorRequired(
authMethodsData = TWO_FACTOR_AUTH_METHODS_DATA, authMethodsData = TWO_FACTOR_AUTH_METHODS_DATA,
captchaToken = null, captchaToken = null,
ssoToken = null, ssoToken = null,
twoFactorProviders = null, twoFactorProviders = null,
) )
// Attempt a normal login with a two factor error first, so that the auth // Attempt a normal login with a two factor error first, so that the auth
// data will be cached. // data will be cached.
coEvery { identityService.preLogin(EMAIL) } returns PRE_LOGIN_SUCCESS.asSuccess() coEvery { identityService.preLogin(EMAIL) } returns PRE_LOGIN_SUCCESS.asSuccess()
coEvery { coEvery {
identityService.getToken( identityService.getToken(
email = EMAIL, email = EMAIL,
authModel = IdentityTokenAuthModel.MasterPassword( authModel = IdentityTokenAuthModel.MasterPassword(
username = EMAIL, username = EMAIL,
password = PASSWORD_HASH, password = PASSWORD_HASH,
), ),
captchaToken = null, captchaToken = null,
uniqueAppId = UNIQUE_APP_ID, uniqueAppId = UNIQUE_APP_ID,
) )
} returns twoFactorResponse } returns twoFactorResponse.asSuccess()
.asSuccess()
val firstResult = repository.login(email = EMAIL, password = PASSWORD, captchaToken = null)
assertEquals(LoginResult.TwoFactorRequired, firstResult)
coVerify { identityService.preLogin(email = EMAIL) }
coVerify {
identityService.getToken(
email = EMAIL,
authModel = IdentityTokenAuthModel.MasterPassword(
username = EMAIL,
password = PASSWORD_HASH,
),
captchaToken = null,
uniqueAppId = UNIQUE_APP_ID,
)
}
// Login with two factor data. val firstResult = repository.login(
val successResponse = GET_TOKEN_RESPONSE_SUCCESS.copy(
twoFactorToken = "twoFactorTokenToStore",
)
coEvery {
identityService.getToken(
email = EMAIL, email = EMAIL,
authModel = IdentityTokenAuthModel.MasterPassword( password = PASSWORD,
username = EMAIL,
password = PASSWORD_HASH,
),
captchaToken = null, captchaToken = null,
uniqueAppId = UNIQUE_APP_ID, )
assertEquals(LoginResult.TwoFactorRequired, firstResult)
coVerify { identityService.preLogin(email = EMAIL) }
coVerify {
identityService.getToken(
email = EMAIL,
authModel = IdentityTokenAuthModel.MasterPassword(
username = EMAIL,
password = PASSWORD_HASH,
),
captchaToken = null,
uniqueAppId = UNIQUE_APP_ID,
)
}
// Login with two factor data.
val successResponse = GET_TOKEN_RESPONSE_SUCCESS.copy(
twoFactorToken = "twoFactorTokenToStore",
)
coEvery {
identityService.getToken(
email = EMAIL,
authModel = IdentityTokenAuthModel.MasterPassword(
username = EMAIL,
password = PASSWORD_HASH,
),
captchaToken = null,
uniqueAppId = UNIQUE_APP_ID,
twoFactorData = TWO_FACTOR_DATA,
)
} returns successResponse.asSuccess()
coEvery {
vaultRepository.unlockVault(
userId = USER_ID_1,
email = EMAIL,
kdf = ACCOUNT_1.profile.toSdkParams(),
initUserCryptoMethod = InitUserCryptoMethod.Password(
password = PASSWORD,
userKey = successResponse.key!!,
),
privateKey = successResponse.privateKey!!,
organizationKeys = null,
)
} returns VaultUnlockResult.InvalidStateError
every {
successResponse.toUserState(
previousUserState = null,
environmentUrlData = EnvironmentUrlDataJson.DEFAULT_US,
)
} returns SINGLE_USER_STATE_1
val finalResult = repository.login(
email = EMAIL,
password = PASSWORD,
twoFactorData = TWO_FACTOR_DATA, twoFactorData = TWO_FACTOR_DATA,
captchaToken = null,
) )
} returns successResponse.asSuccess() assertEquals(LoginResult.Error(errorMessage = null), finalResult)
coEvery { assertEquals(twoFactorResponse, repository.twoFactorResponse)
vaultRepository.unlockVault( fakeAuthDiskSource.assertTwoFactorToken(
userId = USER_ID_1,
email = EMAIL, email = EMAIL,
kdf = ACCOUNT_1.profile.toSdkParams(), twoFactorToken = null,
initUserCryptoMethod = InitUserCryptoMethod.Password(
password = PASSWORD,
userKey = successResponse.key!!,
),
privateKey = successResponse.privateKey!!,
organizationKeys = null,
) )
} returns VaultUnlockResult.InvalidStateError
every {
successResponse.toUserState(
previousUserState = null,
environmentUrlData = EnvironmentUrlDataJson.DEFAULT_US,
)
} returns SINGLE_USER_STATE_1
val finalResult = repository.login(
email = EMAIL,
password = PASSWORD,
twoFactorData = TWO_FACTOR_DATA,
captchaToken = null,
)
assertEquals(LoginResult.Error(errorMessage = null), finalResult)
assertEquals(twoFactorResponse, repository.twoFactorResponse)
fakeAuthDiskSource.assertTwoFactorToken(
email = EMAIL,
twoFactorToken = null,
)
coVerify(exactly = 0) { coVerify(exactly = 0) {
vaultRepository.syncIfNecessary() vaultRepository.syncIfNecessary()
}
} }
}
@Test @Test
fun `login uses remembered two factor tokens`() = runTest { fun `login uses remembered two factor tokens`() = runTest {

View file

@ -311,7 +311,6 @@ class VaultSdkCipherExtensionsTest {
createMockCipherView(1).copy(name = "D"), createMockCipherView(1).copy(name = "D"),
createMockCipherView(1).copy(name = "AbA"), createMockCipherView(1).copy(name = "AbA"),
createMockCipherView(1).copy(name = "aAb"), createMockCipherView(1).copy(name = "aAb"),
) )
val expected = listOf( val expected = listOf(

View file

@ -2,8 +2,8 @@ package com.x8bit.bitwarden.data.vault.repository.util
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockSend import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockSend
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockSendJsonRequest import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockSendJsonRequest
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSdkSend import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSdkSend
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test

View file

@ -241,6 +241,7 @@ class SetupUnlockViewModelTest : BaseViewModelTest() {
) )
} }
} }
@Test @Test
fun `EnableBiometricsClick actin should show error dialog when cipher is null`() { fun `EnableBiometricsClick actin should show error dialog when cipher is null`() {
every { every {

View file

@ -3,8 +3,8 @@ package com.x8bit.bitwarden.ui.auth.feature.masterpasswordguidance
import app.cash.turbine.test import app.cash.turbine.test
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class MasterPasswordGuidanceViewModelTest : BaseViewModelTest() { class MasterPasswordGuidanceViewModelTest : BaseViewModelTest() {