mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
PIN : fix tests with new LockScreenConfig
This commit is contained in:
@@ -19,14 +19,14 @@ package io.element.android.appconfig
|
|||||||
object LockScreenConfig {
|
object LockScreenConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the LockScreen is mandatory or not.
|
* Whether the PIN is mandatory or not.
|
||||||
*/
|
*/
|
||||||
const val IS_MANDATORY: Boolean = false
|
const val IS_PIN_MANDATORY: Boolean = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some PINs are blacklisted.
|
* Some PINs are blacklisted.
|
||||||
*/
|
*/
|
||||||
val PIN_BLACKLIST = listOf("0000", "1234")
|
val PIN_BLACKLIST = setOf("0000", "1234")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The size of the PIN.
|
* The size of the PIN.
|
||||||
|
|||||||
+5
-2
@@ -20,7 +20,10 @@ import io.element.android.appconfig.LockScreenConfig
|
|||||||
import io.element.android.features.lockscreen.impl.pin.model.PinEntry
|
import io.element.android.features.lockscreen.impl.pin.model.PinEntry
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class PinValidator @Inject constructor() {
|
class PinValidator internal constructor(private val pinBlacklist: Set<String>) {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
constructor() : this(LockScreenConfig.PIN_BLACKLIST)
|
||||||
|
|
||||||
sealed interface Result {
|
sealed interface Result {
|
||||||
data object Valid : Result
|
data object Valid : Result
|
||||||
@@ -29,7 +32,7 @@ class PinValidator @Inject constructor() {
|
|||||||
|
|
||||||
fun isPinValid(pinEntry: PinEntry): Result {
|
fun isPinValid(pinEntry: PinEntry): Result {
|
||||||
val pinAsText = pinEntry.toText()
|
val pinAsText = pinEntry.toText()
|
||||||
val isBlacklisted = LockScreenConfig.PIN_BLACKLIST.any { it == pinAsText }
|
val isBlacklisted = pinBlacklist.any { it == pinAsText }
|
||||||
return if (isBlacklisted) {
|
return if (isBlacklisted) {
|
||||||
Result.Invalid(SetupPinFailure.PinBlacklisted)
|
Result.Invalid(SetupPinFailure.PinBlacklisted)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+2
-3
@@ -20,7 +20,6 @@ import app.cash.molecule.RecompositionMode
|
|||||||
import app.cash.molecule.moleculeFlow
|
import app.cash.molecule.moleculeFlow
|
||||||
import app.cash.turbine.test
|
import app.cash.turbine.test
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.appconfig.LockScreenConfig
|
|
||||||
import io.element.android.features.lockscreen.impl.pin.model.assertEmpty
|
import io.element.android.features.lockscreen.impl.pin.model.assertEmpty
|
||||||
import io.element.android.features.lockscreen.impl.pin.model.assertText
|
import io.element.android.features.lockscreen.impl.pin.model.assertText
|
||||||
import io.element.android.features.lockscreen.impl.setup.validation.PinValidator
|
import io.element.android.features.lockscreen.impl.setup.validation.PinValidator
|
||||||
@@ -32,7 +31,7 @@ import org.junit.Test
|
|||||||
|
|
||||||
class SetupPinPresenterTest {
|
class SetupPinPresenterTest {
|
||||||
|
|
||||||
private val blacklistedPin = LockScreenConfig.PIN_BLACKLIST
|
private val blacklistedPin = "1234"
|
||||||
private val halfCompletePin = "12"
|
private val halfCompletePin = "12"
|
||||||
private val completePin = "1235"
|
private val completePin = "1235"
|
||||||
private val mismatchedPin = "1236"
|
private val mismatchedPin = "1236"
|
||||||
@@ -101,6 +100,6 @@ class SetupPinPresenterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createSetupPinPresenter(): SetupPinPresenter {
|
private fun createSetupPinPresenter(): SetupPinPresenter {
|
||||||
return SetupPinPresenter(PinValidator(), aBuildMeta())
|
return SetupPinPresenter(PinValidator(setOf(blacklistedPin)), aBuildMeta())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user