Skip to content

Commit 054bca1

Browse files
committed
Add sensitive field to inputText to remove sensitive data from output and logs
fixes mobile-dev-inc#1226
1 parent 5cb09ff commit 054bca1

File tree

7 files changed

+47
-6
lines changed

7 files changed

+47
-6
lines changed

maestro-client/src/main/java/maestro/Maestro.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,13 @@ class Maestro(
477477
return driver.waitForAppToSettle(initialHierarchy, appId, waitToSettleTimeoutMs)
478478
}
479479

480-
fun inputText(text: String) {
481-
LOGGER.info("Inputting text: $text")
480+
fun inputText(text: String, sensitive: Boolean = false) {
481+
LOGGER.info("Inputting text:".let {
482+
if (sensitive)
483+
"$it ${"".padEnd(text.length, '*')}"
484+
else
485+
"$it $text"
486+
})
482487

483488
driver.inputText(text)
484489
waitForAppToSettle()

maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,19 +426,38 @@ data class AssertWithAICommand(
426426

427427
data class InputTextCommand(
428428
val text: String,
429+
val sensitive: Boolean = false,
429430
override val label: String? = null,
430431
override val optional: Boolean = false,
431432
) : Command {
432433

433434
override fun description(): String {
434-
return label ?: "Input text $text"
435+
if (label != null) {
436+
return label
437+
}
438+
val defaultLabelPrefix = "Input text "
439+
if (sensitive) {
440+
return defaultLabelPrefix + "".padEnd(text.length, '*')
441+
} else {
442+
return defaultLabelPrefix + text
443+
}
435444
}
436445

437446
override fun evaluateScripts(jsEngine: JsEngine): InputTextCommand {
438447
return copy(
439448
text = text.evaluateScripts(jsEngine)
440449
)
441450
}
451+
452+
override fun toString(): String {
453+
val thisText = if (sensitive) {
454+
"".padEnd(text.length, '*')
455+
} else {
456+
text
457+
}
458+
459+
return "InputTextCommand(text=$thisText, sensitive=$sensitive, label=$label, optional=$optional)"
460+
}
442461
}
443462

444463
data class LaunchAppCommand(

maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ class Orchestra(
836836
}
837837
}
838838

839-
maestro.inputText(command.text)
839+
maestro.inputText(command.text, command.sensitive)
840840

841841
return true
842842
}

maestro-orchestra/src/main/java/maestro/orchestra/yaml/YamlFluentCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ data class YamlFluentCommand(
142142
addMediaCommand = addMediaCommand(addMedia, flowPath)
143143
)
144144
)
145-
inputText != null -> listOf(MaestroCommand(InputTextCommand(text = inputText.text, label = inputText.label, optional = inputText.optional)))
145+
inputText != null -> listOf(MaestroCommand(InputTextCommand(text = inputText.text, sensitive = inputText.sensitive, label = inputText.label, optional = inputText.optional)))
146146
inputRandomText != null -> listOf(MaestroCommand(InputRandomCommand(inputType = InputRandomType.TEXT, length = inputRandomText.length, label = inputRandomText.label, optional = inputRandomText.optional)))
147147
inputRandomNumber != null -> listOf(MaestroCommand(InputRandomCommand(inputType = InputRandomType.NUMBER, length = inputRandomNumber.length, label = inputRandomNumber.label, optional = inputRandomNumber.optional)))
148148
inputRandomEmail != null -> listOf(MaestroCommand(InputRandomCommand(inputType = InputRandomType.TEXT_EMAIL_ADDRESS, label = inputRandomEmail.label, optional = inputRandomEmail.optional)))

maestro-orchestra/src/main/java/maestro/orchestra/yaml/YamlInputText.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import java.lang.UnsupportedOperationException
55

66
data class YamlInputText(
77
val text: String,
8+
val sensitive: Boolean = false,
89
val label: String? = null,
910
val optional: Boolean = false,
1011
) {
@@ -18,8 +19,10 @@ data class YamlInputText(
1819
is String -> text
1920
is Map<*, *> -> {
2021
val input = text.getOrDefault("text", "") as String
22+
val sensitive = text.getOrDefault("sensitive", false) as Boolean
2123
val label = text.getOrDefault("label", null) as String?
22-
return YamlInputText(input, label)
24+
val optional = text.getOrDefault("optional", false) as Boolean
25+
return YamlInputText(text = input, sensitive = sensitive, label = label, optional = optional)
2326
}
2427
is Int, is Long, is Char, is Boolean, is Float, is Double -> text.toString()
2528
else -> throw UnsupportedOperationException("Cannot deserialize input text with data type ${text.javaClass}")

maestro-orchestra/src/test/java/maestro/orchestra/MaestroCommandSerializationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ internal class MaestroCommandSerializationTest {
266266
{
267267
"inputTextCommand" : {
268268
"text" : "Hello, world!",
269+
"sensitive" : false,
269270
"optional" : false
270271
}
271272
}

maestro-orchestra/src/test/java/maestro/orchestra/MaestroCommandTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ internal class MaestroCommandTest {
5656
.isEqualTo("Set location with negative coordinates")
5757
}
5858

59+
@Test
60+
fun `description (sensitive text)`() {
61+
// given
62+
val maestroCommand = MaestroCommand(InputTextCommand("password", true))
63+
64+
// when
65+
val description = maestroCommand.description()
66+
67+
// then
68+
assertThat(description)
69+
.isEqualTo("Input text ********")
70+
}
71+
5972
@Test
6073
fun `toString (no commands)`() {
6174
// given

0 commit comments

Comments
 (0)