Light, fluffy, and always free - The AWS Local Emulator alternative
fix(eventbridge): default and validate ECS target settings (#6420)
Aniket Shukla9e1254797879
diff --git a/docs/services/eventbridge.md b/docs/services/eventbridge.mdindex 5ccba35503..ce7ddb1e24 100644--- a/docs/services/eventbridge.md+++ b/docs/services/eventbridge.md@@ -95,6 +95,17 @@ aws events put-events \--endpoint-url $AWS_ENDPOINT_URL```+## Target Settings++`PutTargets` defaults omitted ECS `TaskCount` to `1`, and `EnableECSManagedTags` and+`EnableExecuteCommand` to `false`. Explicit values are preserved. A task count below+one or a malformed target `RoleArn` or `DeadLetterConfig.Arn` returns a+`ValidationException` before any targets in the request are stored.+Role ARNs must identify an IAM role with a non-empty name; dead-letter ARNs must+identify an SQS queue with a region. Both require a published AWS partition and a+12-digit account ID. Queue names are limited to 80 characters, including a FIFO+suffix when present. These checks do not verify resource existence or permissions.+## Default Event BusEventBridge includes a default event bus (`default`) that accepts events from AWS services. Custom buses are for your own application events.diff --git a/pom.xml b/pom.xmlindex 31c62f94aa..c4c4ae8029 100644--- a/pom.xml+++ b/pom.xml@@ -330,6 +330,12 @@</dependency><!-- Testing -->+ <dependency>+ <groupId>software.amazon.awssdk</groupId>+ <artifactId>eventbridge</artifactId>+ <version>${aws.sdk.version}</version>+ <scope>test</scope>+ </dependency><dependency><groupId>software.amazon.awssdk</groupId><artifactId>iotdataplane</artifactId>diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsArnShapes.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsArnShapes.javanew file mode 100644index 0000000000..e7a8b73e74--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsArnShapes.java@@ -0,0 +1,22 @@+package io.github.hectorvent.floci.core.common;++import java.util.regex.Pattern;++/** Resource shapes shared by services; account, partition and API error rules stay with callers. */+public final class AwsArnShapes {++ private static final Pattern SQS_QUEUE_NAME = Pattern.compile("[A-Za-z0-9_-]{1,80}|[A-Za-z0-9_-]{1,75}\\.fifo");++ private AwsArnShapes() {+ }++ public static boolean isIamRole(AwsArnUtils.Arn arn) {+ return "iam".equals(arn.service()) && arn.region().isEmpty()+ && !arn.accountId().isBlank() && arn.resource().startsWith("role/")+ && !arn.resource().substring(5).isBlank();+ }++ public static boolean isSqsQueueName(String name) {+ return name != null && SQS_QUEUE_NAME.matcher(name).matches();+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizer.java b/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizer.javaindex f1a58ddeb9..0dc331f8a3 100644--- a/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizer.java+++ b/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizer.java@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.appsync.graphql.datasource;import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import io.github.hectorvent.floci.config.EmulatorConfig;+import io.github.hectorvent.floci.core.common.AwsArnShapes;import io.github.hectorvent.floci.core.common.AwsArnUtils;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.common.RegionResolver;@@ -63,8 +64,7 @@ public class AppSyncDataSourceAuthorizer {} catch (IllegalArgumentException e) {throw denied(dataSource, "serviceRoleArn is not an IAM role ARN");}- if (!"iam".equals(roleId.service()) || !roleId.region().isEmpty()- || roleId.accountId().isBlank() || !roleId.resource().startsWith("role/")+ if (!AwsArnShapes.isIamRole(roleId)|| roleId.resource().endsWith("/")) {throw denied(dataSource, "serviceRoleArn is not an IAM role ARN");}diff --git a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.javaindex 7f7ce8a7bc..b56d85dda2 100644--- a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java+++ b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java@@ -11,8 +11,10 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;import com.fasterxml.jackson.databind.node.ObjectNode;import com.fasterxml.jackson.databind.node.TextNode;import io.github.hectorvent.floci.config.EmulatorConfig;+import io.github.hectorvent.floci.core.common.AwsArnShapes;import io.github.hectorvent.floci.core.common.AwsArnUtils;import io.github.hectorvent.floci.core.common.AwsException;+import io.github.hectorvent.floci.core.common.AwsPartitions;import io.github.hectorvent.floci.core.common.PaginatedResult;import io.github.hectorvent.floci.core.common.Pagination;import io.github.hectorvent.floci.core.common.RegionResolver;@@ -30,6 +32,7 @@ import io.github.hectorvent.floci.services.eventbridge.model.ArchiveState;import io.github.hectorvent.floci.services.eventbridge.model.ArchivedEvent;import io.github.hectorvent.floci.services.eventbridge.model.Connection;import io.github.hectorvent.floci.services.eventbridge.model.ConnectionState;+import io.github.hectorvent.floci.services.eventbridge.model.EcsParameters;import io.github.hectorvent.floci.services.eventbridge.model.EventBus;import io.github.hectorvent.floci.services.eventbridge.model.Replay;import io.github.hectorvent.floci.services.eventbridge.model.ReplayState;@@ -461,6 +464,12 @@ public class EventBridgeService implements ResourceProvider {"Rule not found: " + ruleName, 400));List<Target> existing = new ArrayList<>(targetStore.get(key).orElse(new ArrayList<>()));for (Target newTarget : newTargets) {+ EcsParameters ecs = newTarget.getEcsParameters();+ if (ecs != null) {+ ecs.setTaskCount(ecs.getTaskCount() == null ? 1 : ecs.getTaskCount());+ ecs.setEnableECSManagedTags(ecs.getEnableECSManagedTags() == null ? false : ecs.getEnableECSManagedTags());+ ecs.setEnableExecuteCommand(ecs.getEnableExecuteCommand() == null ? false : ecs.getEnableExecuteCommand());+ }if (newTarget.getRoleArn() == null && isCrossAccountEventBus(newTarget.getArn(), rule)) {existing.stream().filter(t -> t.getId().equals(newTarget.getId()) && newTarget.getArn().equals(t.getArn()))@@ -490,10 +499,15 @@ public class EventBridgeService implements ResourceProvider {Integer attempts = target.getRetryPolicy() != null ? target.getRetryPolicy().maximumRetryAttempts() : null;Integer age = target.getRetryPolicy() != null ? target.getRetryPolicy().maximumEventAgeInSeconds() : null;String arn = target.getDeadLetterConfig() != null ? target.getDeadLetterConfig().arn() : null;+ Integer taskCount = target.getEcsParameters() != null ? target.getEcsParameters().getTaskCount() : null;String field = null;Object value = null;String constraint = null;- if (attempts != null && (attempts < 0 || attempts > 185)) {+ if (taskCount != null && taskCount < 1) {+ field = "ecsParameters.taskCount";+ value = taskCount;+ constraint = "value greater than or equal to 1";+ } else if (attempts != null && (attempts < 0 || attempts > 185)) {field = "retryPolicy.maximumRetryAttempts";value = attempts;constraint = attempts < 0 ? "value greater than or equal to 0" : "value less than or equal to 185";@@ -517,7 +531,27 @@ public class EventBridgeService implements ResourceProvider {+ "' at 'targets." + (i + 1) + ".member." + field+ "' failed to satisfy constraint: Member must have " + constraint);}+ validateTargetArn(target.getRoleArn(), "iam");+ validateTargetArn(arn, "sqs");+ }+ }++ private static void validateTargetArn(String arn, String service) {+ if (arn == null) {+ return;+ }+ if (AwsArnUtils.isArnFor(arn, service)) {+ AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);+ boolean resourceValid = "iam".equals(service)+ ? AwsArnShapes.isIamRole(parsed) && !parsed.resource().endsWith("/")+ : !parsed.region().isBlank() && AwsArnShapes.isSqsQueueName(parsed.resource());+ if (AwsPartitions.find(parsed.partition()).isPresent()+ && parsed.accountId().matches("[0-9]{12}") && resourceValid) {+ return;+ }}+ throw new AwsException("ValidationException",+ "Parameter " + arn + " is not valid. Reason: Provided Arn is not in correct format.", 400);}public record RemoveTargetsResult(int successfulCount, int failedCount) {}diff --git a/src/main/java/io/github/hectorvent/floci/services/lakeformation/LakeFormationService.java b/src/main/java/io/github/hectorvent/floci/services/lakeformation/LakeFormationService.javaindex 2789972afa..46fe57b21a 100644--- a/src/main/java/io/github/hectorvent/floci/services/lakeformation/LakeFormationService.java+++ b/src/main/java/io/github/hectorvent/floci/services/lakeformation/LakeFormationService.java@@ -1,5 +1,6 @@package io.github.hectorvent.floci.services.lakeformation;+import io.github.hectorvent.floci.core.common.AwsArnShapes;import io.github.hectorvent.floci.core.common.AwsArnUtils;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.common.RegionResolver;@@ -93,11 +94,7 @@ public class LakeFormationService {try {AwsArnUtils.Arn parsed = AwsArnUtils.parse(roleArn);if (parsed.partition().isBlank()- || !"iam".equals(parsed.service())- || !parsed.region().isEmpty()- || parsed.accountId().isBlank()- || !parsed.resource().startsWith("role/")- || parsed.resource().length() == "role/".length()+ || !AwsArnShapes.isIamRole(parsed)|| roleArn.chars().anyMatch(Character::isWhitespace)) {throw new IllegalArgumentException("Invalid IAM role ARN");}diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.javaindex f5ee3aad87..34b29ca25e 100644--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.node.ObjectNode;import io.github.hectorvent.floci.config.EmulatorConfig;+import io.github.hectorvent.floci.core.common.AwsArnShapes;import io.github.hectorvent.floci.core.common.AwsArnUtils;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.common.AwsNamespaces;@@ -5332,8 +5333,7 @@ public class S3Service implements Resettable, ResourceProvider {throw invalidNotificationArn(arn, argumentName);}boolean validResource = switch (service) {- case "sqs" -> parsed.resource().matches("[A-Za-z0-9_-]{1,80}")- || parsed.resource().matches("[A-Za-z0-9_-]{1,75}\\.fifo");+ case "sqs" -> AwsArnShapes.isSqsQueueName(parsed.resource());case "sns" -> parsed.resource().matches("[A-Za-z0-9_-]{1,256}")|| parsed.resource().matches("[A-Za-z0-9_-]{1,251}\\.fifo");case "lambda" -> parsed.resource().matches(diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.javaindex d6d2c4dd8e..b647e4b083 100644--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java@@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.type.TypeReference;import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.node.ObjectNode;+import io.github.hectorvent.floci.core.common.AwsArnShapes;import io.github.hectorvent.floci.core.common.AwsArnUtils;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.common.AwsRegions;@@ -2073,13 +2074,7 @@ public class StepFunctionsService implements Resettable, ResourceProvider {}try {AwsArnUtils.Arn parsed = AwsArnUtils.parse(roleArn);- String resource = parsed.resource();- if (!"iam".equals(parsed.service())- || !parsed.region().isEmpty()- || parsed.accountId().isBlank()- || resource == null- || !resource.startsWith("role/")- || resource.length() == "role/".length()+ if (!AwsArnShapes.isIamRole(parsed)|| roleArn.chars().anyMatch(Character::isWhitespace)) {throw new IllegalArgumentException("Invalid IAM role ARN");}diff --git a/src/test/java/io/github/hectorvent/floci/core/common/AwsArnShapesTest.java b/src/test/java/io/github/hectorvent/floci/core/common/AwsArnShapesTest.javanew file mode 100644index 0000000000..f4ae78b2a0--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/core/common/AwsArnShapesTest.java@@ -0,0 +1,55 @@+package io.github.hectorvent.floci.core.common;++import org.junit.jupiter.api.Test;+import org.junit.jupiter.params.ParameterizedTest;+import org.junit.jupiter.params.provider.CsvSource;+import org.junit.jupiter.params.provider.NullAndEmptySource;+import org.junit.jupiter.params.provider.ValueSource;++import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertFalse;+import static org.junit.jupiter.api.Assertions.assertTrue;++class AwsArnShapesTest {++ @ParameterizedTest+ @ValueSource(strings = {"aws", "aws-us-gov", "aws-cn", "aws-iso", "aws-iso-b", "aws-iso-e", "aws-iso-f", "aws-eusc"})+ void iamRolePathsWorkAcrossPartitions(String partition) {+ assertTrue(AwsArnShapes.isIamRole(AwsArnUtils.parse(+ "arn:" + partition + ":iam::000000000000:role/service-role/application")));+ }++ @ParameterizedTest+ @ValueSource(strings = {+ "arn:aws:sts::000000000000:role/example",+ "arn:aws:iam:us-east-1:000000000000:role/example",+ "arn:aws:iam:::role/example",+ "arn:aws:iam::000000000000:user/example",+ "arn:aws:iam::000000000000:role/",+ "arn:aws:iam::000000000000:role/ ",+ "arn:aws:iam::000000000000:"+ })+ void rejectsNonRoleShapes(String value) {+ assertFalse(AwsArnShapes.isIamRole(AwsArnUtils.parse(value)));+ }++ @Test+ void accountAndPartitionPoliciesRemainWithCallers() {+ assertTrue(AwsArnShapes.isIamRole(AwsArnUtils.parse("arn:custom:iam::123:role/example")));+ }++ @ParameterizedTest+ @CsvSource({"1, false, true", "80, false, true", "81, false, false",+ "6, true, true", "80, true, true", "81, true, false"})+ void queueNameLimitIncludesFifoSuffix(int length, boolean fifo, boolean valid) {+ String name = "q".repeat(length - (fifo ? 5 : 0)) + (fifo ? ".fifo" : "");+ assertEquals(valid, AwsArnShapes.isSqsQueueName(name));+ }++ @ParameterizedTest+ @NullAndEmptySource+ @ValueSource(strings = {"queue/name", "queue:name", "queue name", "queue.name", ".fifo"})+ void rejectsInvalidQueueNames(String name) {+ assertFalse(AwsArnShapes.isSqsQueueName(name));+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeEcsTargetSettingsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeEcsTargetSettingsIntegrationTest.javanew file mode 100644index 0000000000..185660184a--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeEcsTargetSettingsIntegrationTest.java@@ -0,0 +1,200 @@+package io.github.hectorvent.floci.services.eventbridge;++import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;+import io.quarkus.test.junit.QuarkusTest;+import io.restassured.RestAssured;+import org.junit.jupiter.api.AfterEach;+import org.junit.jupiter.api.BeforeEach;+import org.junit.jupiter.api.Test;+import org.junit.jupiter.params.ParameterizedTest;+import org.junit.jupiter.params.provider.CsvSource;+import org.junit.jupiter.params.provider.ValueSource;+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.eventbridge.EventBridgeClient;+import software.amazon.awssdk.services.eventbridge.model.EcsParameters;+import software.amazon.awssdk.services.eventbridge.model.RuleState;+import software.amazon.awssdk.services.eventbridge.model.Target;++import java.net.URI;+import java.util.UUID;++import static io.restassured.RestAssured.given;+import static org.hamcrest.Matchers.equalTo;+import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertNull;+import static org.junit.jupiter.api.Assertions.assertTrue;++@QuarkusTest+class EventBridgeEcsTargetSettingsIntegrationTest {++ private static final String ACCOUNT = "741618800001";+ private static final String CLUSTER = "arn:aws:ecs:us-east-1:" + ACCOUNT + ":cluster/test";+ private static final String TASK = "arn:aws:ecs:us-east-1:" + ACCOUNT + ":task-definition/test:1";+ private EventBridgeClient client;+ private String rule;++ @BeforeEach+ void createRule() {+ RestAssuredJsonUtils.configureAwsContentTypes();+ client = EventBridgeClient.builder()+ .endpointOverride(URI.create("http://localhost:" + RestAssured.port))+ .httpClientBuilder(UrlConnectionHttpClient.builder()).region(Region.US_EAST_1)+ .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(ACCOUNT, "test")))+ .build();+ rule = "ecs-settings-" + UUID.randomUUID();+ client.putRule(request -> request.name(rule).eventPattern("{}").state(RuleState.DISABLED));+ }++ @AfterEach+ void deleteRule() {+ try {+ client.removeTargets(request -> request.rule(rule).ids("t1", "t2"));+ client.deleteRule(request -> request.name(rule));+ } finally {+ client.close();+ }+ }++ @Test+ void missingEcsSettingsReadBackWithDefaults() {+ putTarget(EcsParameters.builder().taskDefinitionArn(TASK).build());++ EcsParameters ecs = listedTarget().ecsParameters();+ assertEquals(1, ecs.taskCount());+ assertEquals(Boolean.FALSE, ecs.enableECSManagedTags());+ assertEquals(Boolean.FALSE, ecs.enableExecuteCommand());+ assertEquals(TASK, ecs.taskDefinitionArn());+ assertNull(ecs.launchType());+ assertNull(ecs.group());+ }++ @Test+ void explicitEcsSettingsArePreserved() {+ putTarget(EcsParameters.builder().taskDefinitionArn(TASK).taskCount(3)+ .enableECSManagedTags(true).enableExecuteCommand(true).group("workers").build());++ EcsParameters ecs = listedTarget().ecsParameters();+ assertEquals(3, ecs.taskCount());+ assertEquals(Boolean.TRUE, ecs.enableECSManagedTags());+ assertEquals(Boolean.TRUE, ecs.enableExecuteCommand());+ assertEquals("workers", ecs.group());+ }++ @Test+ void replacementUsesDefaultsForNewlyOmittedSettings() {+ putTarget(EcsParameters.builder().taskDefinitionArn(TASK).taskCount(3)+ .enableECSManagedTags(true).enableExecuteCommand(true).build());+ putTarget(EcsParameters.builder().taskDefinitionArn(TASK).build());++ EcsParameters ecs = listedTarget().ecsParameters();+ assertEquals(1, ecs.taskCount());+ assertEquals(Boolean.FALSE, ecs.enableECSManagedTags());+ assertEquals(Boolean.FALSE, ecs.enableExecuteCommand());+ }++ @Test+ void targetsWithoutEcsParametersStayUnchanged() {+ client.putTargets(request -> request.rule(rule).targets(Target.builder().id("t1")+ .arn("arn:aws:sqs:us-east-1:" + ACCOUNT + ":queue").build()));+ assertNull(listedTarget().ecsParameters());+ }++ @ParameterizedTest+ @ValueSource(ints = {0, -1})+ void invalidTaskCountsRejectTheWholeRequest(int count) {+ assertRejected("\"EcsParameters\":{\"TaskDefinitionArn\":\"" + TASK + "\",\"TaskCount\":" + count + "}",+ "1 validation error detected: Value '" + count+ + "' at 'targets.2.member.ecsParameters.taskCount' failed to satisfy constraint: "+ + "Member must have value greater than or equal to 1");+ }++ @ParameterizedTest+ @ValueSource(strings = {"RoleArn", "DeadLetterConfig"})+ void malformedArnsRejectTheWholeRequest(String field) {+ String value = field.equals("RoleArn") ? "\"not-an-arn\"" : "{\"Arn\":\"not-an-arn\"}";+ assertRejected("\"" + field + "\":" + value,+ "Parameter not-an-arn is not valid. Reason: Provided Arn is not in correct format.");+ }++ @ParameterizedTest+ @CsvSource({+ "RoleArn, arn:::::",+ "DeadLetterConfig, arn:::::",+ "RoleArn, arn::iam::741618800001:role/target",+ "DeadLetterConfig, arn::sqs:us-east-1:741618800001:queue",+ "RoleArn, arn:aws:iam:::role/target",+ "DeadLetterConfig, arn:aws:sqs:us-east-1::queue",+ "RoleArn, arn:aws:iam::123:role/target",+ "DeadLetterConfig, arn:aws:sqs:us-east-1:abcdefghijkl:queue",+ "RoleArn, arn:unknown:iam::741618800001:role/target",+ "DeadLetterConfig, arn:unknown:sqs:us-east-1:741618800001:queue",+ "RoleArn, arn:aws:iam::741618800001:",+ "DeadLetterConfig, arn:aws:sqs:us-east-1:741618800001:",+ "RoleArn, arn:aws:iam:us-east-1:741618800001:role/target",+ "DeadLetterConfig, arn:aws:sqs::741618800001:queue",+ "RoleArn, arn:aws:iam::741618800001:user/target",+ "RoleArn, arn:aws:iam::741618800001:role/",+ "RoleArn, arn:aws:sqs:us-east-1:741618800001:queue",+ "DeadLetterConfig, arn:aws:iam::741618800001:role/target"+ })+ void invalidArnComponentsRejectTheWholeRequest(String field, String arn) {+ String value = field.equals("RoleArn") ? "\"" + arn + "\"" : "{\"Arn\":\"" + arn + "\"}";+ assertRejected("\"" + field + "\":" + value,+ "Parameter " + arn + " is not valid. Reason: Provided Arn is not in correct format.");+ }++ @ParameterizedTest+ @CsvSource({"80, false", "80, true", "81, false", "81, true"})+ void deadLetterQueueNamesRespectTheSqsLengthLimit(int length, boolean fifo) {+ String name = "q".repeat(length - (fifo ? 5 : 0)) + (fifo ? ".fifo" : "");+ String arn = "arn:aws:sqs:us-east-1:" + ACCOUNT + ":" + name;+ if (length > 80) {+ assertRejected("\"DeadLetterConfig\":{\"Arn\":\"" + arn + "\"}",+ "Parameter " + arn + " is not valid. Reason: Provided Arn is not in correct format.");+ } else {+ client.putTargets(request -> request.rule(rule).targets(Target.builder().id("t1").arn(CLUSTER)+ .deadLetterConfig(config -> config.arn(arn)).build()));+ assertEquals(arn, listedTarget().deadLetterConfig().arn());+ }+ }++ @ParameterizedTest+ @ValueSource(strings = {"aws", "aws-us-gov", "aws-cn", "aws-iso", "aws-iso-b", "aws-iso-e", "aws-iso-f", "aws-eusc"})+ void wellFormedRoleAndDeadLetterArnsRemainAccepted(String partition) {+ String role = "arn:" + partition + ":iam::" + ACCOUNT + ":role/service-role/target";+ String queue = "arn:" + partition + ":sqs:us-east-1:" + ACCOUNT + ":dlq";+ client.putTargets(request -> request.rule(rule).targets(Target.builder().id("t1").arn(CLUSTER)+ .roleArn(role).deadLetterConfig(config -> config.arn(queue)).build()));+ assertEquals(role, listedTarget().roleArn());+ assertEquals(queue, listedTarget().deadLetterConfig().arn());+ }++ private void putTarget(EcsParameters ecs) {+ assertEquals(0, client.putTargets(request -> request.rule(rule).targets(Target.builder()+ .id("t1").arn(CLUSTER).ecsParameters(ecs).build())).failedEntryCount());+ }++ private Target listedTarget() {+ return client.listTargetsByRule(request -> request.rule(rule)).targets().getFirst();+ }++ private void assertRejected(String fields, String message) {+ given().contentType("application/x-amz-json-1.1")+ .header("X-Amz-Target", "AWSEvents.PutTargets")+ .header("Authorization", "AWS4-HMAC-SHA256 Credential=" + ACCOUNT+ + "/20261024/us-east-1/events/aws4_request, SignedHeaders=host, Signature=test")+ .body("""+ {"Rule":"%s","Targets":[+ {"Id":"t1","Arn":"%s"},+ {"Id":"t2","Arn":"%s",%s}+ ]}+ """.formatted(rule, CLUSTER, CLUSTER, fields))+ .when().post("/").then().statusCode(400)+ .body("__type", equalTo("ValidationException"))+ .body("message", equalTo(message));+ assertTrue(client.listTargetsByRule(request -> request.rule(rule)).targets().isEmpty());+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeServiceTest.javaindex 59b0d38268..01dd2c2648 100644--- a/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeServiceTest.java@@ -763,17 +763,26 @@ class EventBridgeServiceTest {}@ParameterizedTest- @ValueSource(ints = {1, 1600})- void putTargetsAcceptsRoleArnAtModelLengthBounds(int length) {+ @ValueSource(ints = {38, 1600})+ void putTargetsAcceptsWellFormedRoleArnWithinModelLengthBounds(int length) {service.putRule("role-rule", null, "{}", null, RuleState.ENABLED, null, null, null, REGION);Target target = new Target("workflow", "arn:aws:states:us-east-1:000000000000:stateMachine:example", null, null);- target.setRoleArn("r".repeat(length));+ String prefix = "arn:aws:iam::000000000000:role/";+ target.setRoleArn(prefix + "r".repeat(length - prefix.length()));service.putTargets("role-rule", null, List.of(target), REGION);assertEquals(target.getRoleArn(), service.listTargetsByRule("role-rule", null, REGION).getFirst().getRoleArn());}+ @Test+ void putTargetsRejectsRoleArnThatOnlySatisfiesTheMinimumLength() {+ Target target = new Target("workflow", "arn:aws:states:us-east-1:000000000000:stateMachine:example", null, null);+ target.setRoleArn("r");++ assertPutTargetsValidation("Parameter r is not valid. Reason: Provided Arn is not in correct format.", target);+ }+@Testvoid putTargetsRejectsRetryAttemptsAboveMaximumBeforeLookingUpTheRule() {Target target = new Target("t1", "arn:aws:sqs:us-east-1:000000000000:queue", null, null);