feat(docdb): support cluster snapshots and restores (#7585)

Adds CreateDBClusterSnapshot, DeleteDBClusterSnapshot, RestoreDBClusterFromSnapshot and RestoreDBClusterToPointInTime, and makes DescribeDBClusterSnapshots list stored snapshots. A snapshot is a mongodump archive of the cluster's MongoDB container; rds-signed requests naming a DocumentDB cluster or snapshot are routed to DocumentDB.

fix(docdb): round out cluster snapshots and restores after review

List DocumentDB snapshots in the RDS-family list form on either endpoint, accept snapshot ARNs, keep the source's encryption and key on restore, check restore and snapshot identifiers against RDS too, read a point-in-time restore's data as a snapshot does, refuse RestoreToTime, apply every describe filter, and remove a cluster whose restore failed even under deletion protection. Drop the unrelated endpoint host, container-name host and audit log group changes. Cover the archive reaching the restored cluster outside mock mode.

Read a snapshot's record and archive together under the snapshot lock delete takes, and refuse a restore whose archive is missing or empty before any cluster exists; a snapshot taken in mock mode is marked metadata-only and restores only in mock mode. A KmsKeyId on RestoreDBClusterFromSnapshot now encrypts the restored cluster under that key even when the snapshot is unencrypted, as the restore guide allows; the point-in-time restore still refuses one for an unencrypted source. Share the docdb-scoped request in the integration test.
This commit is contained in:
jibin-jusdb authored and GitHub committed 2026-11-07 09:58:08 -04:00
1 parent 5fe30ee5eb
commit 46a8cbe51d
13 files changed
+1260 -19

No files matched your search

@@ -0,0 +1,307 @@
package io.floci.aws.services.docdb;
import io.floci.aws.testing.DocDbMockProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.specification.RequestSpecification;
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 static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
/**
* Cluster snapshots and the two restores. Requests are signed for {@code rds}, as the AWS CLI and
* SDKs sign DocumentDB calls, so they reach DocumentDB only through the routing that recognizes a
* DocumentDB cluster or snapshot named in the request.
*/
@QuarkusTest
@TestProfile(DocDbMockProfile.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class DocDbClusterSnapshotIntegrationTest {
private static final String FORM = "application/x-www-form-urlencoded";
private static final String CLUSTER_ID = "snap-source-cluster";
private static final String SNAPSHOT_ID = "snap-source-cluster-manual";
private static final String RESTORED_ID = "snap-restored-cluster";
private static final String POINT_IN_TIME_ID = "snap-point-in-time-cluster";
private static final String LISTED_SNAPSHOT_ID = "snap-source-cluster-listed";
private static final String ARN_RESTORED_ID = "snap-arn-restored-cluster";
private static final String MASTER_USERNAME = "docdbadmin";
private static final String MASTER_PASSWORD = "secret99password";
private static final String AUTH_RDS_SCOPE =
"AWS4-HMAC-SHA256 Credential=test/20260615/us-east-1/rds/aws4_request, "
+ "SignedHeaders=content-type;host, Signature=test";
private static String listedSnapshotArn;
@Test
@Order(1)
void createSourceCluster() {
request("CreateDBCluster")
.formParam("DBClusterIdentifier", CLUSTER_ID)
.formParam("Engine", "docdb")
.formParam("MasterUsername", MASTER_USERNAME)
.formParam("MasterUserPassword", MASTER_PASSWORD)
.when().post("/")
.then()
.statusCode(200)
.body(containsString(CLUSTER_ID));
}
@Test
@Order(2)
void createSnapshotIsAvailableAtOnce() {
request("CreateDBClusterSnapshot")
.formParam("DBClusterSnapshotIdentifier", SNAPSHOT_ID)
.formParam("DBClusterIdentifier", CLUSTER_ID)
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<CreateDBClusterSnapshotResponse"))
.body(containsString("<DBClusterSnapshotIdentifier>" + SNAPSHOT_ID + "</DBClusterSnapshotIdentifier>"))
.body(containsString("<DBClusterIdentifier>" + CLUSTER_ID + "</DBClusterIdentifier>"))
.body(containsString("<Engine>docdb</Engine>"))
.body(containsString("<Status>available</Status>"))
.body(containsString("<SnapshotType>manual</SnapshotType>"))
.body(containsString(":cluster-snapshot:" + SNAPSHOT_ID))
.body(not(containsString(MASTER_PASSWORD)));
}
@Test
@Order(3)
void createSnapshotWithATakenIdentifierFails() {
request("CreateDBClusterSnapshot")
.formParam("DBClusterSnapshotIdentifier", SNAPSHOT_ID)
.formParam("DBClusterIdentifier", CLUSTER_ID)
.when().post("/")
.then()
.statusCode(400)
.body(containsString("DBClusterSnapshotAlreadyExistsFault"));
}
@Test
@Order(4)
void describeSnapshotsOfTheCluster() {
request("DescribeDBClusterSnapshots")
.formParam("DBClusterIdentifier", CLUSTER_ID)
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DBClusterSnapshotIdentifier>" + SNAPSHOT_ID + "</DBClusterSnapshotIdentifier>"));
}
@Test
@Order(5)
void restoreFromSnapshotCreatesAClusterWithTheSnapshotsMasterUser() {
request("RestoreDBClusterFromSnapshot")
.formParam("DBClusterIdentifier", RESTORED_ID)
.formParam("SnapshotIdentifier", SNAPSHOT_ID)
.formParam("Engine", "docdb")
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<RestoreDBClusterFromSnapshotResponse"))
.body(containsString("<DBClusterIdentifier>" + RESTORED_ID + "</DBClusterIdentifier>"))
.body(containsString("<MasterUsername>" + MASTER_USERNAME + "</MasterUsername>"));
}
@Test
@Order(6)
void restoreToPointInTimeCreatesAClusterFromTheSource() {
request("RestoreDBClusterToPointInTime")
.formParam("DBClusterIdentifier", POINT_IN_TIME_ID)
.formParam("SourceDBClusterIdentifier", CLUSTER_ID)
.formParam("UseLatestRestorableTime", "true")
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<RestoreDBClusterToPointInTimeResponse"))
.body(containsString("<DBClusterIdentifier>" + POINT_IN_TIME_ID + "</DBClusterIdentifier>"))
.body(containsString("<MasterUsername>" + MASTER_USERNAME + "</MasterUsername>"));
}
@Test
@Order(7)
void restoredClustersAreDocDbClusters() {
request("DescribeDBClusters")
.formParam("DBClusterIdentifier", RESTORED_ID)
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<Engine>docdb</Engine>"));
}
@Test
@Order(8)
void deleteSnapshot() {
request("DeleteDBClusterSnapshot")
.formParam("DBClusterSnapshotIdentifier", SNAPSHOT_ID)
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DeleteDBClusterSnapshotResponse"))
.body(containsString("<DBClusterSnapshotIdentifier>" + SNAPSHOT_ID + "</DBClusterSnapshotIdentifier>"));
}
@Test
@Order(9)
void aDeletedSnapshotIsGoneFromTheCluster() {
request("DescribeDBClusterSnapshots")
.formParam("DBClusterIdentifier", CLUSTER_ID)
.when().post("/")
.then()
.statusCode(200)
.body(not(containsString(SNAPSHOT_ID)));
}
@Test
@Order(10)
void snapshotOfAnUnknownClusterIsNotFound() {
docDbRequest("CreateDBClusterSnapshot")
.formParam("DBClusterSnapshotIdentifier", "orphan-snapshot")
.formParam("DBClusterIdentifier", "no-such-cluster")
.when().post("/")
.then()
.statusCode(404)
.body(containsString("DBClusterNotFoundFault"));
}
@Test
@Order(11)
void takeASnapshotForTheListingAndArnChecks() {
String body = request("CreateDBClusterSnapshot")
.formParam("DBClusterSnapshotIdentifier", LISTED_SNAPSHOT_ID)
.formParam("DBClusterIdentifier", CLUSTER_ID)
.when().post("/")
.then()
.statusCode(200)
.extract().asString();
listedSnapshotArn = body.substring(body.indexOf("<DBClusterSnapshotArn>") + "<DBClusterSnapshotArn>".length(),
body.indexOf("</DBClusterSnapshotArn>"));
}
@Test
@Order(12)
void theRdsListFormIncludesDocDbSnapshots() {
request("DescribeDBClusterSnapshots")
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DBClusterSnapshotIdentifier>" + LISTED_SNAPSHOT_ID + "</DBClusterSnapshotIdentifier>"));
}
@Test
@Order(13)
void theDocDbListFormIncludesDocDbSnapshots() {
docDbRequest("DescribeDBClusterSnapshots")
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DBClusterSnapshotIdentifier>" + LISTED_SNAPSHOT_ID + "</DBClusterSnapshotIdentifier>"));
}
@Test
@Order(14)
void theDbClusterIdFilterNarrowsTheRdsListForm() {
request("DescribeDBClusterSnapshots")
.formParam("Filters.Filter.1.Name", "db-cluster-id")
.formParam("Filters.Filter.1.Values.Value.1", CLUSTER_ID)
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DBClusterSnapshotIdentifier>" + LISTED_SNAPSHOT_ID + "</DBClusterSnapshotIdentifier>"));
request("DescribeDBClusterSnapshots")
.formParam("Filters.Filter.1.Name", "db-cluster-id")
.formParam("Filters.Filter.1.Values.Value.1", "another-cluster")
.when().post("/")
.then()
.statusCode(200)
.body(not(containsString(LISTED_SNAPSHOT_ID)));
}
@Test
@Order(15)
void anIdentifierStillHonorsTheOtherFilters() {
request("DescribeDBClusterSnapshots")
.formParam("DBClusterSnapshotIdentifier", LISTED_SNAPSHOT_ID)
.formParam("SnapshotType", "automated")
.when().post("/")
.then()
.statusCode(200)
.body(not(containsString("<DBClusterSnapshotIdentifier>")));
}
@Test
@Order(16)
void restoreFromSnapshotAcceptsTheSnapshotArn() {
request("RestoreDBClusterFromSnapshot")
.formParam("DBClusterIdentifier", ARN_RESTORED_ID)
.formParam("SnapshotIdentifier", listedSnapshotArn)
.formParam("Engine", "docdb")
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DBClusterIdentifier>" + ARN_RESTORED_ID + "</DBClusterIdentifier>"));
}
@Test
@Order(17)
void aSnapshotArnOfAnotherRegionIsNotFound() {
docDbRequest("RestoreDBClusterFromSnapshot")
.formParam("DBClusterIdentifier", "arn-other-region-restore")
.formParam("SnapshotIdentifier", listedSnapshotArn.replace(":us-east-1:", ":eu-west-1:"))
.when().post("/")
.then()
.statusCode(404)
.body(containsString("DBClusterSnapshotNotFoundFault"));
}
@Test
@Order(18)
void aPointInTimeRestoreNeedsTheLatestRestorableTime() {
request("RestoreDBClusterToPointInTime")
.formParam("DBClusterIdentifier", "pitr-requested-time")
.formParam("SourceDBClusterIdentifier", CLUSTER_ID)
.formParam("RestoreToTime", "2026-11-01T00:00:00Z")
.when().post("/")
.then()
.statusCode(400)
.body(containsString("InvalidParameterValue"));
request("RestoreDBClusterToPointInTime")
.formParam("DBClusterIdentifier", "pitr-no-time")
.formParam("SourceDBClusterIdentifier", CLUSTER_ID)
.when().post("/")
.then()
.statusCode(400)
.body(containsString("InvalidParameterCombination"));
request("RestoreDBClusterToPointInTime")
.formParam("DBClusterIdentifier", "pitr-both-times")
.formParam("SourceDBClusterIdentifier", CLUSTER_ID)
.formParam("RestoreToTime", "2026-11-01T00:00:00Z")
.formParam("UseLatestRestorableTime", "true")
.when().post("/")
.then()
.statusCode(400)
.body(containsString("InvalidParameterCombination"));
}
private static RequestSpecification request(String action) {
return given()
.header("Authorization", AUTH_RDS_SCOPE)
.contentType(FORM)
.formParam("Action", action);
}
/** As {@link #request}, signed for the docdb endpoint, which dispatches to DocumentDB directly. */
private static RequestSpecification docDbRequest(String action) {
return given()
.header("Authorization", AUTH_RDS_SCOPE.replace("/rds/", "/docdb/"))
.contentType(FORM)
.formParam("Action", action);
}
}
@@ -0,0 +1,250 @@
package io.floci.aws.services.docdb;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.docdb.container.DocDbContainerHandle;
import io.floci.aws.services.docdb.container.DocDbContainerManager;
import io.floci.aws.services.docdb.model.DocDbCluster;
import io.floci.aws.services.docdb.model.DocDbClusterSettings;
import io.floci.aws.services.docdb.model.DocDbClusterSnapshot;
import io.floci.aws.services.ec2.Ec2Service;
import io.floci.aws.services.kms.KmsService;
import io.floci.aws.services.kms.model.KmsKey;
import io.floci.aws.services.rds.RdsService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* Snapshots and restores with a container behind each cluster, the container layer mocked: what a
* snapshot reads from its cluster is what a restore loads into the new one, and the failure paths
* leave nothing behind.
*/
class DocDbClusterSnapshotServiceTest {
private static final String KEY_ARN = "arn:aws:kms:us-east-1:000000000000:key/k1";
private static final String ARCHIVE = "H4sIAAAAAAAA/2NgYGBgBGIQAAAA//8DAP2uCU4MAAAA";
private DocDbService docDbService;
private DocDbContainerManager containerManager;
private EmulatorConfig.DocDbServiceConfig docdbConfig;
private StorageBackend<String, String> archives;
@BeforeEach
void setUp() {
StorageFactory storageFactory = mock(StorageFactory.class);
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> {
StorageBackend<String, Object> store = AccountAwareStorageBackend.inMemory("000000000000");
if ("docdb-cluster-snapshot-data.json".equals(inv.getArgument(1))) {
archives = cast(store);
}
return store;
});
EmulatorConfig config = mock(EmulatorConfig.class);
EmulatorConfig.ServicesConfig servicesConfig = mock(EmulatorConfig.ServicesConfig.class);
docdbConfig = mock(EmulatorConfig.DocDbServiceConfig.class);
when(config.services()).thenReturn(servicesConfig);
when(servicesConfig.docdb()).thenReturn(docdbConfig);
when(docdbConfig.mock()).thenReturn(false);
when(docdbConfig.defaultImage()).thenReturn("mongo:7.0");
containerManager = mock(DocDbContainerManager.class);
// Every cluster gets a container named after it.
when(containerManager.tryStart(anyString(), anyString(), anyString(), anyString(), anyString()))
.thenAnswer(inv -> new DocDbContainerHandle("container-" + inv.getArgument(0),
inv.getArgument(0), "localhost", 27017));
when(containerManager.dumpCluster("container-source")).thenReturn(ARCHIVE);
when(containerManager.masterPassword("container-source")).thenReturn("source-password");
KmsService kmsService = mock(KmsService.class);
KmsKey key = new KmsKey();
key.setKeyId("k1");
key.setArn(KEY_ARN);
key.setEnabled(true);
key.setKeyState("Enabled");
doReturn(key).when(kmsService).describeKey(KEY_ARN, "us-east-1");
docDbService = new DocDbService(config, new RegionResolver("us-east-1", "000000000000"), containerManager,
storageFactory, mock(RdsService.class), mock(Ec2Service.class), kmsService);
}
@Test
void theSnapshotsArchiveReachesTheRestoredClusterWithTheSourcesPassword() {
source(DocDbClusterSettings.defaults());
docDbService.createDbClusterSnapshot("snap", "source", Map.of());
docDbService.restoreDbClusterFromSnapshot("restored", "snap", null, DocDbClusterSettings.defaults(), Map.of());
verify(containerManager).tryStart(eq("restored"), anyString(), eq("admin"), eq("source-password"), anyString());
verify(containerManager).restoreCluster("container-restored", ARCHIVE);
}
@Test
void aPointInTimeRestoreLoadsTheSourcesCurrentData() {
source(DocDbClusterSettings.defaults());
docDbService.restoreDbClusterToPointInTime("copy", "source", DocDbClusterSettings.defaults(), Map.of());
verify(containerManager).dumpCluster("container-source");
verify(containerManager).tryStart(eq("copy"), anyString(), eq("admin"), eq("source-password"), anyString());
verify(containerManager).restoreCluster("container-copy", ARCHIVE);
}
@Test
void aPointInTimeRestoreOfAnUnreadableSourceFailsLikeASnapshotAndCreatesNothing() {
source(DocDbClusterSettings.defaults());
when(containerManager.dumpCluster("container-source")).thenThrow(new IllegalStateException("mongodump exited 1"));
AwsException e = assertThrows(AwsException.class, () -> docDbService.restoreDbClusterToPointInTime(
"copy", "source", DocDbClusterSettings.defaults(), Map.of()));
assertEquals("InvalidDBClusterStateFault", e.getErrorCode());
assertEquals(400, e.getHttpStatus());
assertThrows(AwsException.class, () -> docDbService.getDbCluster("copy"));
verify(containerManager, never()).tryStart(eq("copy"), anyString(), anyString(), anyString(), anyString());
}
@Test
void aFailedLoadRemovesTheRestoredClusterEvenUnderDeletionProtection() {
source(DocDbClusterSettings.defaults());
docDbService.createDbClusterSnapshot("snap", "source", Map.of());
doThrow(new IllegalStateException("mongorestore exited 1"))
.when(containerManager).restoreCluster("container-restored", ARCHIVE);
DocDbClusterSettings protectedCluster = new DocDbClusterSettings(null, null, null, null, null, null,
null, null, true);
AwsException e = assertThrows(AwsException.class, () -> docDbService.restoreDbClusterFromSnapshot(
"restored", "snap", null, protectedCluster, Map.of()));
assertEquals("InvalidRestoreFault", e.getErrorCode());
AwsException gone = assertThrows(AwsException.class, () -> docDbService.getDbCluster("restored"));
assertEquals("DBClusterNotFoundFault", gone.getErrorCode());
verify(containerManager).stop(argThat(handle -> "container-restored".equals(handle.getContainerId())));
}
@Test
void bothRestoresKeepTheSourcesEncryptionAndKey() {
source(new DocDbClusterSettings(null, null, null, true, KEY_ARN, null, null, null, null));
docDbService.createDbClusterSnapshot("snap", "source", Map.of());
DocDbCluster fromSnapshot = docDbService.restoreDbClusterFromSnapshot("restored", "snap", null,
DocDbClusterSettings.defaults(), Map.of());
DocDbCluster pointInTime = docDbService.restoreDbClusterToPointInTime("copy", "source",
DocDbClusterSettings.defaults(), Map.of());
for (DocDbCluster cluster : List.of(fromSnapshot, pointInTime)) {
assertTrue(cluster.isStorageEncrypted(), cluster.getDbClusterIdentifier());
assertEquals(KEY_ARN, cluster.getKmsKeyId(), cluster.getDbClusterIdentifier());
}
}
@Test
void anUnencryptedSnapshotRestoresUnencryptedOrEncryptedUnderANamedKey() {
source(DocDbClusterSettings.defaults());
docDbService.createDbClusterSnapshot("snap", "source", Map.of());
DocDbCluster plain = docDbService.restoreDbClusterFromSnapshot("restored", "snap", null,
DocDbClusterSettings.defaults(), Map.of());
assertFalse(plain.isStorageEncrypted());
assertNull(plain.getKmsKeyId());
DocDbCluster keyed = docDbService.restoreDbClusterFromSnapshot("keyed", "snap", null,
new DocDbClusterSettings(null, null, null, null, KEY_ARN, null, null, null, null), Map.of());
assertTrue(keyed.isStorageEncrypted());
assertEquals(KEY_ARN, keyed.getKmsKeyId());
}
@Test
void aPointInTimeRestoreRefusesAKeyForAnUnencryptedSource() {
source(DocDbClusterSettings.defaults());
AwsException e = assertThrows(AwsException.class, () -> docDbService.restoreDbClusterToPointInTime(
"keyed", "source",
new DocDbClusterSettings(null, null, null, null, KEY_ARN, null, null, null, null), Map.of()));
assertEquals("InvalidParameterCombination", e.getErrorCode());
}
@Test
void aSnapshotWhoseArchiveIsLostIsRefusedBeforeAnyClusterExists() {
source(DocDbClusterSettings.defaults());
docDbService.createDbClusterSnapshot("snap", "source", Map.of());
archives.clear();
AwsException e = assertThrows(AwsException.class, () -> docDbService.restoreDbClusterFromSnapshot(
"restored", "snap", null, DocDbClusterSettings.defaults(), Map.of()));
assertEquals("InvalidDBClusterSnapshotStateFault", e.getErrorCode());
assertThrows(AwsException.class, () -> docDbService.getDbCluster("restored"));
verify(containerManager, never()).tryStart(eq("restored"), anyString(), anyString(), anyString(), anyString());
}
@Test
void aMockModeSnapshotIsMetadataOnlyAndRestoresOnlyInMockMode() {
when(docdbConfig.mock()).thenReturn(true);
source(DocDbClusterSettings.defaults());
DocDbClusterSnapshot snapshot = docDbService.createDbClusterSnapshot("snap", "source", Map.of());
assertTrue(snapshot.isMetadataOnly());
docDbService.restoreDbClusterFromSnapshot("in-mock", "snap", null, DocDbClusterSettings.defaults(), Map.of());
when(docdbConfig.mock()).thenReturn(false);
AwsException e = assertThrows(AwsException.class, () -> docDbService.restoreDbClusterFromSnapshot(
"outside-mock", "snap", null, DocDbClusterSettings.defaults(), Map.of()));
assertEquals("InvalidDBClusterSnapshotStateFault", e.getErrorCode());
verify(containerManager, never()).restoreCluster(anyString(), anyString());
}
@Test
void aSnapshotIsNamedByIdentifierOrByItsOwnArnOnly() {
source(DocDbClusterSettings.defaults());
DocDbClusterSnapshot snapshot = docDbService.createDbClusterSnapshot("snap", "source", Map.of());
String arn = snapshot.getDbClusterSnapshotArn();
assertEquals("snap", docDbService.getDbClusterSnapshot(arn).getDbClusterSnapshotIdentifier());
assertTrue(docDbService.hasClusterSnapshot(arn, "us-east-1"));
String otherRegion = arn.replace(":us-east-1:", ":eu-west-1:");
assertFalse(docDbService.hasClusterSnapshot(otherRegion, "us-east-1"));
assertEquals("DBClusterSnapshotNotFoundFault",
assertThrows(AwsException.class, () -> docDbService.getDbClusterSnapshot(otherRegion)).getErrorCode());
assertEquals("InvalidParameterValue", assertThrows(AwsException.class,
() -> docDbService.getDbClusterSnapshot("arn:aws:rds:us-east-1:000000000000:cluster:source"))
.getErrorCode());
}
@Test
void anIdentifierIsNarrowedByTheClusterAndTypeFilters() {
source(DocDbClusterSettings.defaults());
docDbService.createDbClusterSnapshot("snap", "source", Map.of());
assertEquals(1, docDbService.describeDbClusterSnapshots("snap", "source", "manual").size());
assertTrue(docDbService.describeDbClusterSnapshots("snap", "another-cluster", null).isEmpty());
assertTrue(docDbService.describeDbClusterSnapshots("snap", null, "automated").isEmpty());
}
@SuppressWarnings("unchecked")
private static StorageBackend<String, String> cast(StorageBackend<String, Object> store) {
return (StorageBackend<String, String>) (StorageBackend<?, ?>) store;
}
private void source(DocDbClusterSettings settings) {
docDbService.createDbCluster("source", "5.0.0", "admin", "source-password", false, settings, Map.of());
}
}
@@ -278,7 +278,7 @@ class DocDbIntegrationTest {
given()
.header("Authorization", AUTH)
.contentType(FORM)
.formParam("Action", "RestoreDBClusterFromSnapshot")
.formParam("Action", "CopyDBClusterSnapshot")
.when().post("/")
.then()
.statusCode(400)
@@ -56,6 +56,104 @@ class SharedClusterIdentifierIntegrationTest {
.formParam("Version", "2014-10-31");
}
@Test
void aRestoreCannotTakeAClusterIdentifierRdsAlreadyHolds() {
String held = "restore-target-held-by-rds";
createRdsCluster(held);
createDocDbCluster("restore-source");
query("CreateDBClusterSnapshot")
.formParam("DBClusterIdentifier", "restore-source")
.formParam("DBClusterSnapshotIdentifier", "restore-source-snapshot")
.when().post("/").then().statusCode(200);
query("RestoreDBClusterFromSnapshot")
.formParam("DBClusterIdentifier", held)
.formParam("SnapshotIdentifier", "restore-source-snapshot")
.formParam("Engine", "docdb")
.when().post("/")
.then()
.statusCode(400)
.body(containsString("DBClusterAlreadyExistsFault"));
query("RestoreDBClusterToPointInTime")
.formParam("DBClusterIdentifier", held)
.formParam("SourceDBClusterIdentifier", "restore-source")
.formParam("UseLatestRestorableTime", "true")
.when().post("/")
.then()
.statusCode(400)
.body(containsString("DBClusterAlreadyExistsFault"));
query("DeleteDBClusterSnapshot")
.formParam("DBClusterSnapshotIdentifier", "restore-source-snapshot")
.when().post("/").then().statusCode(200);
deleteCluster("restore-source");
deleteCluster(held);
}
@Test
void aClusterSnapshotIdentifierIsOneSpaceAcrossRdsAndDocumentDb() {
createDocDbCluster("snapshot-space-docdb");
createRdsCluster("snapshot-space-rds");
query("CreateDBClusterSnapshot")
.formParam("DBClusterIdentifier", "snapshot-space-docdb")
.formParam("DBClusterSnapshotIdentifier", "snapshot-space-docdb-first")
.when().post("/").then().statusCode(200);
query("CreateDBClusterSnapshot")
.formParam("DBClusterIdentifier", "snapshot-space-rds")
.formParam("DBClusterSnapshotIdentifier", "snapshot-space-rds-first")
.when().post("/").then().statusCode(200);
// An RDS cluster's snapshot named like a DocumentDB one: refused, not routed to DocumentDB.
query("CreateDBClusterSnapshot")
.formParam("DBClusterIdentifier", "snapshot-space-rds")
.formParam("DBClusterSnapshotIdentifier", "snapshot-space-docdb-first")
.when().post("/")
.then()
.statusCode(400)
.body(containsString("DBClusterSnapshotAlreadyExistsFault"));
// And the reverse.
query("CreateDBClusterSnapshot")
.formParam("DBClusterIdentifier", "snapshot-space-docdb")
.formParam("DBClusterSnapshotIdentifier", "snapshot-space-rds-first")
.when().post("/")
.then()
.statusCode(400)
.body(containsString("DBClusterSnapshotAlreadyExistsFault"));
for (String snapshot : new String[]{"snapshot-space-docdb-first", "snapshot-space-rds-first"}) {
query("DeleteDBClusterSnapshot")
.formParam("DBClusterSnapshotIdentifier", snapshot)
.when().post("/").then().statusCode(200);
}
deleteCluster("snapshot-space-docdb");
deleteCluster("snapshot-space-rds");
}
private static void createRdsCluster(String id) {
query("CreateDBCluster")
.formParam("DBClusterIdentifier", id)
.formParam("Engine", "aurora-postgresql")
.formParam("MasterUsername", "admin")
.formParam("MasterUserPassword", "secret99password")
.when().post("/").then().statusCode(200);
}
private static void createDocDbCluster(String id) {
query("CreateDBCluster")
.formParam("DBClusterIdentifier", id)
.formParam("Engine", "docdb")
.formParam("MasterUsername", "docdbadmin")
.formParam("MasterUserPassword", "secret99password")
.when().post("/").then().statusCode(200);
}
private static void deleteCluster(String id) {
query("DeleteDBCluster")
.formParam("DBClusterIdentifier", id)
.formParam("SkipFinalSnapshot", "true")
.when().post("/").then().statusCode(200);
}
@Test
void docDbCannotTakeAnIdentifierRdsAlreadyHolds() {
query("CreateDBCluster")