fix(stepfunctions): decode intrinsic literal escapes (#9378)

This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-11-24 16:10:23 -04:00
1 parent 941a700f60
commit 7af9847813
3 files changed
+187 -10

No files matched your search

@@ -0,0 +1,69 @@
package io.floci.aws.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class AslExecutorIntrinsicEscapesTest {
private final ObjectMapper mapper = new ObjectMapper();
private AslExecutor executor;
@BeforeEach
@SuppressWarnings("unchecked")
void setUp() {
executor = AslExecutorFixture.builder()
.objectMapper(mapper)
.customResourceLiveness(null)
.build();
}
@Test
void escapedApostropheDoesNotEndTheFormatLiteral() throws Exception {
JsonNode input = mapper.readTree("{\"firstName\":\"Ann\",\"lastName\":\"Lee\"}");
JsonNode result = executor.resolvePath(
"States.Format('Welcome to {} {}\\'s playlist.', $.firstName, $.lastName)", input);
assertEquals("Welcome to Ann Lee's playlist.", result.asText());
}
@Test
void escapedBracesAreLiteralTextNotPlaceholders() throws Exception {
JsonNode input = mapper.readTree("{\"name\":\"Ann\"}");
assertEquals("{ Ann }", executor.resolvePath(
"States.Format('\\{ {} \\}', $.name)", input).asText());
assertEquals("{} Ann", executor.resolvePath(
"States.Format('\\{\\} {}', $.name)", input).asText());
}
@Test
void escapedApostropheAndBackslashWorkInOtherIntrinsics() {
JsonNode result = executor.resolvePath("States.Array('it\\'s', 'C:\\\\', 'x')",
mapper.createObjectNode());
assertEquals(3, result.size());
assertEquals("it's", result.get(0).asText());
assertEquals("C:\\", result.get(1).asText());
assertEquals("x", result.get(2).asText());
}
@Test
void pathValuesAreNotDecodedAsIntrinsicLiterals() throws Exception {
JsonNode input = mapper.readTree("{\"value\":\"\\\\{\\\\}\\\\'\"}");
assertEquals("\\{\\}\\'", executor.resolvePath("States.Array($.value)", input).get(0).asText());
}
@Test
void unreservedBackslashSequenceKeepsItsExistingMeaning() throws Exception {
JsonNode input = mapper.readTree("{\"name\":\"Ann\"}");
assertEquals("a\\q", executor.resolvePath("States.Array('a\\q')", input).get(0).asText());
assertEquals("\\q Ann", executor.resolvePath("States.Format('\\q {}', $.name)", input).asText());
}
}
@@ -0,0 +1,75 @@
package io.floci.aws.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sfn.SfnClient;
import software.amazon.awssdk.services.sfn.model.DescribeExecutionResponse;
import java.net.URI;
import java.time.Duration;
import java.util.UUID;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
@QuarkusTest
class StepFunctionsIntrinsicEscapesIntegrationTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
@BeforeAll
static void configure() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@Test
void sdkExecutionDecodesIntrinsicLiterals() throws Exception {
ObjectNode parameters = MAPPER.createObjectNode();
parameters.put("greeting.$", "States.Format('Welcome to {} {}\\'s playlist.', $.firstName, $.lastName)");
parameters.put("braces.$", "States.Format('\\{ {} \\}', $.firstName)");
parameters.put("array.$", "States.Array('it\\'s', 'C:\\\\')");
ObjectNode pass = MAPPER.createObjectNode().put("Type", "Pass").put("End", true);
pass.set("Parameters", parameters);
ObjectNode states = MAPPER.createObjectNode();
states.set("Format", pass);
ObjectNode definition = MAPPER.createObjectNode().put("StartAt", "Format");
definition.set("States", states);
try (SfnClient client = SfnClient.builder()
.endpointOverride(URI.create("http://localhost:" + RestAssured.port))
.httpClientBuilder(UrlConnectionHttpClient.builder())
.region(Region.US_EAST_1)
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("test", "test")))
.build()) {
String arn = client.createStateMachine(request -> request.name("intrinsic-escapes-" + UUID.randomUUID())
.roleArn("arn:aws:iam::000000000000:role/test-role")
.definition(definition.toString())).stateMachineArn();
try {
String execution = client.startExecution(request -> request.stateMachineArn(arn)
.input("{\"firstName\":\"Ann\",\"lastName\":\"Lee\"}"))
.executionArn();
await().atMost(Duration.ofSeconds(10)).until(() -> !"RUNNING".equals(client.describeExecution(
request -> request.executionArn(execution)).statusAsString()));
DescribeExecutionResponse result = client.describeExecution(request -> request.executionArn(execution));
assertEquals("SUCCEEDED", result.statusAsString(), result.toString());
JsonNode output = MAPPER.readTree(result.output());
assertEquals("Welcome to Ann Lee's playlist.", output.path("greeting").asText());
assertEquals("{ Ann }", output.path("braces").asText());
assertEquals("it's", output.path("array").get(0).asText());
assertEquals("C:\\", output.path("array").get(1).asText());
} finally {
client.deleteStateMachine(request -> request.stateMachineArn(arn));
}
}
}
}