mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(sns): require IAM role ARN for Firehose subscriptions (#4233)
This commit is contained in:
1 parent
b6d5d51bde
commit
97aa084209
5 files changed
+96
-7
No files matched your search
+28
-1
@@ -93,7 +93,7 @@ class SnsFirehoseIntegrationTest {
|
||||
|
||||
// Subscribe envelope delivery stream
|
||||
String envelopeStreamArn = "arn:aws:firehose:us-east-1:000000000000:deliverystream/" + ENVELOPE_STREAM;
|
||||
envelopeSubArn = given()
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "Subscribe")
|
||||
.formParam("TopicArn", topicArn)
|
||||
@@ -101,11 +101,36 @@ class SnsFirehoseIntegrationTest {
|
||||
.formParam("Endpoint", envelopeStreamArn)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("SubscriptionRoleArn"));
|
||||
|
||||
envelopeSubArn = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "Subscribe")
|
||||
.formParam("TopicArn", topicArn)
|
||||
.formParam("Protocol", "firehose")
|
||||
.formParam("Endpoint", envelopeStreamArn)
|
||||
.formParam("Attributes.entry.1.key", "SubscriptionRoleArn")
|
||||
.formParam("Attributes.entry.1.value", "arn:aws:iam::000000000000:role/firehose-role")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<SubscriptionArn>"))
|
||||
.extract().xmlPath().getString("SubscribeResponse.SubscribeResult.SubscriptionArn");
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "GetSubscriptionAttributes")
|
||||
.formParam("SubscriptionArn", envelopeSubArn)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("SubscriptionRoleArn"))
|
||||
.body(containsString("arn:aws:iam::000000000000:role/firehose-role"));
|
||||
|
||||
// Subscribe raw delivery stream
|
||||
String rawStreamArn = "arn:aws:firehose:us-east-1:000000000000:deliverystream/" + RAW_STREAM;
|
||||
rawSubArn = given()
|
||||
@@ -114,6 +139,8 @@ class SnsFirehoseIntegrationTest {
|
||||
.formParam("TopicArn", topicArn)
|
||||
.formParam("Protocol", "firehose")
|
||||
.formParam("Endpoint", rawStreamArn)
|
||||
.formParam("Attributes.entry.1.key", "SubscriptionRoleArn")
|
||||
.formParam("Attributes.entry.1.value", "arn:aws:iam::000000000000:role/firehose-role")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
|
||||
+4
-1
@@ -257,7 +257,10 @@ class SnsMaximumMessageSizeTest {
|
||||
String arn = largeTopic("allowed-protocols");
|
||||
for (String protocol : List.of("sqs", "firehose", "lambda")) {
|
||||
assertNotNull(snsService.subscribe(arn, protocol, "arn:aws:" + protocol
|
||||
+ ":us-east-1:000000000000:target", REGION, Map.of()));
|
||||
+ ":us-east-1:000000000000:target", REGION,
|
||||
"firehose".equals(protocol)
|
||||
? Map.of("SubscriptionRoleArn", "arn:aws:iam::000000000000:role/firehose-role")
|
||||
: Map.of()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ class SnsServiceTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final String BASE_URL = "http://localhost:4566";
|
||||
private static final String FIREHOSE_ROLE_ARN = "arn:aws:iam::000000000000:role/firehose-role";
|
||||
|
||||
private SnsService snsService;
|
||||
|
||||
@@ -130,6 +131,43 @@ class SnsServiceTest {
|
||||
assertEquals(Map.of("attr1", "value1", "attr2", "value2"), sub.getAttributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void subscribe_firehoseRequiresValidRoleArn() {
|
||||
Topic topic = snsService.createTopic("firehose-topic", null, null, REGION);
|
||||
String streamArn = "arn:aws:firehose:us-east-1:000000000000:deliverystream/test-stream";
|
||||
for (Map<String, String> attributes : List.of(
|
||||
Map.<String, String>of(),
|
||||
Map.of("SubscriptionRoleArn", ""),
|
||||
Map.of("SubscriptionRoleArn", "arn:aws:iam::000000000000:user/not-a-role"))) {
|
||||
AwsException ex = assertThrows(AwsException.class, () -> snsService.subscribe(
|
||||
topic.getTopicArn(), "firehose", streamArn, REGION, attributes));
|
||||
assertEquals("InvalidParameter", ex.getErrorCode());
|
||||
assertTrue(ex.getMessage().contains("SubscriptionRoleArn"));
|
||||
}
|
||||
assertTrue(snsService.listSubscriptions(REGION).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void subscribe_firehoseRoleArnIsReturnedAndCanBeUpdated() {
|
||||
Topic topic = snsService.createTopic("firehose-topic", null, null, REGION);
|
||||
Subscription sub = snsService.subscribe(topic.getTopicArn(), "firehose",
|
||||
"arn:aws:firehose:us-east-1:000000000000:deliverystream/test-stream", REGION,
|
||||
Map.of("SubscriptionRoleArn", FIREHOSE_ROLE_ARN));
|
||||
assertEquals(FIREHOSE_ROLE_ARN,
|
||||
snsService.getSubscriptionAttributes(sub.getSubscriptionArn(), REGION).get("SubscriptionRoleArn"));
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> snsService.setSubscriptionAttribute(
|
||||
sub.getSubscriptionArn(), "SubscriptionRoleArn", "not-an-arn", REGION));
|
||||
assertEquals("InvalidParameter", ex.getErrorCode());
|
||||
assertEquals(FIREHOSE_ROLE_ARN,
|
||||
snsService.getSubscriptionAttributes(sub.getSubscriptionArn(), REGION).get("SubscriptionRoleArn"));
|
||||
|
||||
String updated = "arn:aws:iam::000000000000:role/updated-role";
|
||||
snsService.setSubscriptionAttribute(sub.getSubscriptionArn(), "SubscriptionRoleArn", updated, REGION);
|
||||
assertEquals(updated,
|
||||
snsService.getSubscriptionAttributes(sub.getSubscriptionArn(), REGION).get("SubscriptionRoleArn"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void subscribe_idempotent() {
|
||||
Topic topic = snsService.createTopic("my-topic", null, null, REGION);
|
||||
@@ -794,7 +832,8 @@ class SnsServiceTest {
|
||||
|
||||
Topic topic = service.createTopic("firehose-topic", null, null, REGION);
|
||||
String streamArn = "arn:aws:firehose:us-east-1:000000000000:deliverystream/test-stream";
|
||||
service.subscribe(topic.getTopicArn(), "firehose", streamArn, REGION, Map.of());
|
||||
service.subscribe(topic.getTopicArn(), "firehose", streamArn, REGION,
|
||||
Map.of("SubscriptionRoleArn", FIREHOSE_ROLE_ARN));
|
||||
|
||||
String messageId = service.publish(topic.getTopicArn(), null, "Hello Firehose", "Test Subject", REGION);
|
||||
assertNotNull(messageId);
|
||||
@@ -831,7 +870,7 @@ class SnsServiceTest {
|
||||
Topic topic = service.createTopic("firehose-topic-raw", null, null, REGION);
|
||||
String streamArn = "arn:aws:firehose:us-east-1:000000000000:deliverystream/test-stream-raw";
|
||||
service.subscribe(topic.getTopicArn(), "firehose", streamArn, REGION,
|
||||
Map.of("RawMessageDelivery", "true"));
|
||||
Map.of("RawMessageDelivery", "true", "SubscriptionRoleArn", FIREHOSE_ROLE_ARN));
|
||||
|
||||
String message = "{\"raw\":\"payload\"}";
|
||||
String messageId = service.publish(topic.getTopicArn(), null, message, null, REGION);
|
||||
@@ -859,7 +898,7 @@ class SnsServiceTest {
|
||||
|
||||
Topic topic = service.createTopic("firehose-bare-topic", null, null, REGION);
|
||||
service.subscribe(topic.getTopicArn(), "firehose", "bare-stream", REGION,
|
||||
Map.of("RawMessageDelivery", "true"));
|
||||
Map.of("RawMessageDelivery", "true", "SubscriptionRoleArn", FIREHOSE_ROLE_ARN));
|
||||
|
||||
service.publish(topic.getTopicArn(), null, "bare-msg", null, REGION);
|
||||
|
||||
@@ -886,7 +925,8 @@ class SnsServiceTest {
|
||||
|
||||
Topic topic = service.createTopic("firehose-fail-topic", null, null, REGION);
|
||||
service.subscribe(topic.getTopicArn(), "firehose",
|
||||
"arn:aws:firehose:us-east-1:000000000000:deliverystream/failing-stream", REGION, Map.of());
|
||||
"arn:aws:firehose:us-east-1:000000000000:deliverystream/failing-stream", REGION,
|
||||
Map.of("SubscriptionRoleArn", FIREHOSE_ROLE_ARN));
|
||||
|
||||
// Delivery error is logged and tolerated; publisher receives message ID
|
||||
String messageId = service.publish(topic.getTopicArn(), null, "msg", null, REGION);
|
||||
|
||||
Reference in new issue
Block a user