mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(rds): reject malformed event subscription flags (#5481)
This commit is contained in:
1 parent
a96cc04fab
commit
eb3c14d414
4 files changed
+116
-3
No files matched your search
@@ -188,8 +188,11 @@ including empty strings, return `InvalidParameterValue` before changing resource
|
||||
| `ModifyDBProxy` | `RequireTLS`, `DebugLogging` | Preserves the current value |
|
||||
| `ResetDBParameterGroup`, `ResetDBClusterParameterGroup` | `ResetAllParameters` | Defaults to `false`; named parameter resets keep their existing behavior |
|
||||
| `CopyDBClusterSnapshot` | `CopyTags` | Defaults to `false`; explicit request tags still apply |
|
||||
| `CreateEventSubscription` | `Enabled` | Defaults to `true` |
|
||||
| `ModifyEventSubscription` | `Enabled` | Preserves the current value |
|
||||
|
||||
Malformed reset flags leave saved parameter overrides unchanged.
|
||||
Malformed reset flags leave saved parameter overrides unchanged. Malformed event-subscription
|
||||
flags leave the subscription and its topic, source type and event categories unchanged.
|
||||
|
||||
|
||||
## Event notification subscriptions
|
||||
|
||||
@@ -313,7 +313,7 @@ public class RdsQueryHandler {
|
||||
params.getFirst("SourceType"),
|
||||
memberList(params, "SourceIds"),
|
||||
memberList(params, "EventCategories"),
|
||||
optionalBoolean(params.getFirst("Enabled")),
|
||||
parseOptionalBoolean(params, "Enabled"),
|
||||
parseTags(params));
|
||||
return Response.ok(AwsQueryResponse.envelope("CreateEventSubscription", AwsNamespaces.RDS,
|
||||
new XmlBuilder().raw(eventSubscriptionXml(subscription)).build())).build();
|
||||
@@ -325,7 +325,7 @@ public class RdsQueryHandler {
|
||||
params.getFirst("SnsTopicArn"),
|
||||
params.getFirst("SourceType"),
|
||||
memberList(params, "EventCategories"),
|
||||
optionalBoolean(params.getFirst("Enabled")));
|
||||
parseOptionalBoolean(params, "Enabled"));
|
||||
return Response.ok(AwsQueryResponse.envelope("ModifyEventSubscription", AwsNamespaces.RDS,
|
||||
new XmlBuilder().raw(eventSubscriptionXml(subscription)).build())).build();
|
||||
}
|
||||
|
||||
+58
@@ -4,6 +4,8 @@ import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
@@ -34,6 +36,62 @@ class RdsEventSubscriptionIntegrationTest {
|
||||
return prefix + "-" + Long.toString(System.nanoTime(), 36);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"yes", "", " true "})
|
||||
void malformedEnabledDoesNotCreateASubscription(String enabled) {
|
||||
String subscription = name("invalid-enabled");
|
||||
try {
|
||||
rds("CreateEventSubscription", "SubscriptionName", subscription, "SnsTopicArn", TOPIC,
|
||||
"Enabled", enabled).statusCode(400)
|
||||
.body(containsString("InvalidParameterValue"))
|
||||
.body(containsString("Enabled must be true or false."));
|
||||
rds("DescribeEventSubscriptions", "SubscriptionName", subscription).statusCode(404);
|
||||
} finally {
|
||||
rds("DeleteEventSubscription", "SubscriptionName", subscription);
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"yes", "", " true "})
|
||||
void malformedEnabledLeavesTheSubscriptionUnchanged(String enabled) {
|
||||
String subscription = name("unchanged-enabled");
|
||||
rds("CreateEventSubscription", "SubscriptionName", subscription, "SnsTopicArn", TOPIC,
|
||||
"SourceType", "db-instance", "EventCategories.member.1", "availability").statusCode(200);
|
||||
try {
|
||||
rds("ModifyEventSubscription", "SubscriptionName", subscription,
|
||||
"SnsTopicArn", "arn:aws:sns:us-east-1:000000000000:changed",
|
||||
"SourceType", "db-cluster", "EventCategories.member.1", "failure",
|
||||
"Enabled", enabled).statusCode(400)
|
||||
.body(containsString("InvalidParameterValue"));
|
||||
rds("DescribeEventSubscriptions", "SubscriptionName", subscription).statusCode(200)
|
||||
.body(containsString("<SnsTopicArn>" + TOPIC + "</SnsTopicArn>"))
|
||||
.body(containsString("<SourceType>db-instance</SourceType>"))
|
||||
.body(containsString("<EventCategory>availability</EventCategory>"))
|
||||
.body(not(containsString("<EventCategory>failure</EventCategory>")))
|
||||
.body(containsString("<Enabled>true</Enabled>"));
|
||||
} finally {
|
||||
rds("DeleteEventSubscription", "SubscriptionName", subscription).statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void enabledPreservesCreateDefaultAndOmittedModifyState() {
|
||||
String subscription = name("enabled-default");
|
||||
rds("CreateEventSubscription", "SubscriptionName", subscription, "SnsTopicArn", TOPIC)
|
||||
.statusCode(200).body(containsString("<Enabled>true</Enabled>"));
|
||||
try {
|
||||
for (String enabled : new String[]{"FaLsE", "TrUe"}) {
|
||||
String expected = "<Enabled>" + Boolean.parseBoolean(enabled) + "</Enabled>";
|
||||
rds("ModifyEventSubscription", "SubscriptionName", subscription, "Enabled", enabled)
|
||||
.statusCode(200).body(containsString(expected));
|
||||
rds("ModifyEventSubscription", "SubscriptionName", subscription)
|
||||
.statusCode(200).body(containsString(expected));
|
||||
}
|
||||
} finally {
|
||||
rds("DeleteEventSubscription", "SubscriptionName", subscription).statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDescribeModifyAndDelete() {
|
||||
String subscription = name("sub");
|
||||
|
||||
@@ -19,6 +19,7 @@ import io.github.hectorvent.floci.services.rds.model.DbProxyTarget;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbSnapshot;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.EventSubscription;
|
||||
import io.github.hectorvent.floci.services.rds.model.OptionGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.OptionGroupOption;
|
||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
||||
@@ -63,6 +64,57 @@ class RdsQueryHandlerTest {
|
||||
handler = new RdsQueryHandler(service, config, docDbHandler, neptuneHandler);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"CreateEventSubscription", "ModifyEventSubscription"})
|
||||
void eventSubscriptionEnabledRejectsMalformedValuesBeforeServiceCalls(String action) {
|
||||
for (String invalid : List.of("yes", "", " true ")) {
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.putSingle("SubscriptionName", "events");
|
||||
p.putSingle("SnsTopicArn", "arn:aws:sns:us-east-1:000000000000:events");
|
||||
p.putSingle("Enabled", invalid);
|
||||
Response response = handler.handle(action, p, "us-east-1");
|
||||
assertEquals(400, response.getStatus());
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<Code>InvalidParameterValue</Code>"));
|
||||
assertTrue(body.contains("Enabled must be true or false."));
|
||||
verifyNoInteractions(service);
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullSource
|
||||
@ValueSource(strings = {"true", "false", "TrUe", "FaLsE"})
|
||||
void createEventSubscriptionEnabledPreservesValuesAndOmission(String value) {
|
||||
Boolean expected = value == null ? null : Boolean.valueOf(value);
|
||||
when(service.createEventSubscription(eq("us-east-1"), eq("events"), isNull(), isNull(),
|
||||
anyList(), anyList(), eq(expected), anyMap())).thenReturn(new EventSubscription());
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.putSingle("SubscriptionName", "events");
|
||||
if (value != null) {
|
||||
p.putSingle("Enabled", value);
|
||||
}
|
||||
assertEquals(200, handler.handle("CreateEventSubscription", p, "us-east-1").getStatus());
|
||||
verify(service).createEventSubscription(eq("us-east-1"), eq("events"), isNull(), isNull(),
|
||||
anyList(), anyList(), eq(expected), anyMap());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullSource
|
||||
@ValueSource(strings = {"true", "false", "TrUe", "FaLsE"})
|
||||
void modifyEventSubscriptionEnabledPreservesValuesAndOmission(String value) {
|
||||
Boolean expected = value == null ? null : Boolean.valueOf(value);
|
||||
when(service.modifyEventSubscription(eq("us-east-1"), eq("events"), isNull(), isNull(),
|
||||
anyList(), eq(expected))).thenReturn(new EventSubscription());
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.putSingle("SubscriptionName", "events");
|
||||
if (value != null) {
|
||||
p.putSingle("Enabled", value);
|
||||
}
|
||||
assertEquals(200, handler.handle("ModifyEventSubscription", p, "us-east-1").getStatus());
|
||||
verify(service).modifyEventSubscription(eq("us-east-1"), eq("events"), isNull(), isNull(),
|
||||
anyList(), eq(expected));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"ResetDBParameterGroup, DBParameterGroupName",
|
||||
|
||||
Reference in new issue
Block a user