mirror of
https://github.com/bitwarden/android.git
synced 2024-11-22 17:36:01 +03:00
BIT-2430: Allow lowercase TOTP secrets (#1469)
This commit is contained in:
parent
efbb9b3a19
commit
cd25e2b280
2 changed files with 10 additions and 16 deletions
|
@ -165,6 +165,6 @@ sealed class QrCodeScanAction {
|
||||||
* Checks if a string is using base32 digits.
|
* Checks if a string is using base32 digits.
|
||||||
*/
|
*/
|
||||||
private fun String.isBase32(): Boolean {
|
private fun String.isBase32(): Boolean {
|
||||||
val regex = ("^[A-Z2-7]+=*$").toRegex()
|
val regex = ("^[A-Za-z2-7]+=*$").toRegex()
|
||||||
return regex.matches(this)
|
return regex.matches(this)
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ class QrCodeScanViewModelTest : BaseViewModelTest() {
|
||||||
setupMockUri()
|
setupMockUri()
|
||||||
|
|
||||||
val validCode =
|
val validCode =
|
||||||
"otpauth://totp/Test:me?secret=JBSWY3DPEHPK3PXP&algorithm=sha256&digits=8&period=60"
|
"otpauth://totp/Test:me?secret=JBSWY3dpeHPK3PXP&algorithm=sha256&digits=8&period=60"
|
||||||
val viewModel = createViewModel()
|
val viewModel = createViewModel()
|
||||||
val result = TotpCodeResult.Success(validCode)
|
val result = TotpCodeResult.Success(validCode)
|
||||||
|
|
||||||
|
@ -99,8 +99,7 @@ class QrCodeScanViewModelTest : BaseViewModelTest() {
|
||||||
queryParameterNames = setOf(SECRET),
|
queryParameterNames = setOf(SECRET),
|
||||||
)
|
)
|
||||||
|
|
||||||
val validCode =
|
val validCode = "otpauth://totp/Test:me?secret=JBSWY3dpeHPK3PXP"
|
||||||
"otpauth://totp/Test:me?secret=JBSWY3DPEHPK3PXP"
|
|
||||||
val viewModel = createViewModel()
|
val viewModel = createViewModel()
|
||||||
val result = TotpCodeResult.Success(validCode)
|
val result = TotpCodeResult.Success(validCode)
|
||||||
|
|
||||||
|
@ -119,8 +118,7 @@ class QrCodeScanViewModelTest : BaseViewModelTest() {
|
||||||
|
|
||||||
val viewModel = createViewModel()
|
val viewModel = createViewModel()
|
||||||
val result = TotpCodeResult.CodeScanningError
|
val result = TotpCodeResult.CodeScanningError
|
||||||
val invalidCode =
|
val invalidCode = "otpauth://totp/Test:me?secret=JBSWY3dpeHPK3PXP&algorithm=sha224"
|
||||||
"otpauth://totp/Test:me?secret=JBSWY3DPEHPK3PXP&algorithm=sha224"
|
|
||||||
|
|
||||||
viewModel.eventFlow.test {
|
viewModel.eventFlow.test {
|
||||||
viewModel.trySendAction(QrCodeScanAction.QrCodeScanReceive(invalidCode))
|
viewModel.trySendAction(QrCodeScanAction.QrCodeScanReceive(invalidCode))
|
||||||
|
@ -136,8 +134,7 @@ class QrCodeScanViewModelTest : BaseViewModelTest() {
|
||||||
|
|
||||||
val viewModel = createViewModel()
|
val viewModel = createViewModel()
|
||||||
val result = TotpCodeResult.CodeScanningError
|
val result = TotpCodeResult.CodeScanningError
|
||||||
val invalidCode =
|
val invalidCode = "otpauth://totp/Test:me?secret=JBSWY3dpeHPK3PXP&digits=11"
|
||||||
"otpauth://totp/Test:me?secret=JBSWY3DPEHPK3PXP&digits=11"
|
|
||||||
|
|
||||||
viewModel.eventFlow.test {
|
viewModel.eventFlow.test {
|
||||||
viewModel.trySendAction(QrCodeScanAction.QrCodeScanReceive(invalidCode))
|
viewModel.trySendAction(QrCodeScanAction.QrCodeScanReceive(invalidCode))
|
||||||
|
@ -153,8 +150,7 @@ class QrCodeScanViewModelTest : BaseViewModelTest() {
|
||||||
|
|
||||||
val viewModel = createViewModel()
|
val viewModel = createViewModel()
|
||||||
val result = TotpCodeResult.CodeScanningError
|
val result = TotpCodeResult.CodeScanningError
|
||||||
val invalidCode =
|
val invalidCode = "otpauth://totp/Test:me?secret=JBSWY3dpeHPK3PXP&period=0"
|
||||||
"otpauth://totp/Test:me?secret=JBSWY3DPEHPK3PXP&period=0"
|
|
||||||
|
|
||||||
viewModel.eventFlow.test {
|
viewModel.eventFlow.test {
|
||||||
viewModel.trySendAction(QrCodeScanAction.QrCodeScanReceive(invalidCode))
|
viewModel.trySendAction(QrCodeScanAction.QrCodeScanReceive(invalidCode))
|
||||||
|
@ -169,8 +165,7 @@ class QrCodeScanViewModelTest : BaseViewModelTest() {
|
||||||
|
|
||||||
val viewModel = createViewModel()
|
val viewModel = createViewModel()
|
||||||
val result = TotpCodeResult.CodeScanningError
|
val result = TotpCodeResult.CodeScanningError
|
||||||
val invalidCode =
|
val invalidCode = "nototpauth://totp/Test:me?secret=JBSWY3dpeHPK3PXP"
|
||||||
"nototpauth://totp/Test:me?secret=JBSWY3DPEHPK3PXP"
|
|
||||||
|
|
||||||
viewModel.eventFlow.test {
|
viewModel.eventFlow.test {
|
||||||
viewModel.trySendAction(QrCodeScanAction.QrCodeScanReceive(invalidCode))
|
viewModel.trySendAction(QrCodeScanAction.QrCodeScanReceive(invalidCode))
|
||||||
|
@ -182,12 +177,11 @@ class QrCodeScanViewModelTest : BaseViewModelTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `QrCodeScan should emit failure result with non base32 secret`() = runTest {
|
fun `QrCodeScan should emit failure result with non base32 secret`() = runTest {
|
||||||
setupMockUri(secret = "JBSWY3DPEHPK3PXP1")
|
setupMockUri(secret = "JBSWY3dpeHPK3PXP1")
|
||||||
|
|
||||||
val viewModel = createViewModel()
|
val viewModel = createViewModel()
|
||||||
val result = TotpCodeResult.CodeScanningError
|
val result = TotpCodeResult.CodeScanningError
|
||||||
val invalidCode =
|
val invalidCode = "otpauth://totp/Test:me?secret=JBSWY3dpeHPK3PXP1"
|
||||||
"otpauth://totp/Test:me?secret=JBSWY3DPEHPK3PXP1"
|
|
||||||
|
|
||||||
viewModel.eventFlow.test {
|
viewModel.eventFlow.test {
|
||||||
viewModel.trySendAction(QrCodeScanAction.QrCodeScanReceive(invalidCode))
|
viewModel.trySendAction(QrCodeScanAction.QrCodeScanReceive(invalidCode))
|
||||||
|
@ -244,7 +238,7 @@ class QrCodeScanViewModelTest : BaseViewModelTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupMockUri(
|
private fun setupMockUri(
|
||||||
secret: String? = "JBSWY3DPEHPK3PXP",
|
secret: String? = "JBSWY3dpeHPK3PXP",
|
||||||
algorithm: String = "SHA256",
|
algorithm: String = "SHA256",
|
||||||
digits: String = "8",
|
digits: String = "8",
|
||||||
period: String = "60",
|
period: String = "60",
|
||||||
|
|
Loading…
Reference in a new issue