[BWA-253] bug: Filtering empty otp uris sent by Password Manager app (#6869)

This commit is contained in:
aj-rosado
2026-05-06 14:44:42 +01:00
committed by GitHub
parent b9449a7df7
commit a53260fdf7
2 changed files with 43 additions and 3 deletions

View File

@@ -187,7 +187,8 @@ class AuthenticatorRepositoryImpl @Inject constructor(
is DataState.Error -> flowOf(DataState.Error(authenticatorItems.error))
is DataState.NoNetwork -> flowOf(DataState.NoNetwork())
DataState.Loading -> flowOf(DataState.Loading)
is DataState.Loaded -> totpCodeManager.getTotpCodesFlow(authenticatorItems.data)
is DataState.Loaded -> totpCodeManager
.getTotpCodesFlow(authenticatorItems.data)
.map { DataState.Loaded(it) }
is DataState.Pending -> totpCodeManager
@@ -287,7 +288,12 @@ class AuthenticatorRepositoryImpl @Inject constructor(
is AccountSyncState.Success -> {
val verificationCodesList = accounts.toAuthenticatorItems()
totpCodeManager
.getTotpCodesFlow(verificationCodesList)
.getTotpCodesFlow(
itemList = verificationCodesList
.filter {
it.otpUri.isNotEmpty()
},
)
.map { SharedVerificationCodesState.Success(it) }
}
}

View File

@@ -6,6 +6,7 @@ import com.bitwarden.authenticator.data.authenticator.datasource.disk.util.FakeA
import com.bitwarden.authenticator.data.authenticator.datasource.entity.createMockAuthenticatorItemEntity
import com.bitwarden.authenticator.data.authenticator.manager.TotpCodeManager
import com.bitwarden.authenticator.data.authenticator.manager.model.VerificationCodeItem
import com.bitwarden.authenticator.data.authenticator.manager.util.createMockAuthenticatorItem
import com.bitwarden.authenticator.data.authenticator.repository.model.AuthenticatorItem
import com.bitwarden.authenticator.data.authenticator.repository.model.CreateItemResult
import com.bitwarden.authenticator.data.authenticator.repository.model.DeleteItemResult
@@ -157,7 +158,7 @@ class AuthenticatorRepositoryTest {
fun `sharedCodesStateFlow should emit Success when authenticatorBridgeManager emits Success`() =
runTest {
val sharedAccounts = emptyList<SharedAccountData.Account>()
val authenticatorItems = mockk<List<AuthenticatorItem>>()
val authenticatorItems = emptyList<AuthenticatorItem>()
val verificationCodes = mockk<List<VerificationCodeItem>>()
every { sharedAccounts.toAuthenticatorItems() } returns authenticatorItems
every {
@@ -170,6 +171,39 @@ class AuthenticatorRepositoryTest {
}
}
@Suppress("MaxLineLength")
@Test
fun `sharedCodesStateFlow should filter out items with empty otpUri when authenticatorBridgeManager emits Success`() =
runTest {
val sharedAccounts = emptyList<SharedAccountData.Account>()
val itemWithUri = createMockAuthenticatorItem(number = 1)
val itemWithEmptyUri = createMockAuthenticatorItem(
number = 2,
otpUri = "",
)
val allItems = listOf(itemWithUri, itemWithEmptyUri)
val filteredItems = listOf(itemWithUri)
val verificationCodes = mockk<List<VerificationCodeItem>>()
every { sharedAccounts.toAuthenticatorItems() } returns allItems
every {
mockTotpCodeManager.getTotpCodesFlow(filteredItems)
} returns MutableStateFlow(verificationCodes)
authenticatorRepository.sharedCodesStateFlow.test {
assertEquals(
SharedVerificationCodesState.Loading,
awaitItem(),
)
mutableAccountSyncStateFlow.value = AccountSyncState.Success(sharedAccounts)
assertEquals(
SharedVerificationCodesState.Success(verificationCodes),
awaitItem(),
)
verify(exactly = 1) {
mockTotpCodeManager.getTotpCodesFlow(filteredItems)
}
}
}
@Test
@Suppress("MaxLineLength")
fun `firstTimeAccountSyncFlow should emit the first time an account syncs and update SettingsRepository`() =