feat(rds): add and remove a subscription's source identifiers (#4363)

* feat(rds): add and remove a subscription's source identifiers

SourceIds was write-once. CreateEventSubscription accepts the list and
ModifyEventSubscription has no SourceIds member, so
AddSourceIdentifierToSubscription and RemoveSourceIdentifierFromSubscription
are the only way to change it and neither existed.

Adding an id the subscription already carries is a no-op. The model declares
only SourceNotFoundFault and SubscriptionNotFoundFault for these operations,
so no fault fits a duplicate. Removing an id the subscription does not carry is
SourceNotFound, which is the fault that does fit.

* fix(rds): refuse a missing SubscriptionName as a parameter error

SubscriptionName and SourceIdentifier are both required by the model, and only
the identifier was checked. A missing name fell through to the subscription
lookup and came back as SubscriptionNotFound, telling the caller the
subscription does not exist when the request simply did not name one. The two
required members now fail the same way on both operations.

Also imports assertEquals in the new test rather than qualifying it inline.
This commit is contained in:
lex00 authored and GitHub committed 2026-09-25 07:08:02 -04:00
1 parent 08c6ce0768
commit 6cd1bb3794
4 files changed
+203

No files matched your search

+6
View File
@@ -33,6 +33,8 @@ RDS Data API (`rds-data`) is documented separately because it uses REST JSON rou
| `DescribeEventSubscriptions` | List subscriptions, or the one the request names |
| `ModifyEventSubscription` | Update the members the request names |
| `DeleteEventSubscription` | Delete a subscription |
| `AddSourceIdentifierToSubscription` | Add a source id to a subscription |
| `RemoveSourceIdentifierFromSubscription` | Remove a source id from a subscription |
| `CreateDBSubnetGroup` | Create a DB subnet group; tags given here are readable through `ListTagsForResource` |
| `DescribeDBSubnetGroups` | List DB subnet groups |
| `ModifyDBSubnetGroup` | Update DB subnet group description and subnet list |
@@ -145,6 +147,10 @@ The four subscription actions manage the resource itself. **Nothing is published
A subscription is stored and reported back so a client can manage it. No RDS event reaches SNS
through it, so an SNS subscriber sees nothing.
`SourceIds` is set at create and changed only through `AddSourceIdentifierToSubscription` and
`RemoveSourceIdentifierFromSubscription`, since `ModifyEventSubscription` carries no `SourceIds`
member. Adding an id twice is a no-op, because the model declares no fault that fits a duplicate.
`SnsTopicArn` is required and is not resolved against the SNS service. `SourceType` is checked
against the model's valid values, and a request naming `SourceIds` must also name the `SourceType`
they belong to, as the model requires. An omitted `Enabled` activates the subscription.
@@ -95,6 +95,10 @@ public class RdsQueryHandler {
case "DescribeEventSubscriptions" -> handleDescribeEventSubscriptions(params, region);
case "ModifyEventSubscription" -> handleModifyEventSubscription(params, region);
case "DeleteEventSubscription" -> handleDeleteEventSubscription(params, region);
case "AddSourceIdentifierToSubscription" ->
handleAddSourceIdentifierToSubscription(params, region);
case "RemoveSourceIdentifierFromSubscription" ->
handleRemoveSourceIdentifierFromSubscription(params, region);
case "CreateDBSubnetGroup" -> handleCreateDbSubnetGroup(params, region);
case "DescribeDBSubnetGroups" -> handleDescribeDbSubnetGroups(params, region);
case "ModifyDBSubnetGroup" -> handleModifyDbSubnetGroup(params, region);
@@ -308,6 +312,22 @@ public class RdsQueryHandler {
new XmlBuilder().raw(eventSubscriptionXml(subscription)).build())).build();
}
private Response handleAddSourceIdentifierToSubscription(
MultivaluedMap<String, String> params, String region) {
EventSubscription subscription = service.addSourceIdentifierToSubscription(region,
params.getFirst("SubscriptionName"), params.getFirst("SourceIdentifier"));
return Response.ok(AwsQueryResponse.envelope("AddSourceIdentifierToSubscription",
AwsNamespaces.RDS, new XmlBuilder().raw(eventSubscriptionXml(subscription)).build())).build();
}
private Response handleRemoveSourceIdentifierFromSubscription(
MultivaluedMap<String, String> params, String region) {
EventSubscription subscription = service.removeSourceIdentifierFromSubscription(region,
params.getFirst("SubscriptionName"), params.getFirst("SourceIdentifier"));
return Response.ok(AwsQueryResponse.envelope("RemoveSourceIdentifierFromSubscription",
AwsNamespaces.RDS, new XmlBuilder().raw(eventSubscriptionXml(subscription)).build())).build();
}
private Response handleDeleteEventSubscription(MultivaluedMap<String, String> params, String region) {
EventSubscription subscription = service.deleteEventSubscription(region,
params.getFirst("SubscriptionName"));
@@ -8588,6 +8588,59 @@ public class RdsService implements Resettable, ResourceProvider {
return subscription;
}
/**
* AddSourceIdentifierToSubscription. The list is otherwise write-once, because
* ModifyEventSubscription carries no SourceIds member.
*
* <p>Adding an id the subscription already carries is a no-op rather than an error. The model
* declares only SourceNotFoundFault and SubscriptionNotFoundFault for this operation, so there
* is no fault to raise for a duplicate.
*/
public synchronized EventSubscription addSourceIdentifierToSubscription(
String region, String subscriptionName, String sourceIdentifier) {
requireSourceIdentifierRequest(subscriptionName, sourceIdentifier);
EventSubscription subscription = requireEventSubscription(region, subscriptionName);
List<String> ids = new ArrayList<>(subscription.getSourceIdsList());
if (!ids.contains(sourceIdentifier)) {
ids.add(sourceIdentifier);
subscription.setSourceIdsList(ids);
eventSubscriptions.put(eventSubscriptionKey(region, subscriptionName), subscription);
}
return subscription;
}
/**
* RemoveSourceIdentifierFromSubscription. An id the subscription does not carry is
* SourceNotFound, which is the fault the model declares and the only one that fits.
*/
public synchronized EventSubscription removeSourceIdentifierFromSubscription(
String region, String subscriptionName, String sourceIdentifier) {
requireSourceIdentifierRequest(subscriptionName, sourceIdentifier);
EventSubscription subscription = requireEventSubscription(region, subscriptionName);
List<String> ids = new ArrayList<>(subscription.getSourceIdsList());
if (!ids.remove(sourceIdentifier)) {
throw new AwsException("SourceNotFound",
"Source " + sourceIdentifier + " not found in subscription " + subscriptionName + ".", 404);
}
subscription.setSourceIdsList(ids);
eventSubscriptions.put(eventSubscriptionKey(region, subscriptionName), subscription);
return subscription;
}
/**
* Both members are required by the model, so both fail the same way. Letting a missing
* SubscriptionName fall through to the lookup would answer SubscriptionNotFound, which tells
* the caller the subscription does not exist when the request simply did not name one.
*/
private static void requireSourceIdentifierRequest(String subscriptionName, String sourceIdentifier) {
if (subscriptionName == null || subscriptionName.isBlank()) {
throw new AwsException("InvalidParameterValue", "SubscriptionName is required.", 400);
}
if (sourceIdentifier == null || sourceIdentifier.isBlank()) {
throw new AwsException("InvalidParameterValue", "SourceIdentifier is required.", 400);
}
}
public synchronized EventSubscription deleteEventSubscription(String region, String subscriptionName) {
EventSubscription subscription = requireEventSubscription(region, subscriptionName);
eventSubscriptions.delete(eventSubscriptionKey(region, subscriptionName));
@@ -0,0 +1,124 @@
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.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
/** AddSourceIdentifierToSubscription and RemoveSourceIdentifierFromSubscription. */
@QuarkusTest
class RdsSourceIdentifierIntegrationTest {
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 subscription(String prefix) {
String name = prefix + "-" + Long.toString(System.nanoTime(), 36);
rds("CreateEventSubscription", "SubscriptionName", name, "SnsTopicArn", TOPIC,
"SourceType", "db-instance", "SourceIds.member.1", "db-one").statusCode(200);
return name;
}
@Test
void anIdentifierCanBeAddedAndRemoved() {
String name = subscription("srcid");
rds("AddSourceIdentifierToSubscription", "SubscriptionName", name,
"SourceIdentifier", "db-two")
.statusCode(200)
.body(containsString("<SourceId>db-one</SourceId>"))
.body(containsString("<SourceId>db-two</SourceId>"));
rds("DescribeEventSubscriptions", "SubscriptionName", name)
.statusCode(200)
.body(containsString("<SourceId>db-two</SourceId>"));
rds("RemoveSourceIdentifierFromSubscription", "SubscriptionName", name,
"SourceIdentifier", "db-two")
.statusCode(200)
.body(not(containsString("<SourceId>db-two</SourceId>")))
.body(containsString("<SourceId>db-one</SourceId>"));
rds("DescribeEventSubscriptions", "SubscriptionName", name)
.statusCode(200)
.body(not(containsString("<SourceId>db-two</SourceId>")));
}
/**
* The model declares only SourceNotFoundFault and SubscriptionNotFoundFault here, so there is
* no fault that fits a duplicate add.
*/
@Test
void addingAnIdentifierTwiceIsANoOp() {
String name = subscription("dup");
rds("AddSourceIdentifierToSubscription", "SubscriptionName", name,
"SourceIdentifier", "db-one").statusCode(200);
String body = rds("DescribeEventSubscriptions", "SubscriptionName", name)
.statusCode(200).extract().asString();
int first = body.indexOf("<SourceId>db-one</SourceId>");
int second = body.indexOf("<SourceId>db-one</SourceId>", first + 1);
assertEquals(-1, second,
"db-one appears once, not twice: " + body);
}
@Test
void removingAnIdentifierTheSubscriptionDoesNotCarryIsSourceNotFound() {
String name = subscription("absent");
rds("RemoveSourceIdentifierFromSubscription", "SubscriptionName", name,
"SourceIdentifier", "db-nine")
.statusCode(404)
.body(containsString("SourceNotFound"));
}
@Test
void anUnknownSubscriptionIsSubscriptionNotFound() {
rds("AddSourceIdentifierToSubscription", "SubscriptionName", "no-such-subscription",
"SourceIdentifier", "db-one")
.statusCode(404)
.body(containsString("SubscriptionNotFound"));
rds("RemoveSourceIdentifierFromSubscription", "SubscriptionName", "no-such-subscription",
"SourceIdentifier", "db-one")
.statusCode(404)
.body(containsString("SubscriptionNotFound"));
}
/**
* Both members are required by the model, so both answer InvalidParameterValue. A missing name
* used to reach the lookup and come back as SubscriptionNotFound, which says the subscription
* does not exist when the request simply did not name one.
*/
@Test
void aMissingRequiredMemberIsRefusedTheSameWayOnBothOperations() {
String name = subscription("nosrc");
for (String action : new String[]{"AddSourceIdentifierToSubscription",
"RemoveSourceIdentifierFromSubscription"}) {
rds(action, "SubscriptionName", name)
.statusCode(400)
.body(containsString("InvalidParameterValue"));
rds(action, "SourceIdentifier", "db-one")
.statusCode(400)
.body(containsString("InvalidParameterValue"));
}
}
}