diff --git a/appconfig/src/main/kotlin/io/element/android/appconfig/LockScreenConfig.kt b/appconfig/src/main/kotlin/io/element/android/appconfig/LockScreenConfig.kt index 5930f53428..9427a1f9c7 100644 --- a/appconfig/src/main/kotlin/io/element/android/appconfig/LockScreenConfig.kt +++ b/appconfig/src/main/kotlin/io/element/android/appconfig/LockScreenConfig.kt @@ -19,14 +19,14 @@ package io.element.android.appconfig 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. */ - val PIN_BLACKLIST = listOf("0000", "1234") + val PIN_BLACKLIST = setOf("0000", "1234") /** * The size of the PIN. diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/validation/PinValidator.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/validation/PinValidator.kt index 20ad023b1c..b164ee8c88 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/validation/PinValidator.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/validation/PinValidator.kt @@ -20,7 +20,10 @@ import io.element.android.appconfig.LockScreenConfig import io.element.android.features.lockscreen.impl.pin.model.PinEntry import javax.inject.Inject -class PinValidator @Inject constructor() { +class PinValidator internal constructor(private val pinBlacklist: Set) { + + @Inject + constructor() : this(LockScreenConfig.PIN_BLACKLIST) sealed interface Result { data object Valid : Result @@ -29,7 +32,7 @@ class PinValidator @Inject constructor() { fun isPinValid(pinEntry: PinEntry): Result { val pinAsText = pinEntry.toText() - val isBlacklisted = LockScreenConfig.PIN_BLACKLIST.any { it == pinAsText } + val isBlacklisted = pinBlacklist.any { it == pinAsText } return if (isBlacklisted) { Result.Invalid(SetupPinFailure.PinBlacklisted) } else { diff --git a/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinPresenterTest.kt b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinPresenterTest.kt index 21005cc722..ff797b52f4 100644 --- a/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinPresenterTest.kt +++ b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinPresenterTest.kt @@ -20,7 +20,6 @@ import app.cash.molecule.RecompositionMode import app.cash.molecule.moleculeFlow import app.cash.turbine.test 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.assertText import io.element.android.features.lockscreen.impl.setup.validation.PinValidator @@ -32,7 +31,7 @@ import org.junit.Test class SetupPinPresenterTest { - private val blacklistedPin = LockScreenConfig.PIN_BLACKLIST + private val blacklistedPin = "1234" private val halfCompletePin = "12" private val completePin = "1235" private val mismatchedPin = "1236" @@ -101,6 +100,6 @@ class SetupPinPresenterTest { } private fun createSetupPinPresenter(): SetupPinPresenter { - return SetupPinPresenter(PinValidator(), aBuildMeta()) + return SetupPinPresenter(PinValidator(setOf(blacklistedPin)), aBuildMeta()) } }