mirror of
https://github.com/floci-io/floci.git
synced 2026-11-25 14:57:54 -05:00
fix(ses): validate EventBridge default bus ARNs (#4677)
* fix(ses): validate EventBridge default bus ARNs Signed-off-by: boulea7 <zln1905391059@163.com> * fix(ses): reject EventBridge bus account and Region mismatches Signed-off-by: boulea7 <zln1905391059@163.com> --------- Signed-off-by: boulea7 <zln1905391059@163.com>
This commit is contained in:
1 parent
8ff1eae121
commit
d267ba3a9d
8 files changed
+652
-34
No files matched your search
+71
@@ -7,14 +7,18 @@ import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import software.amazon.awssdk.awscore.exception.AwsServiceException;
|
||||
import software.amazon.awssdk.services.ses.SesClient;
|
||||
import software.amazon.awssdk.services.sesv2.SesV2Client;
|
||||
import software.amazon.awssdk.services.sesv2.model.BadRequestException;
|
||||
import software.amazon.awssdk.services.sesv2.model.CreateConfigurationSetEventDestinationRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.CreateConfigurationSetRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.DeleteConfigurationSetEventDestinationRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.DeleteConfigurationSetRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.EventBridgeDestination;
|
||||
import software.amazon.awssdk.services.sesv2.model.EventDestinationDefinition;
|
||||
import software.amazon.awssdk.services.sesv2.model.EventType;
|
||||
import software.amazon.awssdk.services.sesv2.model.GetConfigurationSetEventDestinationsRequest;
|
||||
@@ -43,6 +47,8 @@ class SesConfigurationSetEventDestinationTest {
|
||||
private static final String ED_NAME = "ed-sns";
|
||||
private static final String TOPIC_ARN = "arn:aws:sns:us-east-1:000000000000:ses-events";
|
||||
private static final String TOPIC_ARN_2 = "arn:aws:sns:us-east-1:000000000000:ses-events-2";
|
||||
private static final String DEFAULT_BUS_ARN = "arn:aws:events:us-east-1:000000000000:event-bus/default";
|
||||
private static final String CUSTOM_BUS_ARN = "arn:aws:events:us-east-1:000000000000:event-bus/custom";
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
@@ -224,6 +230,71 @@ class SesConfigurationSetEventDestinationTest {
|
||||
.isEqualTo(404);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@CsvSource({
|
||||
"custom," + CUSTOM_BUS_ARN,
|
||||
"mismatched-account,arn:aws:events:us-east-1:111111111111:event-bus/default",
|
||||
"mismatched-region,arn:aws:events:us-west-2:000000000000:event-bus/default"
|
||||
})
|
||||
@Order(9)
|
||||
void v2_eventBridgeDefaultBusAcceptedAndInvalidBusRejected(String caseName, String rejectedBusArn) {
|
||||
String destinationName = "ed-eventbridge-" + caseName;
|
||||
sesV2.createConfigurationSetEventDestination(CreateConfigurationSetEventDestinationRequest.builder()
|
||||
.configurationSetName(v2CsName)
|
||||
.eventDestinationName(destinationName)
|
||||
.eventDestination(EventDestinationDefinition.builder()
|
||||
.enabled(true)
|
||||
.matchingEventTypes(EventType.SEND)
|
||||
.eventBridgeDestination(EventBridgeDestination.builder().eventBusArn(DEFAULT_BUS_ARN).build())
|
||||
.build())
|
||||
.build());
|
||||
|
||||
try {
|
||||
assertThatThrownBy(() -> sesV2.createConfigurationSetEventDestination(
|
||||
CreateConfigurationSetEventDestinationRequest.builder()
|
||||
.configurationSetName(v2CsName)
|
||||
.eventDestinationName("ed-invalid-" + caseName)
|
||||
.eventDestination(EventDestinationDefinition.builder()
|
||||
.matchingEventTypes(EventType.SEND)
|
||||
.eventBridgeDestination(EventBridgeDestination.builder().eventBusArn(rejectedBusArn).build())
|
||||
.build())
|
||||
.build()))
|
||||
.isInstanceOf(BadRequestException.class)
|
||||
.extracting(e -> ((AwsServiceException) e).statusCode())
|
||||
.isEqualTo(400);
|
||||
|
||||
assertThatThrownBy(() -> sesV2.updateConfigurationSetEventDestination(
|
||||
UpdateConfigurationSetEventDestinationRequest.builder()
|
||||
.configurationSetName(v2CsName)
|
||||
.eventDestinationName(destinationName)
|
||||
.eventDestination(EventDestinationDefinition.builder()
|
||||
.enabled(false)
|
||||
.matchingEventTypes(EventType.BOUNCE)
|
||||
.eventBridgeDestination(EventBridgeDestination.builder().eventBusArn(rejectedBusArn).build())
|
||||
.build())
|
||||
.build()))
|
||||
.isInstanceOf(BadRequestException.class)
|
||||
.extracting(e -> ((AwsServiceException) e).statusCode())
|
||||
.isEqualTo(400);
|
||||
|
||||
GetConfigurationSetEventDestinationsResponse response =
|
||||
sesV2.getConfigurationSetEventDestinations(GetConfigurationSetEventDestinationsRequest.builder()
|
||||
.configurationSetName(v2CsName)
|
||||
.build());
|
||||
assertThat(response.eventDestinations()).hasSize(1);
|
||||
assertThat(response.eventDestinations().get(0).name()).isEqualTo(destinationName);
|
||||
assertThat(response.eventDestinations().get(0).enabled()).isTrue();
|
||||
assertThat(response.eventDestinations().get(0).matchingEventTypes()).containsExactly(EventType.SEND);
|
||||
assertThat(response.eventDestinations().get(0).eventBridgeDestination().eventBusArn())
|
||||
.isEqualTo(DEFAULT_BUS_ARN);
|
||||
} finally {
|
||||
sesV2.deleteConfigurationSetEventDestination(DeleteConfigurationSetEventDestinationRequest.builder()
|
||||
.configurationSetName(v2CsName)
|
||||
.eventDestinationName(destinationName)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────── V1 (Query/XML) ───────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user