diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherListViewExtensions.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherListViewExtensions.kt index 95332e62a5..96a43ef05b 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherListViewExtensions.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherListViewExtensions.kt @@ -7,16 +7,19 @@ import com.bitwarden.vault.CopyableCipherFields import com.bitwarden.vault.LoginListView /** - * Returns true when the cipher is not deleted and contains at least one FIDO 2 credential. + * Returns true when the cipher is not archived, not deleted and contains at least one FIDO 2 + * credential. */ val CipherListView.isActiveWithFido2Credentials: Boolean - get() = deletedDate == null && login?.hasFido2 ?: false + get() = archivedDate == null && deletedDate == null && login?.hasFido2 ?: false /** - * Returns true when the cipher type is not deleted and contains a copyable password. + * Returns true when the cipher type is not archived, not deleted and contains a copyable password. */ val CipherListView.isActiveWithCopyablePassword: Boolean - get() = deletedDate == null && copyableFields.contains(CopyableCipherFields.LOGIN_PASSWORD) + get() = archivedDate == null && + deletedDate == null && + copyableFields.contains(CopyableCipherFields.LOGIN_PASSWORD) /** * Returns the [LoginListView] if the cipher is of type [CipherListViewType.Login], otherwise null. diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherViewExtensions.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherViewExtensions.kt index 159198b7c4..2e829a5432 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherViewExtensions.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherViewExtensions.kt @@ -48,13 +48,17 @@ fun CipherView.toAutofillCipherProvider(): AutofillCipherProvider = } /** - * Returns true when the cipher is not deleted and contains at least one FIDO 2 credential. + * Returns true when the cipher is not archived, not deleted and contains at least one FIDO 2 + * credential. */ val CipherView.isActiveWithFido2Credentials: Boolean - get() = deletedDate == null && !(login?.fido2Credentials.isNullOrEmpty()) + get() = archivedDate == null && + deletedDate == null && + !(login?.fido2Credentials.isNullOrEmpty()) /** - * Returns true when the cipher is not deleted and contains at least one Password credential. + * Returns true when the cipher is not archived, not deleted and contains at least one Password + * credential. */ val CipherView.isActiveWithPasswordCredentials: Boolean - get() = deletedDate == null && !(login?.password.isNullOrEmpty()) + get() = archivedDate == null && deletedDate == null && !(login?.password.isNullOrEmpty()) diff --git a/app/src/test/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherListViewExtensionsTest.kt b/app/src/test/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherListViewExtensionsTest.kt index 282490a49c..94c0f7f5b5 100644 --- a/app/src/test/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherListViewExtensionsTest.kt +++ b/app/src/test/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherListViewExtensionsTest.kt @@ -62,7 +62,48 @@ class CipherListViewExtensionsTest { @Suppress("MaxLineLength") @Test - fun `isActiveWithFido2Credentials should return true when Fido2 credentials are present and cipher is not deleted`() { + fun `isActiveWithCopyablePassword should return true when copyable fields contains LOGIN_PASSWORD and cipher is not deleted or archived`() { + val cipherListView = createMockCipherListView( + number = 1, + type = CipherListViewType.Login(v1 = createMockLoginListView(number = 1)), + ) + assertTrue(cipherListView.isActiveWithCopyablePassword) + } + + @Suppress("MaxLineLength") + @Test + fun `isActiveWithCopyablePassword should return false copyable fields does not contain LOGIN_PASSWORD`() { + val cipherListView = createMockCipherListView( + number = 1, + copyableFields = emptyList(), + type = CipherListViewType.Login(v1 = createMockLoginListView(number = 1)), + ) + assertFalse(cipherListView.isActiveWithCopyablePassword) + } + + @Test + fun `isActiveWithCopyablePassword should return false when cipher is archived`() { + val cipherListView = createMockCipherListView( + number = 1, + type = CipherListViewType.Login(v1 = createMockLoginListView(number = 1)), + isArchived = true, + ) + assertFalse(cipherListView.isActiveWithCopyablePassword) + } + + @Test + fun `isActiveWithCopyablePassword should return false when cipher is deleted`() { + val cipherListView = createMockCipherListView( + number = 1, + type = CipherListViewType.Login(v1 = createMockLoginListView(number = 1)), + isDeleted = true, + ) + assertFalse(cipherListView.isActiveWithCopyablePassword) + } + + @Suppress("MaxLineLength") + @Test + fun `isActiveWithFido2Credentials should return true when Fido2 credentials are present and cipher is not deleted or archived`() { val cipherListView = createMockCipherListView( number = 1, type = CipherListViewType.Login( @@ -90,6 +131,21 @@ class CipherListViewExtensionsTest { assertFalse(cipherListView.isActiveWithFido2Credentials) } + @Test + fun `isActiveWithFido2Credentials should return false when cipher is archived`() { + val cipherListView = createMockCipherListView( + number = 1, + type = CipherListViewType.Login( + createMockLoginListView( + number = 1, + hasFido2 = true, + ), + ), + isArchived = true, + ) + assertFalse(cipherListView.isActiveWithFido2Credentials) + } + @Test fun `isActiveWithFido2Credentials should return false when cipher is deleted`() { val cipherListView = createMockCipherListView( diff --git a/app/src/test/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherViewExtensionsTest.kt b/app/src/test/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherViewExtensionsTest.kt index 7fd598fdb1..75a420f760 100644 --- a/app/src/test/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherViewExtensionsTest.kt +++ b/app/src/test/kotlin/com/x8bit/bitwarden/data/autofill/util/CipherViewExtensionsTest.kt @@ -142,7 +142,7 @@ class CipherViewExtensionsTest { @Suppress("MaxLineLength") @Test - fun `isActiveWithFido2Credentials should return true when type is login, deleted date is null, and fido2 credentials are not null`() { + fun `isActiveWithFido2Credentials should return true when type is login, deleted and archived date is null, and fido2 credentials are not null`() { assertTrue( createMockCipherView( number = 1, @@ -152,6 +152,13 @@ class CipherViewExtensionsTest { ) } + @Test + fun `isActiveWithFido2Credentials should return false when archive date is not null`() { + assertFalse( + createMockCipherView(number = 1, isArchived = true).isActiveWithFido2Credentials, + ) + } + @Test fun `isActiveWithFido2Credentials should return false when deleted date is not null`() { assertFalse( @@ -187,7 +194,7 @@ class CipherViewExtensionsTest { @Suppress("MaxLineLength") @Test - fun `isActiveWithPasswordCredentials should return true when type is login, deleted date is null, and password credentials are not empty`() { + fun `isActiveWithPasswordCredentials should return true when type is login, deleted and archived date is null, and password credentials are not empty`() { assertTrue( createMockCipherView( number = 1, @@ -197,6 +204,13 @@ class CipherViewExtensionsTest { ) } + @Test + fun `isActiveWithPasswordCredentials should return false when archive date is not null`() { + assertFalse( + createMockCipherView(number = 1, isArchived = true).isActiveWithPasswordCredentials, + ) + } + @Test fun `isActiveWithPasswordCredentials should return false when deleted date is not null`() { assertFalse(