test(stepfunctions): cover Lambda mapping SDK Uuid validation (#7701)

Pin JSONPath and JSONata mapping updates, state transitions, and response casing. Consolidate invalid request coverage and reject the legacy UUID spelling with the expected error message.

Related to floci-io/floci#7697; the runtime fix landed in #7720.
This commit is contained in:
jwoa95 authored and GitHub committed 2026-11-09 13:51:54 -04:00
1 parent 92eff0aca5
commit c2d7456dda
3 files changed
+50 -18

No files matched your search

@@ -9,6 +9,8 @@ import io.floci.aws.services.lambda.LambdaController;
import io.floci.aws.services.secretsmanager.SecretsManagerJsonHandler;
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.ArgumentCaptor;
import static org.junit.jupiter.api.Assertions.*;
@@ -25,20 +27,35 @@ class SdkManagementTaskInvokerTest {
lambda, mock(SecretsManagerJsonHandler.class), registry, mapper);
@Test
void usesSdkUuidWithoutChangingTheLambdaRequestBodyOrInput() throws Exception {
void lambdaMappingUpdateUsesSdkUuidWithoutMutatingTheTaskInput() throws Exception {
when(registry.isServiceEnabled("lambda")).thenReturn(true);
when(lambda.updateEventSourceMapping(eq("mapping-id"), anyString()))
.thenReturn(Response.ok(mapper.readTree("{\"UUID\":\"mapping-id\",\"State\":\"Disabled\"}")).build());
JsonNode input = mapper.readTree("{\"Uuid\":\"mapping-id\",\"Enabled\":false,\"BatchSize\":3}");
JsonNode request = mapper.readTree("{\"Uuid\":\"mapping-id\",\"Enabled\":false,\"BatchSize\":3}");
JsonNode result = invoker.invoke(StatesIntegration.parse(
"arn:aws:states:::aws-sdk:lambda:updateEventSourceMapping").orElseThrow(), input, "eu-west-2");
JsonNode result = invoker.invoke(lambdaMappingIntegration(), request, "eu-west-2");
ArgumentCaptor<String> body = ArgumentCaptor.forClass(String.class);
verify(lambda).updateEventSourceMapping(eq("mapping-id"), body.capture());
assertEquals(mapper.readTree("{\"Enabled\":false,\"BatchSize\":3}"), mapper.readTree(body.getValue()));
assertEquals("mapping-id", input.path("Uuid").asText());
assertEquals("mapping-id", request.path("Uuid").asText());
assertEquals("mapping-id", result.path("UUID").asText());
assertEquals("Disabled", result.path("State").asText());
}
@ParameterizedTest
@ValueSource(strings = {"{}", "{\"Uuid\":null}", "{\"Uuid\":\"\"}", "{\"Uuid\":\" \"}",
"{\"UUID\":\"mapping-id\"}"})
void lambdaMappingUpdateRejectsInvalidSdkUuidRequests(String requestJson) throws Exception {
when(registry.isServiceEnabled("lambda")).thenReturn(true);
JsonNode request = mapper.readTree(requestJson);
AslExecutor.FailStateException error = assertThrows(AslExecutor.FailStateException.class,
() -> invoker.invoke(lambdaMappingIntegration(), request, "eu-west-2"));
assertEquals("Lambda.InvalidParameterValueException", error.error);
assertEquals("Uuid is required.", error.cause);
verifyNoInteractions(lambda);
}
@Test
@@ -106,4 +123,8 @@ class SdkManagementTaskInvokerTest {
private static StatesIntegration integration() {
return StatesIntegration.parse("arn:aws:states:::aws-sdk:ecs:updateService").orElseThrow();
}
private static StatesIntegration lambdaMappingIntegration() {
return StatesIntegration.parse("arn:aws:states:::aws-sdk:lambda:updateEventSourceMapping").orElseThrow();
}
}
@@ -126,14 +126,22 @@ class StepFunctionsSdkManagementIntegrationTest {
try {
JsonNode listed = task("lambda", "listEventSourceMappings", Map.of("FunctionName", function), region, "aws");
assertEquals(uuid, listed.path("EventSourceMappings").get(0).path("UUID").asText());
JsonNode updated = runTask("lambda", "updateEventSourceMapping", Map.of("Uuid", uuid,
"Enabled", false, "BatchSize", 3), region, "aws", ACCOUNT, false, queryLanguage);
assertEquals(uuid, updated.path("UUID").asText());
assertEquals(3, updated.path("BatchSize").asInt());
assertEquals("Disabled", updated.path("State").asText());
assertTrue(updated.path("LastModified").isTextual());
assertEquals(3, lambda("get", "/2015-03-31/event-source-mappings/" + uuid, Map.of(), region)
.<Integer>path("BatchSize"));
boolean jsonata = "JSONata".equals(queryLanguage);
for (boolean enabled : List.of(true, false)) {
JsonNode updated = runTask("lambda", "updateEventSourceMapping", Map.of(
jsonata ? "Uuid" : "Uuid.$", jsonata ? "{% $states.input.mappingId %}" : "$.mappingId",
"Enabled", enabled, "BatchSize", 3), region, "aws", ACCOUNT, false,
queryLanguage, Map.of("mappingId", uuid));
assertEquals(uuid, updated.path("UUID").asText());
assertEquals(3, updated.path("BatchSize").asInt());
String state = enabled ? "Enabled" : "Disabled";
assertEquals(state, updated.path("State").asText());
assertTrue(updated.path("LastModified").isTextual());
Response mapping = lambda("get", "/2015-03-31/event-source-mappings/" + uuid, Map.of(), region);
assertEquals(uuid, mapping.path("UUID"));
assertEquals(3, mapping.<Integer>path("BatchSize"));
assertEquals(state, mapping.path("State"));
}
JsonNode pagination = runTask("lambda", "listEventSourceMappings", Map.of("FunctionName", function,
"MaxItems", 1), region, "aws", ACCOUNT, true);
assertEquals("Lambda.InvalidParameterValueException", pagination.path("Error").asText());
@@ -153,12 +161,12 @@ class StepFunctionsSdkManagementIntegrationTest {
private static JsonNode runTask(String service, String action, Map<String, Object> parameters,
String region, String partition, String account, boolean catchError) throws Exception {
return runTask(service, action, parameters, region, partition, account, catchError, "JSONPath");
return runTask(service, action, parameters, region, partition, account, catchError, "JSONPath", Map.of());
}
private static JsonNode runTask(String service, String action, Map<String, Object> parameters,
String region, String partition, String account, boolean catchError,
String queryLanguage) throws Exception {
String queryLanguage, Map<String, Object> input) throws Exception {
ObjectNode task = MAPPER.createObjectNode().put("Type", "Task").put("End", true)
.put("Resource", "arn:" + partition + ":states:::aws-sdk:" + service + ":" + action);
task.set("JSONata".equals(queryLanguage) ? "Arguments" : "Parameters", MAPPER.valueToTree(parameters));
@@ -181,7 +189,8 @@ class StepFunctionsSdkManagementIntegrationTest {
.roleArn("arn:" + partition + ":iam::" + account + ":role/test-role")
.definition(definition.toString())).stateMachineArn();
try {
String execution = client.startExecution(request -> request.stateMachineArn(arn).input("{}"))
String execution = client.startExecution(request -> request.stateMachineArn(arn)
.input(MAPPER.valueToTree(input).toString()))
.executionArn();
await().atMost(Duration.ofSeconds(10)).until(() -> !"RUNNING".equals(client.describeExecution(
request -> request.executionArn(execution)).statusAsString()));