From 2726206a8ac2a6e4e540d29c97b274170417bd9c Mon Sep 17 00:00:00 2001 From: Tarek Belkahia Date: Sat, 24 Aug 2024 18:50:46 +0100 Subject: [PATCH] Replace input text with redacted version in TestDebugReporter --- .../maestro/cli/report/TestDebugReporter.kt | 4 ++++ .../src/main/java/maestro/orchestra/Commands.kt | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/maestro-cli/src/main/java/maestro/cli/report/TestDebugReporter.kt b/maestro-cli/src/main/java/maestro/cli/report/TestDebugReporter.kt index 7a5600d189..d555d04be1 100644 --- a/maestro-cli/src/main/java/maestro/cli/report/TestDebugReporter.kt +++ b/maestro-cli/src/main/java/maestro/cli/report/TestDebugReporter.kt @@ -14,6 +14,7 @@ import maestro.debuglog.DebugLogStore import maestro.debuglog.LogConfig import maestro.orchestra.MaestroCommand import org.slf4j.LoggerFactory +import com.fasterxml.jackson.databind.module.SimpleModule import java.io.File import java.nio.file.Files import java.nio.file.Path @@ -28,6 +29,7 @@ import java.util.IdentityHashMap import java.util.Properties import kotlin.io.path.absolutePathString import kotlin.io.path.exists +import maestro.orchestra.InputTextCommand object TestDebugReporter { @@ -43,6 +45,8 @@ object TestDebugReporter { // json mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY) + val module = SimpleModule().addSerializer(InputTextCommand.Serializer()) + mapper.registerModule(module) } fun saveFlow(flowName: String, data: FlowDebugMetadata, path: Path) { diff --git a/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt b/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt index 27b911c729..e69477d7a2 100644 --- a/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt +++ b/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt @@ -19,6 +19,9 @@ package maestro.orchestra +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.ser.std.StdSerializer import maestro.KeyCode import maestro.Point import maestro.ScrollDirection @@ -385,6 +388,20 @@ data class InputTextCommand( override fun toString(): String { return "InputTextCommand(text=$redacted,label=$label)" } + + class Serializer : StdSerializer { + + constructor() : super(InputTextCommand::class.java) + constructor(item: Class) : super(item) + + override fun serialize(value: InputTextCommand, gen: JsonGenerator, provider: SerializerProvider) = with (gen) { + writeStartObject() + writeStringField("text", value.redacted) + if (value.label != null) writeStringField("label", value.label) + if (value.redact) writeBooleanField("redact", true) + writeEndObject() + } + } } data class LaunchAppCommand(