mirror of
https://github.com/bitwarden/android.git
synced 2024-11-29 14:28:55 +03:00
BIT-2015 BIT-2016: Fix min number and min special chars not propagating (#1163)
This commit is contained in:
parent
3394ff4648
commit
0791d787e0
3 changed files with 29 additions and 2 deletions
|
@ -522,8 +522,8 @@ class GeneratorViewModel @Inject constructor(
|
||||||
avoidAmbiguous = password.avoidAmbiguousChars,
|
avoidAmbiguous = password.avoidAmbiguousChars,
|
||||||
minLowercase = null,
|
minLowercase = null,
|
||||||
minUppercase = null,
|
minUppercase = null,
|
||||||
minNumber = null,
|
minNumber = password.minNumbers.toUByte(),
|
||||||
minSpecial = null,
|
minSpecial = password.minSpecial.toUByte(),
|
||||||
)
|
)
|
||||||
val shouldSave = !password.isUserInteracting
|
val shouldSave = !password.isUserInteracting
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asSharedFlow
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fake implementation of [GeneratorRepository] for testing purposes.
|
* A fake implementation of [GeneratorRepository] for testing purposes.
|
||||||
|
@ -38,6 +39,8 @@ class FakeGeneratorRepository : GeneratorRepository {
|
||||||
|
|
||||||
private var usernameGenerationOptions: UsernameGenerationOptions? = null
|
private var usernameGenerationOptions: UsernameGenerationOptions? = null
|
||||||
|
|
||||||
|
private var passwordGeneratorRequest: PasswordGeneratorRequest? = null
|
||||||
|
|
||||||
private val mutablePasswordHistoryStateFlow =
|
private val mutablePasswordHistoryStateFlow =
|
||||||
MutableStateFlow<LocalDataState<List<PasswordHistoryView>>>(LocalDataState.Loading)
|
MutableStateFlow<LocalDataState<List<PasswordHistoryView>>>(LocalDataState.Loading)
|
||||||
|
|
||||||
|
@ -79,6 +82,7 @@ class FakeGeneratorRepository : GeneratorRepository {
|
||||||
passwordGeneratorRequest: PasswordGeneratorRequest,
|
passwordGeneratorRequest: PasswordGeneratorRequest,
|
||||||
shouldSave: Boolean,
|
shouldSave: Boolean,
|
||||||
): GeneratedPasswordResult {
|
): GeneratedPasswordResult {
|
||||||
|
this.passwordGeneratorRequest = passwordGeneratorRequest
|
||||||
return generatePasswordResult
|
return generatePasswordResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,4 +199,11 @@ class FakeGeneratorRepository : GeneratorRepository {
|
||||||
fun setMockPasswordGeneratorPolicy(policy: PolicyInformation.PasswordGenerator?) {
|
fun setMockPasswordGeneratorPolicy(policy: PolicyInformation.PasswordGenerator?) {
|
||||||
this.passwordGeneratorPolicy = policy
|
this.passwordGeneratorPolicy = policy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the passed in request matches the stored request.
|
||||||
|
*/
|
||||||
|
fun assertEqualsStoredRequest(request: PasswordGeneratorRequest) {
|
||||||
|
assertEquals(request, passwordGeneratorRequest)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.x8bit.bitwarden.ui.tools.feature.generator
|
||||||
import androidx.lifecycle.SavedStateHandle
|
import androidx.lifecycle.SavedStateHandle
|
||||||
import app.cash.turbine.test
|
import app.cash.turbine.test
|
||||||
import app.cash.turbine.turbineScope
|
import app.cash.turbine.turbineScope
|
||||||
|
import com.bitwarden.generators.PasswordGeneratorRequest
|
||||||
import com.x8bit.bitwarden.R
|
import com.x8bit.bitwarden.R
|
||||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||||
import com.x8bit.bitwarden.data.auth.repository.model.PolicyInformation
|
import com.x8bit.bitwarden.data.auth.repository.model.PolicyInformation
|
||||||
|
@ -281,6 +282,21 @@ class GeneratorViewModelTest : BaseViewModelTest() {
|
||||||
updatedPasswordOptions,
|
updatedPasswordOptions,
|
||||||
fakeGeneratorRepository.getPasscodeGenerationOptions(),
|
fakeGeneratorRepository.getPasscodeGenerationOptions(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fakeGeneratorRepository.assertEqualsStoredRequest(
|
||||||
|
PasswordGeneratorRequest(
|
||||||
|
lowercase = true,
|
||||||
|
uppercase = true,
|
||||||
|
numbers = true,
|
||||||
|
special = false,
|
||||||
|
length = 14.toUByte(),
|
||||||
|
avoidAmbiguous = false,
|
||||||
|
minLowercase = null,
|
||||||
|
minUppercase = null,
|
||||||
|
minNumber = 1.toUByte(),
|
||||||
|
minSpecial = 1.toUByte(),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
@Suppress("MaxLineLength")
|
||||||
|
|
Loading…
Reference in a new issue