mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix: parse S3 EventBridge notification XML (#3350)
This commit is contained in:
1 parent
9f36a8729f
commit
ad9a88cf7e
2 files changed
+131
-1
No files matched your search
@@ -1779,7 +1779,7 @@ public class S3Controller {
|
||||
new LambdaNotification(parsed.id, parsed.arn, parsed.events, parsed.filterRules));
|
||||
}
|
||||
|
||||
config.setEventBridgeEnabled(xml.contains("<EventBridgeConfiguration"));
|
||||
config.setEventBridgeEnabled(parseEventBridgeConfiguration(xml));
|
||||
|
||||
s3Service.putBucketNotificationConfiguration(bucket, config);
|
||||
return Response.ok().build();
|
||||
@@ -1788,6 +1788,20 @@ public class S3Controller {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean parseEventBridgeConfiguration(String xml) {
|
||||
if (!"NotificationConfiguration".equals(XmlParser.rootElementName(xml))) {
|
||||
throw new AwsException("MalformedXML", "The XML you provided was not well-formed.", 400);
|
||||
}
|
||||
List<String> children = XmlParser.childElementNames(xml, "NotificationConfiguration");
|
||||
long eventBridgeConfigurations = children.stream()
|
||||
.filter("EventBridgeConfiguration"::equals)
|
||||
.count();
|
||||
if (eventBridgeConfigurations > 1) {
|
||||
throw new AwsException("MalformedXML", "The XML you provided was not well-formed.", 400);
|
||||
}
|
||||
return eventBridgeConfigurations == 1;
|
||||
}
|
||||
|
||||
private record ParsedNotificationGroup(String id, String arn, List<String> events,
|
||||
List<FilterRule> filterRules) {}
|
||||
|
||||
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
@QuarkusTest
|
||||
class S3EventBridgeNotificationValidationIntegrationTest {
|
||||
|
||||
@Test
|
||||
void namespacedEventBridgeConfigurationIsAccepted() {
|
||||
String bucket = createBucket("namespaced");
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.body("""
|
||||
<s3:NotificationConfiguration xmlns:s3="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<s3:EventBridgeConfiguration/>
|
||||
</s3:NotificationConfiguration>
|
||||
""")
|
||||
.when()
|
||||
.put("/" + bucket + "?notification")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + bucket + "?notification")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<EventBridgeConfiguration"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void malformedNotificationConfigurationIsRejected() {
|
||||
String bucket = createBucket("malformed");
|
||||
|
||||
putNotification(bucket, "<NotificationConfiguration><EventBridgeConfiguration></NotificationConfiguration>")
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>MalformedXML</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventBridgeTextInCommentDoesNotEnableEventBridge() {
|
||||
String bucket = createBucket("comment");
|
||||
|
||||
putNotification(bucket, """
|
||||
<NotificationConfiguration>
|
||||
<!-- <EventBridgeConfiguration/> -->
|
||||
</NotificationConfiguration>
|
||||
""").statusCode(200);
|
||||
|
||||
getNotification(bucket)
|
||||
.statusCode(200)
|
||||
.body(not(containsString("<EventBridgeConfiguration")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void wrongNotificationConfigurationRootIsRejected() {
|
||||
String bucket = createBucket("wrong-root");
|
||||
|
||||
putNotification(bucket, "<OtherConfiguration><EventBridgeConfiguration/></OtherConfiguration>")
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>MalformedXML</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void duplicateEventBridgeConfigurationsAreRejected() {
|
||||
String bucket = createBucket("duplicate");
|
||||
|
||||
putNotification(bucket, """
|
||||
<NotificationConfiguration>
|
||||
<EventBridgeConfiguration/>
|
||||
<EventBridgeConfiguration/>
|
||||
</NotificationConfiguration>
|
||||
""")
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>MalformedXML</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyNotificationConfigurationDisablesEventBridge() {
|
||||
String bucket = createBucket("empty");
|
||||
|
||||
putNotification(bucket, "<NotificationConfiguration/>").statusCode(200);
|
||||
|
||||
getNotification(bucket)
|
||||
.statusCode(200)
|
||||
.body(not(containsString("<EventBridgeConfiguration")));
|
||||
}
|
||||
|
||||
private static String createBucket(String suffix) {
|
||||
String bucket = "eventbridge-validation-" + suffix;
|
||||
given().when().put("/" + bucket).then().statusCode(200);
|
||||
return bucket;
|
||||
}
|
||||
|
||||
private static io.restassured.response.ValidatableResponse putNotification(String bucket, String body) {
|
||||
return given()
|
||||
.contentType("application/xml")
|
||||
.body(body)
|
||||
.when()
|
||||
.put("/" + bucket + "?notification")
|
||||
.then();
|
||||
}
|
||||
|
||||
private static io.restassured.response.ValidatableResponse getNotification(String bucket) {
|
||||
return given()
|
||||
.when()
|
||||
.get("/" + bucket + "?notification")
|
||||
.then();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user