mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(rds): manage event notification subscriptions (#4332)
* feat(rds): manage event notification subscriptions CreateEventSubscription, DescribeEventSubscriptions, ModifyEventSubscription and DeleteEventSubscription were all missing, so the subscription resource could not be created. Constraints come from the model. A SubscriptionName under 255 characters, a required SnsTopicArn, SourceType limited to the documented valid values, and a SourceIds list that may only be supplied alongside the SourceType its ids belong to. An omitted Enabled activates the subscription, which the model describes only in the negative: a subscription that is not activated is created but not active. Modify applies only the members the request names. Nothing is published to the topic. A subscription is stored and reported back and no RDS event reaches SNS through it. The docs say so. * fix(rds): synchronize the event subscription methods and cite the SourceIds constraint createEventSubscription checked for a duplicate name and then stored, so two concurrent creates of the same name both passed the check and the second overwrote the first with neither caller seeing SubscriptionAlreadyExist. The four methods are synchronized now, matching the 48 other public synchronized methods in this file and the find-then-throw-then-store shape of createDbSnapshot. The comment on the SourceIds coupling said only that the model states it, which sent a reviewer to the operation documentation where it is absent. It now quotes the constraint and says it lives on CreateEventSubscriptionMessage.SourceIds rather than on the operation. * fix(rds): keep a rejected modify inert, carry subscription tags, and page the describe Four findings from the automated review, all confirmed against the model. ModifyEventSubscription wrote SnsTopicArn before validating SourceType, so a request carrying a new topic and an unmodelled source type answered 400 with the topic already changed. The store returns the live instance, so a later describe reported it. This is the same shape as the Lambda code signing bug in #4286 and I did not carry the lesson across. CreateEventSubscriptionMessage has a Tags member that was dropped on the floor, and resolveTagHandle had no arm for an es: ARN, so a subscription could neither be created with tags nor tagged afterwards. DescribeEventSubscriptionsMessage has MaxRecords and Marker, and its output shape has Marker. None were read or emitted, so a bounded page returned everything with no way to continue. The new test used var, which AGENTS.md prohibits, the same thing flagged on #4286. * fix(rds): bound MaxRecords and resume paging past a deleted marker Two defects I introduced in the pagination added last round. MaxRecords was unbounded. Zero built an empty page and then read its last element, throwing IndexOutOfBoundsException, and a negative value produced invalid bounds. The model documents minimum 20, maximum 100, default 100, and handleDescribeEvents a few hundred lines up already enforces that range. An omitted value now defaults to 100 rather than returning everything. The marker resumed by looking for its own name, so a subscription deleted between calls left the offset at zero and handed back the first page again. Resuming at the first name strictly greater than the marker is stable under deletion. The test used MaxRecords 1, a value the model rejects, so it exercised a page size real RDS never serves. It now creates 21 subscriptions and pages with 20. * fix(rds): validate MaxRecords before the named-subscription shortcut The range check sat after the early return for a named subscription, so a request naming one alongside an out-of-range MaxRecords succeeded. Request validation should not depend on which branch serves the read.
This commit is contained in:
1 parent
dd05c533e5
commit
09dcbabe2b
5 files changed
+549
No files matched your search
+231
@@ -0,0 +1,231 @@
|
||||
package io.github.hectorvent.floci.services.rds;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/** Create, Describe, Modify and Delete for an RDS event notification subscription. */
|
||||
@QuarkusTest
|
||||
class RdsEventSubscriptionIntegrationTest {
|
||||
|
||||
private static final String TOPIC = "arn:aws:sns:us-east-1:000000000000:rds-events";
|
||||
|
||||
private static ValidatableResponse rds(String action, String... formParams) {
|
||||
RequestSpecification request = given()
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=test/20260615/us-east-1/rds/aws4_request, "
|
||||
+ "SignedHeaders=content-type;host, Signature=test")
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", action)
|
||||
.formParam("Version", "2014-10-31");
|
||||
for (int i = 0; i < formParams.length; i += 2) {
|
||||
request = request.formParam(formParams[i], formParams[i + 1]);
|
||||
}
|
||||
return request.when().post("/").then();
|
||||
}
|
||||
|
||||
private static String name(String prefix) {
|
||||
return prefix + "-" + Long.toString(System.nanoTime(), 36);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDescribeModifyAndDelete() {
|
||||
String subscription = name("sub");
|
||||
rds("CreateEventSubscription",
|
||||
"SubscriptionName", subscription,
|
||||
"SnsTopicArn", TOPIC,
|
||||
"SourceType", "db-instance",
|
||||
"SourceIds.member.1", "db-one",
|
||||
"EventCategories.member.1", "availability")
|
||||
.statusCode(200)
|
||||
.body("CreateEventSubscriptionResponse.CreateEventSubscriptionResult.EventSubscription.CustSubscriptionId",
|
||||
equalTo(subscription))
|
||||
.body("CreateEventSubscriptionResponse.CreateEventSubscriptionResult.EventSubscription.Status",
|
||||
equalTo("active"))
|
||||
.body("CreateEventSubscriptionResponse.CreateEventSubscriptionResult.EventSubscription.Enabled",
|
||||
equalTo("true"))
|
||||
.body("CreateEventSubscriptionResponse.CreateEventSubscriptionResult.EventSubscription.SourceIdsList.SourceId",
|
||||
equalTo("db-one"))
|
||||
.body("CreateEventSubscriptionResponse.CreateEventSubscriptionResult.EventSubscription.EventSubscriptionArn",
|
||||
containsString(":es:" + subscription));
|
||||
|
||||
rds("DescribeEventSubscriptions", "SubscriptionName", subscription)
|
||||
.statusCode(200)
|
||||
.body(containsString("<CustSubscriptionId>" + subscription + "</CustSubscriptionId>"));
|
||||
|
||||
rds("ModifyEventSubscription", "SubscriptionName", subscription, "Enabled", "false")
|
||||
.statusCode(200)
|
||||
.body("ModifyEventSubscriptionResponse.ModifyEventSubscriptionResult.EventSubscription.Enabled",
|
||||
equalTo("false"))
|
||||
// SourceType was not named, so it survives the modify.
|
||||
.body("ModifyEventSubscriptionResponse.ModifyEventSubscriptionResult.EventSubscription.SourceType",
|
||||
equalTo("db-instance"));
|
||||
|
||||
rds("DeleteEventSubscription", "SubscriptionName", subscription).statusCode(200);
|
||||
rds("DescribeEventSubscriptions", "SubscriptionName", subscription).statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRejectedModifyChangesNothing() {
|
||||
String subscription = name("atomic");
|
||||
rds("CreateEventSubscription", "SubscriptionName", subscription, "SnsTopicArn", TOPIC,
|
||||
"SourceType", "db-instance").statusCode(200);
|
||||
|
||||
// Valid SnsTopicArn, invalid SourceType. The topic must not survive the 400.
|
||||
rds("ModifyEventSubscription", "SubscriptionName", subscription,
|
||||
"SnsTopicArn", "arn:aws:sns:us-east-1:000000000000:other", "SourceType", "db-widget")
|
||||
.statusCode(400);
|
||||
|
||||
rds("DescribeEventSubscriptions", "SubscriptionName", subscription)
|
||||
.statusCode(200)
|
||||
.body(containsString("<SnsTopicArn>" + TOPIC + "</SnsTopicArn>"))
|
||||
.body(not(containsString("rds-events-other")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagsGivenAtCreateAreReadableThroughListTagsForResource() {
|
||||
String subscription = name("tagged");
|
||||
String arn = rds("CreateEventSubscription", "SubscriptionName", subscription,
|
||||
"SnsTopicArn", TOPIC, "Tags.Tag.1.Key", "team", "Tags.Tag.1.Value", "platform")
|
||||
.statusCode(200)
|
||||
.extract().path("CreateEventSubscriptionResponse.CreateEventSubscriptionResult"
|
||||
+ ".EventSubscription.EventSubscriptionArn");
|
||||
|
||||
rds("ListTagsForResource", "ResourceName", arn)
|
||||
.statusCode(200)
|
||||
.body(containsString("<Key>team</Key>"))
|
||||
.body(containsString("<Value>platform</Value>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeHonoursMaxRecordsAndMarker() {
|
||||
// The model bounds MaxRecords at 20, so a meaningful page needs more than 20 rows.
|
||||
String prefix = "page-" + Long.toString(System.nanoTime(), 36);
|
||||
for (int i = 0; i < 21; i++) {
|
||||
rds("CreateEventSubscription", "SubscriptionName", String.format("%s-%02d", prefix, i),
|
||||
"SnsTopicArn", TOPIC).statusCode(200);
|
||||
}
|
||||
|
||||
String marker = rds("DescribeEventSubscriptions", "MaxRecords", "20")
|
||||
.statusCode(200)
|
||||
.extract().path("DescribeEventSubscriptionsResponse"
|
||||
+ ".DescribeEventSubscriptionsResult.Marker");
|
||||
assertNotNull(marker, "a bounded page short of the end carries a Marker");
|
||||
|
||||
rds("DescribeEventSubscriptions", "MaxRecords", "20", "Marker", marker)
|
||||
.statusCode(200)
|
||||
.body(not(containsString("<CustSubscriptionId>" + marker + "</CustSubscriptionId>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anOutOfRangeMaxRecordsIsRefused() {
|
||||
// 0 used to build an empty page and then read its last element.
|
||||
rds("DescribeEventSubscriptions", "MaxRecords", "0").statusCode(400)
|
||||
.body(containsString("InvalidParameterValue"));
|
||||
rds("DescribeEventSubscriptions", "MaxRecords", "-5").statusCode(400);
|
||||
rds("DescribeEventSubscriptions", "MaxRecords", "19").statusCode(400);
|
||||
rds("DescribeEventSubscriptions", "MaxRecords", "101").statusCode(400);
|
||||
rds("DescribeEventSubscriptions", "MaxRecords", "20").statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void anOutOfRangeMaxRecordsIsRefusedEvenWhenASubscriptionIsNamed() {
|
||||
String subscription = name("named");
|
||||
rds("CreateEventSubscription", "SubscriptionName", subscription, "SnsTopicArn", TOPIC)
|
||||
.statusCode(200);
|
||||
|
||||
// The named-subscription read used to return before the page size was looked at.
|
||||
rds("DescribeEventSubscriptions", "SubscriptionName", subscription, "MaxRecords", "0")
|
||||
.statusCode(400)
|
||||
.body(containsString("InvalidParameterValue"));
|
||||
rds("DescribeEventSubscriptions", "SubscriptionName", subscription, "MaxRecords", "20")
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMarkerWhoseSubscriptionIsGoneDoesNotRestartTheWalk() {
|
||||
String prefix = "gone-" + Long.toString(System.nanoTime(), 36);
|
||||
for (int i = 0; i < 21; i++) {
|
||||
rds("CreateEventSubscription", "SubscriptionName", String.format("%s-%02d", prefix, i),
|
||||
"SnsTopicArn", TOPIC).statusCode(200);
|
||||
}
|
||||
String marker = rds("DescribeEventSubscriptions", "MaxRecords", "20")
|
||||
.statusCode(200)
|
||||
.extract().path("DescribeEventSubscriptionsResponse"
|
||||
+ ".DescribeEventSubscriptionsResult.Marker");
|
||||
assertNotNull(marker);
|
||||
|
||||
rds("DeleteEventSubscription", "SubscriptionName", marker).statusCode(200);
|
||||
|
||||
// Resuming from a name that no longer exists must not hand back the first page again.
|
||||
rds("DescribeEventSubscriptions", "MaxRecords", "20", "Marker", marker)
|
||||
.statusCode(200)
|
||||
.body(not(containsString("<CustSubscriptionId>" + prefix + "-00</CustSubscriptionId>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sourceIdsWithoutASourceTypeIsRefused() {
|
||||
rds("CreateEventSubscription",
|
||||
"SubscriptionName", name("nosrctype"),
|
||||
"SnsTopicArn", TOPIC,
|
||||
"SourceIds.member.1", "db-one")
|
||||
.statusCode(400)
|
||||
.body(containsString("InvalidParameterCombination"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnmodelledSourceTypeIsRefused() {
|
||||
rds("CreateEventSubscription",
|
||||
"SubscriptionName", name("badtype"),
|
||||
"SnsTopicArn", TOPIC,
|
||||
"SourceType", "db-widget")
|
||||
.statusCode(400)
|
||||
.body(containsString("InvalidParameterValue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMissingTopicArnIsRefusedAndASecondCreateClashes() {
|
||||
rds("CreateEventSubscription", "SubscriptionName", name("notopic"))
|
||||
.statusCode(404)
|
||||
.body(containsString("SNSTopicArnNotFound"));
|
||||
|
||||
String subscription = name("dup");
|
||||
rds("CreateEventSubscription", "SubscriptionName", subscription, "SnsTopicArn", TOPIC)
|
||||
.statusCode(200);
|
||||
rds("CreateEventSubscription", "SubscriptionName", subscription, "SnsTopicArn", TOPIC)
|
||||
.statusCode(400)
|
||||
.body(containsString("SubscriptionAlreadyExist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeWithNoNameListsThemAndAnUnknownNameIsNotFound() {
|
||||
String subscription = name("listed");
|
||||
rds("CreateEventSubscription", "SubscriptionName", subscription, "SnsTopicArn", TOPIC)
|
||||
.statusCode(200);
|
||||
|
||||
rds("DescribeEventSubscriptions")
|
||||
.statusCode(200)
|
||||
.body(containsString("<CustSubscriptionId>" + subscription + "</CustSubscriptionId>"));
|
||||
|
||||
rds("DescribeEventSubscriptions", "SubscriptionName", "no-such-subscription")
|
||||
.statusCode(404)
|
||||
.body(containsString("SubscriptionNotFound"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInactiveSubscriptionIsCreatedButNotActive() {
|
||||
String subscription = name("off");
|
||||
rds("CreateEventSubscription",
|
||||
"SubscriptionName", subscription, "SnsTopicArn", TOPIC, "Enabled", "false")
|
||||
.statusCode(200)
|
||||
.body("CreateEventSubscriptionResponse.CreateEventSubscriptionResult.EventSubscription.Enabled",
|
||||
equalTo("false"))
|
||||
.body(not(containsString("<Enabled>true</Enabled>")));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user