mirror of
https://github.com/bitwarden/android.git
synced 2025-02-17 12:30:00 +03:00
BIT-693: Password strength indicator sdk update (#672)
This commit is contained in:
parent
9ba6474c37
commit
02aad8f215
2 changed files with 42 additions and 51 deletions
|
@ -14,7 +14,6 @@ import com.x8bit.bitwarden.data.auth.datasource.network.service.AccountsService
|
|||
import com.x8bit.bitwarden.data.auth.datasource.network.service.HaveIBeenPwnedService
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.service.IdentityService
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.AuthSdkSource
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.util.toKdfTypeJson
|
||||
import com.x8bit.bitwarden.data.auth.manager.UserLogoutManager
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.AuthState
|
||||
|
@ -386,24 +385,25 @@ class AuthRepositoryImpl constructor(
|
|||
onSuccess = { BreachCountResult.Success(it) },
|
||||
)
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
override suspend fun getPasswordStrength(
|
||||
email: String,
|
||||
password: String,
|
||||
): PasswordStrengthResult {
|
||||
// TODO: Replace with SDK call (BIT-964)
|
||||
// Ex: return authSdkSource.passwordStrength(email, password)
|
||||
val length = password.length
|
||||
return PasswordStrengthResult.Success(
|
||||
passwordStrength = when {
|
||||
length <= 3 -> PasswordStrength.LEVEL_0
|
||||
length <= 6 -> PasswordStrength.LEVEL_1
|
||||
length <= 9 -> PasswordStrength.LEVEL_2
|
||||
length <= 11 -> PasswordStrength.LEVEL_3
|
||||
else -> PasswordStrength.LEVEL_4
|
||||
},
|
||||
)
|
||||
}
|
||||
): PasswordStrengthResult =
|
||||
authSdkSource
|
||||
.passwordStrength(
|
||||
email = email,
|
||||
password = password,
|
||||
)
|
||||
.fold(
|
||||
onSuccess = {
|
||||
PasswordStrengthResult.Success(
|
||||
passwordStrength = it,
|
||||
)
|
||||
},
|
||||
onFailure = {
|
||||
PasswordStrengthResult.Error
|
||||
},
|
||||
)
|
||||
|
||||
private fun getVaultUnlockType(
|
||||
userId: String,
|
||||
|
|
|
@ -1205,59 +1205,50 @@ class AuthRepositoryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `getPasswordStrength should be based on password length`() = runTest {
|
||||
// TODO: Replace with SDK call (BIT-964)
|
||||
fun `getPasswordStrength returns expected results for various strength levels`() = runTest {
|
||||
coEvery {
|
||||
authSdkSource.passwordStrength(any(), eq("level_0"))
|
||||
} returns Result.success(LEVEL_0)
|
||||
|
||||
coEvery {
|
||||
authSdkSource.passwordStrength(any(), eq("level_1"))
|
||||
} returns Result.success(LEVEL_1)
|
||||
|
||||
coEvery {
|
||||
authSdkSource.passwordStrength(any(), eq("level_2"))
|
||||
} returns Result.success(LEVEL_2)
|
||||
|
||||
coEvery {
|
||||
authSdkSource.passwordStrength(any(), eq("level_3"))
|
||||
} returns Result.success(LEVEL_3)
|
||||
|
||||
coEvery {
|
||||
authSdkSource.passwordStrength(any(), eq("level_4"))
|
||||
} returns Result.success(LEVEL_4)
|
||||
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_0),
|
||||
repository.getPasswordStrength(EMAIL, "1"),
|
||||
)
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_0),
|
||||
repository.getPasswordStrength(EMAIL, "12"),
|
||||
)
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_0),
|
||||
repository.getPasswordStrength(EMAIL, "123"),
|
||||
repository.getPasswordStrength(EMAIL, "level_0"),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_1),
|
||||
repository.getPasswordStrength(EMAIL, "1234"),
|
||||
)
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_1),
|
||||
repository.getPasswordStrength(EMAIL, "12345"),
|
||||
)
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_1),
|
||||
repository.getPasswordStrength(EMAIL, "123456"),
|
||||
repository.getPasswordStrength(EMAIL, "level_1"),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_2),
|
||||
repository.getPasswordStrength(EMAIL, "1234567"),
|
||||
)
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_2),
|
||||
repository.getPasswordStrength(EMAIL, "12345678"),
|
||||
)
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_2),
|
||||
repository.getPasswordStrength(EMAIL, "123456789"),
|
||||
repository.getPasswordStrength(EMAIL, "level_2"),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_3),
|
||||
repository.getPasswordStrength(EMAIL, "123456789a"),
|
||||
)
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_3),
|
||||
repository.getPasswordStrength(EMAIL, "123456789ab"),
|
||||
repository.getPasswordStrength(EMAIL, "level_3"),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
PasswordStrengthResult.Success(LEVEL_4),
|
||||
repository.getPasswordStrength(EMAIL, "123456789abc"),
|
||||
repository.getPasswordStrength(EMAIL, "level_4"),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue