mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(eventbridge): enforce tag resource ownership (#6326)
* fix(eventbridge): enforce tag resource ownership * fix(eventbridge): resolve tag ARN partition from request region * fix(eventbridge): report missing tag resources
This commit is contained in:
1 parent
d05399feb1
commit
1473fc9b83
3 files changed
+111
-7
No files matched your search
+17
@@ -276,4 +276,21 @@ class EventBridgeIntegrationTest {
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void listTagsForMissingResourceReturnsNotFound() {
|
||||
for (String resource : new String[] {
|
||||
"event-bus/missing-tags-bus", "rule/missing-tags-rule",
|
||||
"archive/missing-tags-archive", "replay/unsupported-tags-resource"
|
||||
}) {
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.ListTagsForResource")
|
||||
.body("{\"ResourceARN\":\"arn:aws:events:us-east-1:000000000000:" + resource + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
}
|
||||
}
|
||||
+62
@@ -19,6 +19,7 @@ import io.github.hectorvent.floci.services.eventbridge.model.Rule;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.RuleState;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Target;
|
||||
import io.github.hectorvent.floci.services.resourcegroupstagging.ResourceGroupsTaggingService;
|
||||
import io.github.hectorvent.floci.testing.PartitionMatrix;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -115,6 +116,67 @@ class EventBridgeServiceTest {
|
||||
service.createEventBus("my-bus", null, null, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceRejectsArnFromAnotherAccount() {
|
||||
EventBus bus = service.createEventBus("owned-bus", null, null, REGION);
|
||||
String foreignAccountArn = bus.getArn().replace(":000000000000:", ":111111111111:");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () ->
|
||||
service.tagResource(foreignAccountArn, Map.of("env", "test"), REGION));
|
||||
|
||||
assertEquals("ResourceNotFoundException", error.getErrorCode());
|
||||
assertTrue(service.listTagsForResource(bus.getArn(), REGION).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceRejectsArnFromAnotherRegion() {
|
||||
EventBus bus = service.createEventBus("owned-bus", null, null, REGION);
|
||||
String foreignRegionArn = bus.getArn().replace(":us-east-1:", ":eu-west-1:");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () ->
|
||||
service.tagResource(foreignRegionArn, Map.of("env", "test"), REGION));
|
||||
|
||||
assertEquals("ResourceNotFoundException", error.getErrorCode());
|
||||
assertTrue(service.listTagsForResource(bus.getArn(), REGION).isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource(PartitionMatrix.NON_COMMERCIAL_CASES)
|
||||
void tagResourceAcceptsResourceArnFromRequestedPartition(PartitionMatrix.PartitionCase partitionCase) {
|
||||
String region = partitionCase.region();
|
||||
EventBus bus = service.createEventBus("partition-bus", null, null, region);
|
||||
|
||||
service.tagResource(bus.getArn(), Map.of("env", "test"), region);
|
||||
|
||||
assertEquals(Map.of("env", "test"), service.listTagsForResource(bus.getArn(), region));
|
||||
PartitionMatrix.assertArnIn(partitionCase, bus.getArn());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"event-bus/missing", "event-bus/", "rule/missing", "archive/missing", "replay/missing"
|
||||
})
|
||||
void listTagsForResourceRejectsMissingOrUnsupportedResources(String resource) {
|
||||
String arn = "arn:aws:events:us-east-1:000000000000:" + resource;
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () ->
|
||||
service.listTagsForResource(arn, REGION));
|
||||
|
||||
assertEquals("ResourceNotFoundException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTagsForResourceRejectsArnFromAnotherAccount() {
|
||||
EventBus bus = service.createEventBus("owned-bus", null, null, REGION);
|
||||
service.tagResource(bus.getArn(), Map.of("env", "test"), REGION);
|
||||
String foreignAccountArn = bus.getArn().replace(":000000000000:", ":111111111111:");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () ->
|
||||
service.listTagsForResource(foreignAccountArn, REGION));
|
||||
|
||||
assertEquals("ResourceNotFoundException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createEventBusBlankNameThrows() {
|
||||
assertThrows(AwsException.class, () ->
|
||||
|
||||
Reference in new issue
Block a user