Browse Source

PIN : fix tests with new LockScreenConfig

pull/1624/head
ganfra 11 months ago
parent
commit
20eed4f7d7
  1. 6
      appconfig/src/main/kotlin/io/element/android/appconfig/LockScreenConfig.kt
  2. 7
      features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/validation/PinValidator.kt
  3. 5
      features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinPresenterTest.kt

6
appconfig/src/main/kotlin/io/element/android/appconfig/LockScreenConfig.kt

@ -19,14 +19,14 @@ package io.element.android.appconfig @@ -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.

7
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 @@ -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<String>) {
@Inject
constructor() : this(LockScreenConfig.PIN_BLACKLIST)
sealed interface Result {
data object Valid : Result
@ -29,7 +32,7 @@ class PinValidator @Inject constructor() { @@ -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 {

5
features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinPresenterTest.kt

@ -20,7 +20,6 @@ import app.cash.molecule.RecompositionMode @@ -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 @@ -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 { @@ -101,6 +100,6 @@ class SetupPinPresenterTest {
}
private fun createSetupPinPresenter(): SetupPinPresenter {
return SetupPinPresenter(PinValidator(), aBuildMeta())
return SetupPinPresenter(PinValidator(setOf(blacklistedPin)), aBuildMeta())
}
}

Loading…
Cancel
Save