Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ data class CustomField(
val type: String,
val value: String
) {
/**
* Whether this field holds a secret value. Secret fields are masked in the UI and
* should be marked as sensitive when copied, so the system keeps them out of the
* clipboard preview and history (Android 13+), just like the account password.
*/
val isSensitive: Boolean
get() = type == TYPE_SECRET

companion object {
const val TYPE_TEXT = "text"
const val TYPE_SECRET = "secret"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ fun PasswordItemContent(
},
trailingIcon = {
IconButton(onClick = {
context.copyToClipboard(customField.value)
context.copyToClipboard(customField.value, isSensitive = customField.isSensitive)
Toast.makeText(
context,
String.format(copiedText, customField.label),
Expand Down Expand Up @@ -378,7 +378,7 @@ fun PasswordItemContent(
},
trailingIcon = {
IconButton(onClick = {
context.copyToClipboard(customField.value)
context.copyToClipboard(customField.value, isSensitive = customField.isSensitive)
Toast.makeText(
context,
String.format(copiedText, customField.label),
Expand Down Expand Up @@ -409,7 +409,7 @@ fun PasswordItemContent(
},
trailingIcon = {
IconButton(onClick = {
context.copyToClipboard(customField.value)
context.copyToClipboard(customField.value, isSensitive = customField.isSensitive)
Toast.makeText(
context,
String.format(copiedText, customField.label),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hegocre.nextcloudpasswords.data.password

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

/**
* Unit test for [CustomField.isSensitive], which decides whether a custom field value
* must be flagged as sensitive when copied to the clipboard.
*/
class CustomFieldTest {
private fun field(type: String) = CustomField(label = "label", type = type, value = "value")

@Test
fun secretFieldIsSensitive() {
assertTrue(field(CustomField.TYPE_SECRET).isSensitive)
}

@Test
fun nonSecretFieldsAreNotSensitive() {
assertFalse(field(CustomField.TYPE_TEXT).isSensitive)
assertFalse(field(CustomField.TYPE_EMAIL).isSensitive)
assertFalse(field(CustomField.TYPE_URL).isSensitive)
assertFalse(field(CustomField.TYPE_FILE).isSensitive)
assertFalse(field(CustomField.TYPE_DATA).isSensitive)
}

@Test
fun unknownTypeIsNotSensitive() {
assertFalse(field("something-else").isSensitive)
}
}