mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(eventbridge): preserve target role ARN configuration (#4946)
* fix(eventbridge): preserve target role ARN configuration * fix(eventbridge): handle stored targets without an ARN --------- Co-authored-by: Vamsi Akavarapu <16164447+vamsiak@users.noreply.github.com>
This commit is contained in:
1 parent
ab2c0def0a
commit
a18aa246d3
8 files changed
+392
-3
No files matched your search
+106
@@ -0,0 +1,106 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
|
||||
import software.amazon.awssdk.services.eventbridge.model.DeadLetterConfig;
|
||||
import software.amazon.awssdk.services.eventbridge.model.EventBridgeException;
|
||||
import software.amazon.awssdk.services.eventbridge.model.RetryPolicy;
|
||||
import software.amazon.awssdk.services.eventbridge.model.Target;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
@DisplayName("EventBridge target RoleArn")
|
||||
class EventBridgeTargetRoleTest {
|
||||
|
||||
private EventBridgeClient client;
|
||||
private String rule;
|
||||
private String role;
|
||||
private String stateMachineArn;
|
||||
private String crossAccountBusArn;
|
||||
private String deadLetterArn;
|
||||
|
||||
@BeforeEach
|
||||
void createRule() {
|
||||
client = TestFixtures.eventBridgeClient();
|
||||
rule = TestFixtures.uniqueName("eb-role");
|
||||
String ruleArn = client.putRule(r -> r.name(rule).eventPattern("{}")).ruleArn();
|
||||
String[] parts = ruleArn.split(":", 6);
|
||||
role = "arn:" + parts[1] + ":iam::" + parts[4] + ":role/eventbridge-target";
|
||||
stateMachineArn = "arn:" + parts[1] + ":states:" + parts[3] + ":" + parts[4] + ":stateMachine:example";
|
||||
crossAccountBusArn = "arn:" + parts[1] + ":events:" + parts[3] + ":111111111111:event-bus/destination";
|
||||
deadLetterArn = "arn:" + parts[1] + ":sqs:" + parts[3] + ":" + parts[4] + ":target-role-dlq";
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void cleanup() {
|
||||
try {
|
||||
client.removeTargets(r -> r.rule(rule).ids("target"));
|
||||
client.deleteRule(r -> r.name(rule));
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void roundTripAndReplaceRoleWithRetryAndDeadLetterSettings() {
|
||||
RetryPolicy retry = RetryPolicy.builder().maximumRetryAttempts(2).maximumEventAgeInSeconds(60).build();
|
||||
DeadLetterConfig dlq = DeadLetterConfig.builder().arn(deadLetterArn).build();
|
||||
putTarget(Target.builder().id("target").arn(stateMachineArn).roleArn(role)
|
||||
.retryPolicy(retry).deadLetterConfig(dlq).build());
|
||||
|
||||
Target stored = storedTarget();
|
||||
assertThat(stored.roleArn()).isEqualTo(role);
|
||||
assertThat(stored.retryPolicy()).isEqualTo(retry);
|
||||
assertThat(stored.deadLetterConfig()).isEqualTo(dlq);
|
||||
|
||||
String replacement = role + "-updated";
|
||||
putTarget(stored.toBuilder().roleArn(replacement).build());
|
||||
assertThat(storedTarget().roleArn()).isEqualTo(replacement);
|
||||
assertThat(client.listTargetsByRule(r -> r.rule(rule)).targets()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void omittedRoleDoesNotInheritTheRuleRole() {
|
||||
client.putRule(r -> r.name(rule).eventPattern("{}").roleArn(role));
|
||||
putTarget(Target.builder().id("target").arn(stateMachineArn).build());
|
||||
|
||||
assertThat(storedTarget().roleArn()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void omittedRoleOnSameCrossAccountBusTargetIsRetained() {
|
||||
putTarget(Target.builder().id("target").arn(crossAccountBusArn).roleArn(role).build());
|
||||
putTarget(Target.builder().id("target").arn(crossAccountBusArn).build());
|
||||
|
||||
assertThat(storedTarget().roleArn()).isEqualTo(role);
|
||||
|
||||
putTarget(Target.builder().id("target").arn(crossAccountBusArn + "-changed").build());
|
||||
assertThat(storedTarget().roleArn()).isNull();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 1601})
|
||||
void invalidRoleLengthReturnsValidationException(int length) {
|
||||
assertThatThrownBy(() -> putTarget(Target.builder().id("target").arn(stateMachineArn)
|
||||
.roleArn("r".repeat(length)).build()))
|
||||
.isInstanceOfSatisfying(EventBridgeException.class, error -> {
|
||||
assertThat(error.statusCode()).isEqualTo(400);
|
||||
assertThat(error.awsErrorDetails().errorCode()).isEqualTo("ValidationException");
|
||||
assertThat(error.getMessage()).contains("targets.1.member.roleArn");
|
||||
});
|
||||
}
|
||||
|
||||
private void putTarget(Target target) {
|
||||
assertThat(client.putTargets(r -> r.rule(rule).targets(target)).failedEntryCount()).isZero();
|
||||
}
|
||||
|
||||
private Target storedTarget() {
|
||||
return client.listTargetsByRule(r -> r.rule(rule)).targets().get(0);
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,18 @@ the state machine from the account and region in its ARN.
|
||||
|
||||
State machine aliases and versions are not supported as EventBridge targets.
|
||||
|
||||
## Target Roles
|
||||
|
||||
`PutTargets` stores each target's optional `RoleArn`, and `ListTargetsByRule`
|
||||
returns it when set. It is independent of the rule's `RoleArn`. An explicit
|
||||
role update replaces the stored value. Omitting the role on an existing
|
||||
cross-account event-bus target with the same ID and ARN retains its previous
|
||||
role, as documented by AWS.
|
||||
|
||||
The value must be between 1 and 1600 characters when supplied. Floci stores
|
||||
the role as configuration; target delivery does not assume it or enforce its
|
||||
IAM policies.
|
||||
|
||||
## Target Retry and Dead-Letter Queues
|
||||
|
||||
A target's `RetryPolicy` and `DeadLetterConfig` are validated by `PutTargets`, stored with the target, returned by `ListTargetsByRule`, and applied to delivery from `PutEvents` and scheduled rules.
|
||||
|
||||
@@ -224,6 +224,7 @@ public class EventBridgeHandler {
|
||||
input.isEmpty() ? null : input,
|
||||
inputPath.isEmpty() ? null : inputPath
|
||||
);
|
||||
target.setRoleArn(t.path("RoleArn").asText(null));
|
||||
target.setInputTransformer(InputTransformer.fromJson(t.path("InputTransformer")));
|
||||
JsonNode sqsParamsNode = t.path("SqsParameters");
|
||||
if (!sqsParamsNode.isMissingNode() && sqsParamsNode.isObject()) {
|
||||
@@ -317,6 +318,9 @@ public class EventBridgeHandler {
|
||||
if (t.getRetryPolicy() != null) {
|
||||
node.set("RetryPolicy", objectMapper.valueToTree(t.getRetryPolicy()));
|
||||
}
|
||||
if (t.getRoleArn() != null) {
|
||||
node.put("RoleArn", t.getRoleArn());
|
||||
}
|
||||
if (t.getDeadLetterConfig() != null) {
|
||||
node.set("DeadLetterConfig", objectMapper.valueToTree(t.getDeadLetterConfig()));
|
||||
}
|
||||
|
||||
+24
-3
@@ -406,14 +406,20 @@ public class EventBridgeService implements ResourceProvider {
|
||||
// ──────────────────────────── Targets ────────────────────────────
|
||||
|
||||
public int putTargets(String ruleName, String busName, List<Target> newTargets, String region) {
|
||||
validateRetrySettings(newTargets);
|
||||
validateTargetSettings(newTargets);
|
||||
String effectiveBus = resolvedBusName(busName);
|
||||
String key = ruleKey(region, effectiveBus, ruleName);
|
||||
ruleStore.get(key)
|
||||
Rule rule = ruleStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Rule not found: " + ruleName, 400));
|
||||
List<Target> existing = new ArrayList<>(targetStore.get(key).orElse(new ArrayList<>()));
|
||||
for (Target newTarget : newTargets) {
|
||||
if (newTarget.getRoleArn() == null && isCrossAccountEventBus(newTarget.getArn(), rule)) {
|
||||
existing.stream()
|
||||
.filter(t -> t.getId().equals(newTarget.getId()) && newTarget.getArn().equals(t.getArn()))
|
||||
.findFirst()
|
||||
.ifPresent(t -> newTarget.setRoleArn(t.getRoleArn()));
|
||||
}
|
||||
existing.removeIf(t -> t.getId().equals(newTarget.getId()));
|
||||
existing.add(newTarget);
|
||||
}
|
||||
@@ -422,7 +428,16 @@ public class EventBridgeService implements ResourceProvider {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void validateRetrySettings(List<Target> targets) {
|
||||
private boolean isCrossAccountEventBus(String targetArn, Rule rule) {
|
||||
if (!AwsArnUtils.isArnFor(targetArn, "events")) {
|
||||
return false;
|
||||
}
|
||||
AwsArnUtils.Arn arn = AwsArnUtils.parse(targetArn);
|
||||
String accountId = rule.getAccountId() != null ? rule.getAccountId() : regionResolver.getAccountId();
|
||||
return arn.resource().startsWith("event-bus/") && AwsArnUtils.isForeignAccount(arn, accountId);
|
||||
}
|
||||
|
||||
private static void validateTargetSettings(List<Target> targets) {
|
||||
for (int i = 0; i < targets.size(); i++) {
|
||||
Target target = targets.get(i);
|
||||
Integer attempts = target.getRetryPolicy() != null ? target.getRetryPolicy().maximumRetryAttempts() : null;
|
||||
@@ -443,6 +458,12 @@ public class EventBridgeService implements ResourceProvider {
|
||||
field = "deadLetterConfig.arn";
|
||||
value = arn;
|
||||
constraint = arn.isEmpty() ? "length greater than or equal to 1" : "length less than or equal to 1600";
|
||||
} else if (target.getRoleArn() != null
|
||||
&& (target.getRoleArn().isEmpty() || target.getRoleArn().length() > 1600)) {
|
||||
field = "roleArn";
|
||||
value = target.getRoleArn();
|
||||
constraint = target.getRoleArn().isEmpty()
|
||||
? "length greater than or equal to 1" : "length less than or equal to 1600";
|
||||
}
|
||||
if (field != null) {
|
||||
throw new AwsException("ValidationException", "1 validation error detected: Value '" + value
|
||||
|
||||
@@ -11,6 +11,7 @@ public class Target {
|
||||
|
||||
private String id;
|
||||
private String arn;
|
||||
private String roleArn;
|
||||
private String input;
|
||||
private String inputPath;
|
||||
private InputTransformer inputTransformer;
|
||||
@@ -35,6 +36,9 @@ public class Target {
|
||||
public String getArn() { return arn; }
|
||||
public void setArn(String arn) { this.arn = arn; }
|
||||
|
||||
public String getRoleArn() { return roleArn; }
|
||||
public void setRoleArn(String roleArn) { this.roleArn = roleArn; }
|
||||
|
||||
public String getInput() { return input; }
|
||||
public void setInput(String input) { this.input = input; }
|
||||
|
||||
|
||||
+113
@@ -17,6 +17,7 @@ import io.github.hectorvent.floci.services.resourcegroupstagging.ResourceGroupsT
|
||||
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 org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
@@ -372,17 +373,129 @@ class EventBridgeServiceTest {
|
||||
service.putRule("my-rule", null, "{\"source\":[\"my.app\"]}", null, RuleState.ENABLED,
|
||||
null, null, null, REGION);
|
||||
Target target = new Target("t1", "arn:aws:sqs:us-east-1:000000000000:queue", null, null);
|
||||
target.setRoleArn("arn:aws:iam::000000000000:role/eventbridge-target");
|
||||
target.setRetryPolicy(new Target.RetryPolicy(4, 120));
|
||||
target.setDeadLetterConfig(new Target.DeadLetterConfig("arn:aws:sqs:us-east-1:000000000000:dlq"));
|
||||
|
||||
service.putTargets("my-rule", null, List.of(target), REGION);
|
||||
|
||||
Target stored = service.listTargetsByRule("my-rule", null, REGION).getFirst();
|
||||
assertEquals(target.getRoleArn(), stored.getRoleArn());
|
||||
assertEquals(new Target.RetryPolicy(4, 120), stored.getRetryPolicy());
|
||||
assertEquals(new Target.DeadLetterConfig("arn:aws:sqs:us-east-1:000000000000:dlq"),
|
||||
stored.getDeadLetterConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
void crossAccountBusUpdateReplacesStoredTargetWithoutArn() {
|
||||
service.putRule("role-rule", null, "{}", null, RuleState.ENABLED, null, null, null, REGION);
|
||||
service.putTargets("role-rule", null, List.of(new Target("bus", null, null, null)), REGION);
|
||||
String arn = "arn:aws:events:us-east-1:111111111111:event-bus/destination";
|
||||
|
||||
service.putTargets("role-rule", null, List.of(new Target("bus", arn, null, null)), REGION);
|
||||
|
||||
List<Target> stored = service.listTargetsByRule("role-rule", null, REGION);
|
||||
assertEquals(1, stored.size());
|
||||
assertEquals(arn, stored.getFirst().getArn());
|
||||
assertNull(stored.getFirst().getRoleArn());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"aws, us-east-1",
|
||||
"aws-us-gov, us-gov-west-1",
|
||||
"aws-cn, cn-north-1"
|
||||
})
|
||||
void omittedRoleOnCrossAccountBusUpdateRetainsTheStoredRole(String partition, String region) {
|
||||
service.putRule("role-rule", null, "{}", null, RuleState.ENABLED, null, null, null, region);
|
||||
String arn = "arn:" + partition + ":events:" + region + ":111111111111:event-bus/destination";
|
||||
Target original = new Target("bus", arn, null, null);
|
||||
original.setRoleArn("arn:" + partition + ":iam::000000000000:role/eventbridge-target");
|
||||
service.putTargets("role-rule", null, List.of(original), region);
|
||||
|
||||
Target updated = new Target("bus", arn, "{\"updated\":true}", null);
|
||||
service.putTargets("role-rule", null, List.of(updated), region);
|
||||
|
||||
Target stored = service.listTargetsByRule("role-rule", null, region).getFirst();
|
||||
assertEquals(original.getRoleArn(), stored.getRoleArn());
|
||||
assertEquals(updated.getInput(), stored.getInput());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"arn:aws:events:us-east-1:000000000000:event-bus/local",
|
||||
"arn:aws:states:us-east-1:111111111111:stateMachine:workflow",
|
||||
"arn:aws:events:us-east-1:111111111111:rule/other"
|
||||
})
|
||||
void omittedRoleDoesNotRetainRolesForOtherTargetTypes(String arn) {
|
||||
service.putRule("role-rule", null, "{}", null, RuleState.ENABLED, null, null, null, REGION);
|
||||
Target original = new Target("target", arn, null, null);
|
||||
original.setRoleArn("arn:aws:iam::000000000000:role/original");
|
||||
service.putTargets("role-rule", null, List.of(original), REGION);
|
||||
|
||||
service.putTargets("role-rule", null, List.of(new Target("target", arn, null, null)), REGION);
|
||||
|
||||
assertNull(service.listTargetsByRule("role-rule", null, REGION).getFirst().getRoleArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacingCrossAccountBusArnOrIdDoesNotCopyTheOldRole() {
|
||||
service.putRule("role-rule", null, "{}", null, RuleState.ENABLED, null, null, null, REGION);
|
||||
String arn = "arn:aws:events:us-east-1:111111111111:event-bus/original";
|
||||
Target original = new Target("bus", arn, null, null);
|
||||
original.setRoleArn("arn:aws:iam::000000000000:role/original");
|
||||
service.putTargets("role-rule", null, List.of(original), REGION);
|
||||
|
||||
service.putTargets("role-rule", null, List.of(new Target("other-id", arn, null, null)), REGION);
|
||||
service.putTargets("role-rule", null, List.of(new Target("bus", arn + "-changed", null, null)), REGION);
|
||||
|
||||
assertTrue(service.listTargetsByRule("role-rule", null, REGION).stream()
|
||||
.allMatch(target -> target.getRoleArn() == null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitRoleUpdateReplacesCrossAccountBusRole() {
|
||||
service.putRule("role-rule", null, "{}", null, RuleState.ENABLED, null, null, null, REGION);
|
||||
String arn = "arn:aws:events:us-east-1:111111111111:event-bus/destination";
|
||||
Target original = new Target("bus", arn, null, null);
|
||||
original.setRoleArn("arn:aws:iam::000000000000:role/original");
|
||||
service.putTargets("role-rule", null, List.of(original), REGION);
|
||||
Target updated = new Target("bus", arn, null, null);
|
||||
updated.setRoleArn("arn:aws:iam::000000000000:role/replacement");
|
||||
|
||||
service.putTargets("role-rule", null, List.of(updated), REGION);
|
||||
|
||||
List<Target> stored = service.listTargetsByRule("role-rule", null, REGION);
|
||||
assertEquals(1, stored.size());
|
||||
assertEquals(updated.getRoleArn(), stored.getFirst().getRoleArn());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 1601})
|
||||
void putTargetsRejectsRoleArnOutsideModelLengthBounds(int length) {
|
||||
Target valid = new Target("valid", "arn:aws:states:us-east-1:000000000000:stateMachine:valid", null, null);
|
||||
Target invalid = new Target("invalid", valid.getArn(), null, null);
|
||||
String role = "r".repeat(length);
|
||||
invalid.setRoleArn(role);
|
||||
String constraint = length == 0 ? "greater than or equal to 1" : "less than or equal to 1600";
|
||||
|
||||
assertPutTargetsValidation("1 validation error detected: Value '" + role + "' at "
|
||||
+ "'targets.2.member.roleArn' failed to satisfy constraint: Member must have length " + constraint,
|
||||
valid, invalid);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {1, 1600})
|
||||
void putTargetsAcceptsRoleArnAtModelLengthBounds(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));
|
||||
|
||||
service.putTargets("role-rule", null, List.of(target), REGION);
|
||||
|
||||
assertEquals(target.getRoleArn(), service.listTargetsByRule("role-rule", null, REGION).getFirst().getRoleArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putTargetsRejectsRetryAttemptsAboveMaximumBeforeLookingUpTheRule() {
|
||||
Target target = new Target("t1", "arn:aws:sqs:us-east-1:000000000000:queue", null, null);
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class EventBridgeTargetRoleIntegrationTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/eventbridge-target";
|
||||
private String rule;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void removeTestResources() {
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.RemoveTargets")
|
||||
.body("{\"Rule\":\"" + rule + "\",\"Ids\":[\"workflow\"]}")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.DeleteRule")
|
||||
.body("{\"Name\":\"" + rule + "\"}")
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTargetsReturnsRoleAlongsideRetryAndDeadLetterSettings() {
|
||||
rule = "eb-target-role-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.PutRule")
|
||||
.body("{\"Name\":\"" + rule + "\",\"EventPattern\":\"{}\"}")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.PutTargets")
|
||||
.body("""
|
||||
{
|
||||
"Rule": "%s",
|
||||
"Targets": [{
|
||||
"Id": "workflow",
|
||||
"Arn": "arn:aws:states:us-east-1:000000000000:stateMachine:example",
|
||||
"RoleArn": "%s",
|
||||
"RetryPolicy": {"MaximumRetryAttempts": 2, "MaximumEventAgeInSeconds": 60},
|
||||
"DeadLetterConfig": {"Arn": "arn:aws:sqs:us-east-1:000000000000:target-role-dlq"}
|
||||
}]
|
||||
}
|
||||
""".formatted(rule, ROLE))
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("FailedEntryCount", equalTo(0));
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.ListTargetsByRule")
|
||||
.body("{\"Rule\":\"" + rule + "\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("Targets[0].RoleArn", equalTo(ROLE))
|
||||
.body("Targets[0].RetryPolicy.MaximumRetryAttempts", equalTo(2))
|
||||
.body("Targets[0].RetryPolicy.MaximumEventAgeInSeconds", equalTo(60))
|
||||
.body("Targets[0].DeadLetterConfig.Arn",
|
||||
equalTo("arn:aws:sqs:us-east-1:000000000000:target-role-dlq"));
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.storage.PersistentStorage;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Target;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
class TargetPersistenceTest {
|
||||
|
||||
@TempDir
|
||||
Path directory;
|
||||
|
||||
@Test
|
||||
void targetRoleSurvivesPersistentStorageReload() {
|
||||
Path file = directory.resolve("targets.json");
|
||||
TypeReference<Map<String, List<Target>>> type = new TypeReference<>() {};
|
||||
PersistentStorage<String, List<Target>> writer = new PersistentStorage<>(file, type);
|
||||
Target target = new Target("workflow", "arn:aws:states:us-east-1:000000000000:stateMachine:example", null, null);
|
||||
target.setRoleArn("arn:aws:iam::000000000000:role/path/eventbridge-target");
|
||||
target.setRetryPolicy(new Target.RetryPolicy(2, 60));
|
||||
target.setDeadLetterConfig(new Target.DeadLetterConfig("arn:aws:sqs:us-east-1:000000000000:dlq"));
|
||||
writer.put("rule", List.of(target));
|
||||
|
||||
PersistentStorage<String, List<Target>> reader = new PersistentStorage<>(file, type);
|
||||
reader.load();
|
||||
|
||||
Target restored = reader.get("rule").orElseThrow().getFirst();
|
||||
assertEquals(target.getRoleArn(), restored.getRoleArn());
|
||||
assertEquals(target.getRetryPolicy(), restored.getRetryPolicy());
|
||||
assertEquals(target.getDeadLetterConfig(), restored.getDeadLetterConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyStoredTargetsLoadWithoutARole() throws Exception {
|
||||
Path file = directory.resolve("targets.json");
|
||||
Files.writeString(file, """
|
||||
{"rule":[{"id":"queue","arn":"arn:aws:sqs:us-east-1:000000000000:queue"}]}
|
||||
""");
|
||||
PersistentStorage<String, List<Target>> reader = new PersistentStorage<>(file, new TypeReference<>() {});
|
||||
reader.load();
|
||||
|
||||
Target restored = reader.get("rule").orElseThrow().getFirst();
|
||||
assertEquals("queue", restored.getId());
|
||||
assertNull(restored.getRoleArn());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user