mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ses): validate the SNS topic of an event destination (#8275)
This commit is contained in:
1 parent
e4d7061eff
commit
2cb54dad8f
17 files changed
+542
-70
No files matched your search
@@ -38,6 +38,7 @@ class SesBooleanCoercionV2IntegrationTest {
|
||||
send("POST", "/v2/email/identities", "{\"EmailIdentity\":\"" + DOMAIN + "\"}").statusCode(200);
|
||||
send("POST", "/v2/email/configuration-sets", "{\"ConfigurationSetName\":\"" + CS + "\"}")
|
||||
.statusCode(200);
|
||||
SnsTopicFixture.create(REGION, "coercion");
|
||||
send("POST", "/v2/email/configuration-sets/" + CS + "/event-destinations", """
|
||||
{"EventDestinationName": "%s",
|
||||
"EventDestination": {"Enabled": "yes", "MatchingEventTypes": ["SEND"],
|
||||
|
||||
@@ -151,30 +151,6 @@ class SesConfigurationSetEventDestinationTest {
|
||||
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void snsBlankTopicArn_throws() {
|
||||
EventDestination ed = new EventDestination();
|
||||
ed.setMatchingEventTypes(List.of("SEND"));
|
||||
SnsDestination sns = new SnsDestination();
|
||||
sns.setTopicArn("");
|
||||
ed.setSnsDestination(sns);
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertEquals("SnsDestination requires a non-blank TopicArn.", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void snsNullTopicArn_throws() {
|
||||
EventDestination ed = new EventDestination();
|
||||
ed.setMatchingEventTypes(List.of("SEND"));
|
||||
ed.setSnsDestination(new SnsDestination()); // TopicArn left null
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertEquals("SnsDestination requires a non-blank TopicArn.", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void firehoseMissingDeliveryStream_throws() {
|
||||
EventDestination ed = new EventDestination();
|
||||
|
||||
+24
-1
@@ -38,6 +38,8 @@ class SesConfigurationSetEventDestinationV1IntegrationTest {
|
||||
.formParam("ConfigurationSet.Name", CS)
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
SnsTopicFixture.create("us-east-1", "topic-a");
|
||||
SnsTopicFixture.create("us-east-1", "topic-b");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -304,7 +306,28 @@ class SesConfigurationSetEventDestinationV1IntegrationTest {
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("SnsDestination requires a non-blank TopicArn"));
|
||||
.body(containsString("<Code>InvalidSNSDestination</Code>"))
|
||||
.body(containsString("<Message>Invalid ARN provided: topic ARN = .</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
void createConfigurationSetEventDestination_missingSnsTopic_rejected() {
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH)
|
||||
.formParam("Action", "CreateConfigurationSetEventDestination")
|
||||
.formParam("ConfigurationSetName", CS)
|
||||
.formParam("EventDestination.Name", "v1-ed-sns-missing")
|
||||
.formParam("EventDestination.Enabled", "true")
|
||||
.formParam("EventDestination.MatchingEventTypes.member.1", "send")
|
||||
.formParam("EventDestination.SNSDestination.TopicARN", "arn:aws:sns:us-east-1:000000000000:never-created")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>InvalidSNSDestination</Code>"))
|
||||
.body(containsString("<Message>SNS topic <arn:aws:sns:us-east-1:000000000000:never-created> "
|
||||
+ "not found.</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+66
-1
@@ -37,6 +37,10 @@ class SesConfigurationSetEventDestinationV2IntegrationTest {
|
||||
@Test
|
||||
@Order(1)
|
||||
void createConfigurationSet() {
|
||||
for (String topic : new String[] {"ses-events", "ses-events-2", "dup", "x", "ed-a", "ed-b", "ed-c",
|
||||
"ed-a-updated"}) {
|
||||
SnsTopicFixture.create("us-east-1", topic);
|
||||
}
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
@@ -122,7 +126,7 @@ class SesConfigurationSetEventDestinationV2IntegrationTest {
|
||||
"EventDestinationName": "ed-x",
|
||||
"EventDestination": {
|
||||
"MatchingEventTypes": ["SEND"],
|
||||
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:ghost"}
|
||||
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:x"}
|
||||
}
|
||||
}
|
||||
""")
|
||||
@@ -738,4 +742,65 @@ class SesConfigurationSetEventDestinationV2IntegrationTest {
|
||||
.body("EventDestinations[0].EventBridgeDestination.EventBusArn",
|
||||
equalTo(SCOPED_DEFAULT_BUS_ARN));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(100)
|
||||
void snsDestination_missingTopicRejectedOnCreateAndUpdate() {
|
||||
String body = """
|
||||
{
|
||||
"EventDestinationName": "ed-sns",
|
||||
"EventDestination": {
|
||||
"MatchingEventTypes": ["SEND"],
|
||||
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:never-created"}
|
||||
}
|
||||
}
|
||||
""";
|
||||
String message = "SNS topic <arn:aws:sns:us-east-1:000000000000:never-created> not found.";
|
||||
String set = "v2-cs-sns-check";
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{\"ConfigurationSetName\": \"" + set + "\"}")
|
||||
.when()
|
||||
.post("/v2/email/configuration-sets")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body.replace("never-created", "x"))
|
||||
.when()
|
||||
.post("/v2/email/configuration-sets/" + set + "/event-destinations")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/v2/email/configuration-sets/" + set + "/event-destinations")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo(message));
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/v2/email/configuration-sets/v2-cs-ghost/event-destinations")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", equalTo(message));
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.put("/v2/email/configuration-sets/" + set + "/event-destinations/ed-sns")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo(message));
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -2,6 +2,7 @@ package io.floci.aws.services.ses;
|
||||
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.services.ses.model.ConfigurationSet;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -13,6 +14,7 @@ import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* The ListConfigurationSets {@code Filter}. Every message and precedence below is what SES v2
|
||||
@@ -26,7 +28,8 @@ class SesConfigurationSetListFilterServiceTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SesConfigurationSetService(new InMemoryStorage<>());
|
||||
service = new SesConfigurationSetService(new InMemoryStorage<>(), mock(SesEventPublisher.class),
|
||||
new RegionResolver(REGION, "000000000000"));
|
||||
for (String name : List.of("Filter-Alpha", "filter-beta", "other-FILTER-gamma", "unrelated")) {
|
||||
ConfigurationSet configSet = new ConfigurationSet();
|
||||
configSet.setName(name);
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.floci.aws.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.core.storage.PersistentStorage;
|
||||
import io.floci.aws.services.ses.model.ConfigurationSet;
|
||||
@@ -24,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Unit test for the extracted configuration-set domain: store ownership, key derivation and name
|
||||
@@ -44,7 +46,8 @@ class SesConfigurationSetServiceTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SesConfigurationSetService(new InMemoryStorage<>());
|
||||
service = new SesConfigurationSetService(new InMemoryStorage<>(), mock(SesEventPublisher.class),
|
||||
new RegionResolver(REGION, "000000000000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -203,7 +206,8 @@ class SesConfigurationSetServiceTest {
|
||||
void messageSecurityOptions_surviveAPersistentStorageReload(@TempDir Path dir) {
|
||||
Path file = dir.resolve("ses-config-sets.json");
|
||||
SesConfigurationSetService writer = new SesConfigurationSetService(
|
||||
new PersistentStorage<>(file, new TypeReference<Map<String, ConfigurationSet>>() {}));
|
||||
new PersistentStorage<>(file, new TypeReference<Map<String, ConfigurationSet>>() {}),
|
||||
mock(SesEventPublisher.class), new RegionResolver(REGION, "000000000000"));
|
||||
writer.create(cs("smime-cs"), REGION);
|
||||
writer.create(cs("default-cs"), REGION);
|
||||
writer.updateMessageSecurityOptions("smime-cs",
|
||||
@@ -214,7 +218,8 @@ class SesConfigurationSetServiceTest {
|
||||
PersistentStorage<String, ConfigurationSet> reloaded =
|
||||
new PersistentStorage<>(file, new TypeReference<Map<String, ConfigurationSet>>() {});
|
||||
reloaded.load();
|
||||
SesConfigurationSetService reader = new SesConfigurationSetService(reloaded);
|
||||
SesConfigurationSetService reader = new SesConfigurationSetService(reloaded, mock(SesEventPublisher.class),
|
||||
new RegionResolver(REGION, "000000000000"));
|
||||
|
||||
SigningScheme smime = reader.get("smime-cs", REGION).getMessageSecurityOptions().getSigningScheme();
|
||||
assertEquals("DETACHED", smime.getSmimeScheme().getSignatureFormat());
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
package io.floci.aws.services.ses;
|
||||
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.services.ses.SesEventPublisher.TopicAccess;
|
||||
import io.floci.aws.services.ses.model.ConfigurationSet;
|
||||
import io.floci.aws.services.ses.model.EventDestination;
|
||||
import io.floci.aws.services.ses.model.SnsDestination;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** The SNS topic of an event destination is checked when it is set; messages and order were probed. */
|
||||
class SesConfigurationSetSnsDestinationTest {
|
||||
|
||||
private static final String ACCOUNT_ID = "000000000000";
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String CS = "events";
|
||||
private static final String TOPIC = "arn:aws:sns:us-east-1:000000000000:events";
|
||||
private static final String OTHER_TOPIC = "arn:aws:sns:us-east-1:000000000000:other";
|
||||
|
||||
private SesEventPublisher publisher;
|
||||
private SesConfigurationSetService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
publisher = mock(SesEventPublisher.class);
|
||||
when(publisher.eventDestinationTopicAccess(any(), any(), any(), any())).thenReturn(TopicAccess.NOT_FOUND);
|
||||
when(publisher.eventDestinationTopicAccess(TOPIC, CS, ACCOUNT_ID, REGION)).thenReturn(TopicAccess.PUBLISHABLE);
|
||||
serviceWithConfigurationSet(new RegionResolver(REGION, ACCOUNT_ID), REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void publishableTopicIsStored() {
|
||||
create("to-sns", TOPIC, false);
|
||||
|
||||
assertEquals(TOPIC, storedTopic());
|
||||
}
|
||||
|
||||
@Test
|
||||
void paddedArnOfAPublishableTopicIsRefusedAndNotStored() {
|
||||
String padded = " " + TOPIC + " ";
|
||||
|
||||
assertEquals("Invalid SNSDestination", refusal(() -> create("to-sns", padded, false)).getMessage());
|
||||
AwsException v2 = assertThrows(AwsException.class, () -> create("to-sns", padded, true));
|
||||
assertEquals("BadRequestException", v2.getErrorCode());
|
||||
assertEquals("1 validation error detected: Value '" + padded + "' at 'destinations.1.member.snsTopicArn' "
|
||||
+ "failed to satisfy constraint: Member must satisfy regular expression pattern: "
|
||||
+ "arn:aws[^:]*:sns:[a-zA-Z0-9\\-]*:\\d{12}:[a-zA-Z_0-9+=,.@\\-_/:]+", v2.getMessage());
|
||||
assertEquals(List.of(), service.getEventDestinations(CS, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void paddedArnOfAMissingTopicIsReportedWithoutItsPadding() {
|
||||
assertRefused("SNS topic <" + OTHER_TOPIC + "> not found.", " " + OTHER_TOPIC + " ");
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingTopicIsRefused() {
|
||||
assertRefused("SNS topic <" + OTHER_TOPIC + "> not found.", OTHER_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
void topicThatRefusesSesIsRefused() {
|
||||
when(publisher.eventDestinationTopicAccess(OTHER_TOPIC, CS, ACCOUNT_ID, REGION))
|
||||
.thenReturn(TopicAccess.DENIED);
|
||||
|
||||
assertRefused("Access denied to SNS topic <" + OTHER_TOPIC
|
||||
+ ">. Verify the SNS topic policy grants Amazon SES the sns:Publish permission.", OTHER_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
void valueThatIsNotATopicArnIsRefused() {
|
||||
String form = " should have the form <arn:aws:sns:region:[account-id]:[topic-name]>";
|
||||
|
||||
assertRefused("Invalid SNS topic ARN <not-an-arn>" + form, "not-an-arn");
|
||||
assertRefused("Invalid SNS topic ARN <arn:aws:sqs:us-east-1:000000000000:x>" + form,
|
||||
"arn:aws:sqs:us-east-1:000000000000:x");
|
||||
assertRefused("Invalid SNS topic ARN <>" + form, " ");
|
||||
for (String arn : List.of("arn:aws:sns:us-east-1:abc:t", "arn:aws:sns:us-east-1:12345678901:t",
|
||||
"arn:aws:sns:us-east-1::t", "arn:aws:sns:US-EAST-1:000000000000:t",
|
||||
"arn:foo:sns:us-east-1:000000000000:t")) {
|
||||
assertRefused("Invalid SNS topic ARN <" + arn + ">" + form, arn);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void topicArnWithoutARegionIsATopicOfAnotherRegion() {
|
||||
assertRefused("SNS topic must be located in same region as SES <us-east-1>",
|
||||
"arn:aws:sns::000000000000:events");
|
||||
assertRefused("SNS topic must be located in same region as SES <us-east-1>",
|
||||
"arn:aws:sns:not-a-region:000000000000:events");
|
||||
}
|
||||
|
||||
@Test
|
||||
void topicArnSnsWouldNotAcceptIsRefused() {
|
||||
for (String arn : List.of("arn:aws:sns:us-east-1:000000000000:", "arn:aws:sns:us-east-1:000000000000:bad name!",
|
||||
"arn:aws-cn:sns:us-east-1:000000000000:events")) {
|
||||
assertRefused("Invalid parameter for SNS topic <" + arn
|
||||
+ ">. Verify the SNS topic configuration is correct.", arn);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void topicOfARegionNoPartitionPublishesIsJudgedByTheDeploymentPartition() {
|
||||
String region = "local-region-1";
|
||||
String topic = "arn:aws-cn:sns:local-region-1:000000000000:events";
|
||||
when(publisher.eventDestinationTopicAccess(topic, CS, ACCOUNT_ID, region)).thenReturn(TopicAccess.PUBLISHABLE);
|
||||
serviceWithConfigurationSet(new RegionResolver("cn-north-1", ACCOUNT_ID, "aws-cn"), region);
|
||||
|
||||
service.createEventDestination(CS, "to-sns", destination(topic), ACCOUNT_ID, region, false);
|
||||
|
||||
assertEquals(topic, service.getEventDestinations(CS, region).get(0).getSnsDestination().getTopicArn());
|
||||
String commercial = "arn:aws:sns:local-region-1:000000000000:events";
|
||||
AwsException refused = assertThrows(AwsException.class,
|
||||
() -> service.updateEventDestination(CS, "to-sns", destination(commercial), ACCOUNT_ID, region,
|
||||
false));
|
||||
assertEquals("Invalid parameter for SNS topic <" + commercial
|
||||
+ ">. Verify the SNS topic configuration is correct.", refused.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void topicOfAnotherRegionIsRefusedWithoutALookup() {
|
||||
assertRefused("SNS topic must be located in same region as SES <us-east-1>",
|
||||
"arn:aws:sns:us-west-2:000000000000:events");
|
||||
|
||||
verify(publisher, never()).eventDestinationTopicAccess(any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyAndMissingTopicArnHaveTheirOwnMessagesPerApi() {
|
||||
assertEquals("Invalid ARN provided: topic ARN = .", refusal(() -> create("to-sns", "", false)).getMessage());
|
||||
assertEquals("Invalid topic ARN provided: .", refusal(() -> create("to-sns", "", true)).getMessage());
|
||||
assertEquals("Invalid topic ARN provided: null.", refusal(() -> create("to-sns", null, true)).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void disabledDestinationIsCheckedToo() {
|
||||
EventDestination destination = destination(OTHER_TOPIC);
|
||||
destination.setEnabled(false);
|
||||
|
||||
AwsException e = refusal(() -> service.createEventDestination(CS, "to-sns", destination, ACCOUNT_ID,
|
||||
REGION, false));
|
||||
|
||||
assertEquals("SNS topic <" + OTHER_TOPIC + "> not found.", e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void v1CreateLooksUpTheSetAndTheNameBeforeTheTopic() {
|
||||
create("to-sns", TOPIC, false);
|
||||
|
||||
assertEquals("ConfigurationSetDoesNotExist", assertThrows(AwsException.class,
|
||||
() -> service.createEventDestination("ghost", "to-sns", destination(OTHER_TOPIC), ACCOUNT_ID,
|
||||
REGION, false)).getErrorCode());
|
||||
assertEquals("AlreadyExists", assertThrows(AwsException.class,
|
||||
() -> create("to-sns", OTHER_TOPIC, false)).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2CreateChecksTheTopicBeforeTheSetAndTheName() {
|
||||
create("to-sns", TOPIC, true);
|
||||
|
||||
assertEquals("InvalidSNSDestination", assertThrows(AwsException.class,
|
||||
() -> service.createEventDestination("ghost", "to-sns", destination(OTHER_TOPIC), ACCOUNT_ID,
|
||||
REGION, true)).getErrorCode());
|
||||
assertEquals("InvalidSNSDestination", assertThrows(AwsException.class,
|
||||
() -> create("to-sns", OTHER_TOPIC, true)).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateLooksUpTheDestinationBeforeTheTopic() {
|
||||
for (boolean v2 : new boolean[] {false, true}) {
|
||||
assertEquals("NotFoundException", assertThrows(AwsException.class,
|
||||
() -> service.updateEventDestination(CS, "unknown", destination(OTHER_TOPIC), ACCOUNT_ID,
|
||||
REGION, v2)).getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void refusedUpdateKeepsTheStoredDestination() {
|
||||
create("to-sns", TOPIC, false);
|
||||
|
||||
AwsException e = refusal(() -> service.updateEventDestination(CS, "to-sns", destination(OTHER_TOPIC),
|
||||
ACCOUNT_ID, REGION, false));
|
||||
|
||||
assertEquals("SNS topic <" + OTHER_TOPIC + "> not found.", e.getMessage());
|
||||
assertEquals(TOPIC, storedTopic());
|
||||
}
|
||||
|
||||
private void serviceWithConfigurationSet(RegionResolver regionResolver, String region) {
|
||||
service = new SesConfigurationSetService(new InMemoryStorage<>(), publisher, regionResolver);
|
||||
ConfigurationSet configurationSet = new ConfigurationSet();
|
||||
configurationSet.setName(CS);
|
||||
service.create(configurationSet, region);
|
||||
}
|
||||
|
||||
private void assertRefused(String message, String topicArn) {
|
||||
for (boolean v2 : new boolean[] {false, true}) {
|
||||
assertEquals(message, refusal(() -> create("to-sns", topicArn, v2)).getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static AwsException refusal(Runnable call) {
|
||||
AwsException e = assertThrows(AwsException.class, call::run);
|
||||
assertEquals("InvalidSNSDestination", e.getErrorCode());
|
||||
assertEquals(400, e.getHttpStatus());
|
||||
return e;
|
||||
}
|
||||
|
||||
private void create(String name, String topicArn, boolean v2) {
|
||||
service.createEventDestination(CS, name, destination(topicArn), ACCOUNT_ID, REGION, v2);
|
||||
}
|
||||
|
||||
private String storedTopic() {
|
||||
return service.getEventDestinations(CS, REGION).get(0).getSnsDestination().getTopicArn();
|
||||
}
|
||||
|
||||
private static EventDestination destination(String topicArn) {
|
||||
EventDestination destination = new EventDestination();
|
||||
destination.setEnabled(true);
|
||||
destination.setMatchingEventTypes(List.of("SEND"));
|
||||
SnsDestination sns = new SnsDestination();
|
||||
sns.setTopicArn(topicArn);
|
||||
destination.setSnsDestination(sns);
|
||||
return destination;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.floci.aws.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.services.acm.AcmService;
|
||||
import io.floci.aws.services.route53.Route53Service;
|
||||
@@ -172,7 +173,8 @@ final class SesServiceTestBuilder {
|
||||
contactService = new SesContactService(contactListStore, contactStore, clock);
|
||||
suppressionService = new SesSuppressionService(suppressionStore, accountSuppressionStore,
|
||||
new InMemoryStorage<>());
|
||||
configSetService = new SesConfigurationSetService(configSetStore);
|
||||
configSetService = new SesConfigurationSetService(configSetStore, mock(SesEventPublisher.class),
|
||||
new RegionResolver("us-east-1", "000000000000"));
|
||||
identityService = new SesIdentityService(identityStore, route53Service, clock);
|
||||
sentEmailService = new SesSentEmailService(emailStore);
|
||||
cvetService = new SesCvetService(cvetStore);
|
||||
|
||||
+24
-2
@@ -53,11 +53,31 @@ class SesSnsPublishAuthorizationIntegrationTest {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEventDestinationIsRefusedWhileItsTopicRefusesSes() {
|
||||
String topicArn = createSubscribedTopic(OWNER, createQueue(OWNER));
|
||||
setTopicPolicy(OWNER, topicArn, rootOnly(topicArn));
|
||||
String name = "authz-" + suffix();
|
||||
ses(OWNER, "CreateConfigurationSet", Map.of("ConfigurationSet.Name", name)).statusCode(200);
|
||||
cleanup.register(() -> ses(OWNER, "DeleteConfigurationSet", Map.of("ConfigurationSetName", name))
|
||||
.statusCode(200));
|
||||
|
||||
ses(OWNER, "CreateConfigurationSetEventDestination", Map.of(
|
||||
"ConfigurationSetName", name,
|
||||
"EventDestination.Name", "to-sns",
|
||||
"EventDestination.Enabled", "true",
|
||||
"EventDestination.MatchingEventTypes.member.1", "send",
|
||||
"EventDestination.SNSDestination.TopicARN", topicArn))
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>InvalidSNSDestination</Code>"))
|
||||
.body(containsString("Access denied to SNS topic <" + topicArn + ">. Verify the SNS topic "
|
||||
+ "policy grants Amazon SES the sns:Publish permission."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCallerRefusedSnsPublishCannotReachATopicThatRefusesSesThroughAConfigurationSet() {
|
||||
String queueUrl = createQueue(OWNER);
|
||||
String topicArn = createSubscribedTopic(OWNER, queueUrl);
|
||||
setTopicPolicy(OWNER, topicArn, rootOnly(topicArn));
|
||||
String sender = createSender();
|
||||
String user = "ses-only-" + suffix();
|
||||
String accessKeyId = EnforcementFixtures.createUser(cleanup, baseUri.getPort(),
|
||||
@@ -66,6 +86,9 @@ class SesSnsPublishAuthorizationIntegrationTest {
|
||||
"PolicyName", "ses-only", "PolicyDocument", """
|
||||
{"Version":"2012-10-17","Statement":[
|
||||
{"Effect":"Allow","Action":"ses:*","Resource":"*"}]}""")).statusCode(200);
|
||||
// The destination is refused while the topic refuses SES, so the policy changes after it is set.
|
||||
String configurationSet = createConfigurationSet(accessKeyId, topicArn);
|
||||
setTopicPolicy(OWNER, topicArn, rootOnly(topicArn));
|
||||
given()
|
||||
.header("Authorization", EnforcementFixtures.auth(accessKeyId, "sns"))
|
||||
.header("X-Amz-Target", "SNS_20100331.Publish")
|
||||
@@ -76,7 +99,6 @@ class SesSnsPublishAuthorizationIntegrationTest {
|
||||
.then()
|
||||
.statusCode(allOf(greaterThanOrEqualTo(400), lessThan(500)));
|
||||
|
||||
String configurationSet = createConfigurationSet(accessKeyId, topicArn);
|
||||
sendEmail(accessKeyId, sender, SUCCESS, configurationSet);
|
||||
|
||||
assertEquals(0, receive(OWNER, queueUrl));
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.floci.aws.services.ses;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
|
||||
/** Creates the SNS topics that SES settings name, since SES checks a topic when it is set. */
|
||||
final class SnsTopicFixture {
|
||||
|
||||
private SnsTopicFixture() {
|
||||
}
|
||||
|
||||
static String create(String region, String name) {
|
||||
return given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=AKID/20260101/" + region + "/sns/aws4_request")
|
||||
.formParam("Action", "CreateTopic")
|
||||
.formParam("Name", name)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("CreateTopicResponse.CreateTopicResult.TopicArn");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user