mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): replace AWS::S3::Bucket when BucketName changes (#5762)
A change to BucketName is a replacement: CloudFormation creates the new bucket first and then deletes the old one, unless UpdateReplacePolicy is Retain. S3CfnProvisioner created the replacement but never removed the displaced bucket, so a successful rename left both buckets, and a rename that a later resource failed ended in UPDATE_ROLLBACK_FAILED, with DescribeStackResources still naming the new bucket. Record the displaced bucket with ReplacementCleanup and delegate the replacement lifecycle to it, so the committed update deletes the old bucket, honouring UpdateReplacePolicy: Retain, and a rollback points the resource back at the original bucket and deletes the replacement. Route the bucket delete through CfnDeletes.safeDelete so a bucket already gone is tolerated while a real failure such as BucketNotEmpty still propagates and reaches the stack as DELETE_FAILED. Fixes #5678 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
5dcddc9dfa
commit
8298779ead
4 files changed
+515
-13
No files matched your search
+285
@@ -0,0 +1,285 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Replacing updates of {@code AWS::S3::Bucket} through the whole engine. A template that changes
|
||||
* {@code BucketName} replaces the bucket: the new one is created and the old is deleted once the
|
||||
* update commits (unless {@code UpdateReplacePolicy: Retain}), and a later resource that fails the
|
||||
* update rolls the replacement back and points the resource at the original bucket again.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationS3BucketReplacementIntegrationTest {
|
||||
|
||||
/**
|
||||
* A rename the engine can commit: the old bucket is deleted after {@code UPDATE_COMPLETE} and
|
||||
* its {@code DELETE_COMPLETE} event names it.
|
||||
*/
|
||||
@Test
|
||||
void renamingTheBucketDeletesTheOldOneAfterTheUpdateCommits() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "s3-replace-" + suffix;
|
||||
String oldBucket = "s3-replace-old-" + suffix;
|
||||
String newBucket = "s3-replace-new-" + suffix;
|
||||
|
||||
createStack(stackName, template(oldBucket, "", false));
|
||||
assertBucketPresent(oldBucket);
|
||||
|
||||
updateStack(stackName, template(newBucket, "", false));
|
||||
await(stackName, "UPDATE_COMPLETE");
|
||||
|
||||
String describe = describeStack(stackName);
|
||||
assertEquals(newBucket, output(describe, "BucketRef"));
|
||||
assertBucketPresent(newBucket);
|
||||
assertBucketMissing(oldBucket);
|
||||
assertEvent(describeEvents(stackName), "DELETE_COMPLETE", oldBucket);
|
||||
|
||||
deleteStack(stackName);
|
||||
}
|
||||
|
||||
/** {@code UpdateReplacePolicy: Retain} keeps the bucket the rename displaced. */
|
||||
@Test
|
||||
void updateReplacePolicyRetainKeepsTheOldBucket() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "s3-retain-" + suffix;
|
||||
String oldBucket = "s3-retain-old-" + suffix;
|
||||
String newBucket = "s3-retain-new-" + suffix;
|
||||
|
||||
createStack(stackName, template(oldBucket, "", false));
|
||||
updateStack(stackName, template(newBucket, "", true));
|
||||
await(stackName, "UPDATE_COMPLETE");
|
||||
|
||||
assertEquals(newBucket, output(describeStack(stackName), "BucketRef"));
|
||||
assertBucketPresent(newBucket);
|
||||
assertBucketPresent(oldBucket);
|
||||
|
||||
deleteStack(stackName);
|
||||
}
|
||||
|
||||
/**
|
||||
* A rename a later resource fails rolls back: the stack ends in {@code UPDATE_ROLLBACK_COMPLETE},
|
||||
* the resource names the original bucket again, and the replacement the attempt created is gone.
|
||||
*/
|
||||
@Test
|
||||
void aFailedRenameRollsBackToTheOriginalBucket() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "s3-rollback-" + suffix;
|
||||
String oldBucket = "s3-rollback-old-" + suffix;
|
||||
String newBucket = "s3-rollback-new-" + suffix;
|
||||
|
||||
createStack(stackName, template(oldBucket, "", false));
|
||||
assertBucketPresent(oldBucket);
|
||||
|
||||
// SecretString and GenerateSecretString cannot be combined, so the resource after the
|
||||
// bucket fails the update and the rename has to be undone.
|
||||
String failingSecret = """
|
||||
,"Failure":{"Type":"AWS::SecretsManager::Secret","DependsOn":"Bucket",
|
||||
"Properties":{"Name":"s3-rollback-secret-%s","SecretString":"x",
|
||||
"GenerateSecretString":{"PasswordLength":32}}}""".formatted(suffix);
|
||||
updateStack(stackName, template(newBucket, failingSecret, false));
|
||||
await(stackName, "UPDATE_ROLLBACK_COMPLETE");
|
||||
|
||||
String describe = describeStack(stackName);
|
||||
assertEquals(oldBucket, output(describe, "BucketRef"));
|
||||
assertBucketPresent(oldBucket);
|
||||
assertBucketMissing(newBucket);
|
||||
|
||||
deleteStack(stackName);
|
||||
}
|
||||
|
||||
/**
|
||||
* A failed update that changed the bucket's own settings without renaming it restores them: the
|
||||
* same bucket is pointed at a different {@code VersioningConfiguration}, a later resource fails,
|
||||
* and the bucket ends with the versioning status the stack started with.
|
||||
*/
|
||||
@Test
|
||||
void aFailedInPlaceUpdateRestoresTheBucketConfiguration() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "s3-inplace-" + suffix;
|
||||
String bucket = "s3-inplace-" + suffix;
|
||||
|
||||
createStack(stackName, inPlaceTemplate(bucket, "Enabled", ""));
|
||||
assertVersioning(bucket, "Enabled");
|
||||
|
||||
String failingSecret = """
|
||||
,"Failure":{"Type":"AWS::SecretsManager::Secret","DependsOn":"Bucket",
|
||||
"Properties":{"Name":"s3-inplace-secret-%s","SecretString":"x",
|
||||
"GenerateSecretString":{"PasswordLength":32}}}""".formatted(suffix);
|
||||
updateStack(stackName, inPlaceTemplate(bucket, "Suspended", failingSecret));
|
||||
await(stackName, "UPDATE_ROLLBACK_COMPLETE");
|
||||
|
||||
assertVersioning(bucket, "Enabled");
|
||||
|
||||
deleteStack(stackName);
|
||||
}
|
||||
|
||||
/**
|
||||
* A rename onto a name the account already owns creates no bucket, so a failed update rolls the
|
||||
* resource back to the original bucket without deleting the one this update never created.
|
||||
*/
|
||||
@Test
|
||||
void aFailedRenameOntoAnAlreadyOwnedBucketLeavesThatBucketStanding() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "s3-owned-" + suffix;
|
||||
String oldBucket = "s3-owned-old-" + suffix;
|
||||
String ownedBucket = "s3-owned-existing-" + suffix;
|
||||
|
||||
createBucket(ownedBucket);
|
||||
|
||||
createStack(stackName, template(oldBucket, "", false));
|
||||
assertBucketPresent(oldBucket);
|
||||
|
||||
String failingSecret = """
|
||||
,"Failure":{"Type":"AWS::SecretsManager::Secret","DependsOn":"Bucket",
|
||||
"Properties":{"Name":"s3-owned-secret-%s","SecretString":"x",
|
||||
"GenerateSecretString":{"PasswordLength":32}}}""".formatted(suffix);
|
||||
updateStack(stackName, template(ownedBucket, failingSecret, false));
|
||||
await(stackName, "UPDATE_ROLLBACK_COMPLETE");
|
||||
|
||||
String describe = describeStack(stackName);
|
||||
assertEquals(oldBucket, output(describe, "BucketRef"));
|
||||
assertBucketPresent(oldBucket);
|
||||
assertBucketPresent(ownedBucket);
|
||||
|
||||
deleteStack(stackName);
|
||||
}
|
||||
|
||||
private static String inPlaceTemplate(String bucketName, String versioningStatus, String extraResources) {
|
||||
return """
|
||||
{
|
||||
"Resources": {
|
||||
"Bucket": {
|
||||
"Type": "AWS::S3::Bucket",
|
||||
"Properties": {"BucketName": "%s", "VersioningConfiguration": {"Status": "%s"}}
|
||||
}%s
|
||||
}
|
||||
}""".formatted(bucketName, versioningStatus, extraResources);
|
||||
}
|
||||
|
||||
private static String template(String bucketName, String extraResources, boolean retain) {
|
||||
String updateReplacePolicy = retain ? ", \"UpdateReplacePolicy\": \"Retain\"" : "";
|
||||
return """
|
||||
{
|
||||
"Resources": {
|
||||
"Bucket": {
|
||||
"Type": "AWS::S3::Bucket"%1$s,
|
||||
"Properties": { "BucketName": "%2$s" }
|
||||
}%3$s
|
||||
},
|
||||
"Outputs": { "BucketRef": { "Value": { "Ref": "Bucket" } } }
|
||||
}
|
||||
""".formatted(updateReplacePolicy, bucketName, extraResources);
|
||||
}
|
||||
|
||||
private static void createStack(String stackName, String body) {
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack").formParam("Version", "2010-05-15")
|
||||
.formParam("StackName", stackName).formParam("TemplateBody", body)
|
||||
.when().post("/").then().statusCode(200);
|
||||
await(stackName, "CREATE_COMPLETE");
|
||||
}
|
||||
|
||||
private static void updateStack(String stackName, String body) {
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStack").formParam("Version", "2010-05-15")
|
||||
.formParam("StackName", stackName).formParam("TemplateBody", body)
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
private static void deleteStack(String stackName) {
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DeleteStack").formParam("Version", "2010-05-15")
|
||||
.formParam("StackName", stackName)
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
private static String describeStack(String stackName) {
|
||||
return given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks").formParam("Version", "2010-05-15")
|
||||
.formParam("StackName", stackName)
|
||||
.when().post("/").then().statusCode(200).extract().asString();
|
||||
}
|
||||
|
||||
private static String describeEvents(String stackName) {
|
||||
return given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStackEvents").formParam("Version", "2010-05-15")
|
||||
.formParam("StackName", stackName)
|
||||
.when().post("/").then().statusCode(200).extract().asString();
|
||||
}
|
||||
|
||||
private static void assertVersioning(String bucket, String status) {
|
||||
given()
|
||||
.when()
|
||||
.get("/" + bucket + "?versioning")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Status>" + status + "</Status>"));
|
||||
}
|
||||
|
||||
private static void await(String stackName, String status) {
|
||||
String xml = "";
|
||||
long deadline = System.currentTimeMillis() + 10_000;
|
||||
while (System.currentTimeMillis() < deadline) {
|
||||
xml = describeStack(stackName);
|
||||
if (xml.contains("<StackStatus>" + status + "</StackStatus>")) {
|
||||
return;
|
||||
}
|
||||
if (xml.contains("_FAILED</StackStatus>")) {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
fail("stack " + stackName + " never reached " + status + ": " + xml);
|
||||
}
|
||||
|
||||
private static void createBucket(String bucket) {
|
||||
given().when().put("/" + bucket).then().statusCode(200);
|
||||
}
|
||||
|
||||
private static void assertBucketPresent(String bucket) {
|
||||
given().when().head("/" + bucket).then().statusCode(200);
|
||||
}
|
||||
|
||||
private static void assertBucketMissing(String bucket) {
|
||||
given().when().head("/" + bucket).then().statusCode(404);
|
||||
}
|
||||
|
||||
private static void assertEvent(String eventsXml, String status, String physicalId) {
|
||||
Pattern p = Pattern.compile("<member>(.*?)</member>", Pattern.DOTALL);
|
||||
Matcher m = p.matcher(eventsXml);
|
||||
while (m.find()) {
|
||||
String member = m.group(1);
|
||||
if (member.contains("<ResourceStatus>" + status + "</ResourceStatus>")
|
||||
&& member.contains("<PhysicalResourceId>" + physicalId + "</PhysicalResourceId>")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("no " + status + " event for " + physicalId + " in " + eventsXml);
|
||||
}
|
||||
|
||||
private static String output(String describeXml, String key) {
|
||||
Matcher m = Pattern.compile("<OutputKey>" + key + "</OutputKey>\\s*<OutputValue>(.*?)</OutputValue>", Pattern.DOTALL)
|
||||
.matcher(describeXml);
|
||||
if (!m.find()) {
|
||||
m = Pattern.compile("<OutputValue>(.*?)</OutputValue>\\s*<OutputKey>" + key + "</OutputKey>", Pattern.DOTALL)
|
||||
.matcher(describeXml);
|
||||
assertTrue(m.find(), "output " + key + " missing in " + describeXml);
|
||||
}
|
||||
return m.group(1);
|
||||
}
|
||||
}
|
||||
+169
@@ -20,8 +20,10 @@ import org.mockito.ArgumentCaptor;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
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;
|
||||
@@ -169,6 +171,115 @@ class S3CfnProvisionerTest {
|
||||
verify(s3).createBucket("renamed", REGION);
|
||||
}
|
||||
|
||||
/**
|
||||
* A rename is a replacing update: the prior bucket is reported for the post-commit cleanup and
|
||||
* deleted once the update commits, exactly as AWS replaces a bucket whose BucketName changed.
|
||||
*/
|
||||
@Test
|
||||
void renamingTheBucketReplacesItAndReportsTheOldNameForCleanup() {
|
||||
StackResource r = resource("Bucket", "AWS::S3::Bucket");
|
||||
r.setPhysicalId("old-bucket");
|
||||
provisioner.provision(r, props("{\"BucketName\": \"new-bucket\"}"), replacingContext("old-bucket"));
|
||||
|
||||
assertEquals("new-bucket", r.getPhysicalId());
|
||||
verify(s3).createBucket("new-bucket", REGION);
|
||||
assertTrue(provisioner.hasReplacementUpdate(r));
|
||||
assertEquals("old-bucket", provisioner.updateCleanupPhysicalId(r));
|
||||
|
||||
UpdateCleanupResult result = provisioner.completeUpdate(r);
|
||||
verify(s3).deleteBucket("old-bucket");
|
||||
assertEquals(new UpdateCleanupResult(true, true, "old-bucket", 0, null), result);
|
||||
|
||||
provisioner.clearUpdate(r);
|
||||
assertFalse(provisioner.hasReplacementUpdate(r));
|
||||
assertNull(provisioner.updateCleanupPhysicalId(r));
|
||||
}
|
||||
|
||||
/** A rename whose delete is finally done leaves nothing owed. */
|
||||
@Test
|
||||
void aCommittedReplacementWhoseOldBucketIsAlreadyGoneCompletesCleanup() {
|
||||
doThrow(new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404))
|
||||
.when(s3).deleteBucket("old-bucket");
|
||||
StackResource r = resource("Bucket", "AWS::S3::Bucket");
|
||||
r.setPhysicalId("old-bucket");
|
||||
provisioner.provision(r, props("{\"BucketName\": \"new-bucket\"}"), replacingContext("old-bucket"));
|
||||
|
||||
assertDoesNotThrow(() -> provisioner.completeUpdate(r));
|
||||
assertFalse(provisioner.hasReplacementUpdate(r));
|
||||
}
|
||||
|
||||
/**
|
||||
* A later resource failing the update rolls the rename back: the resource names the old bucket
|
||||
* again, with the attributes it had, and the replacement the attempt created is deleted.
|
||||
*/
|
||||
@Test
|
||||
void rollingBackAReplacingUpdateRestoresTheOldBucketAndDeletesTheReplacement() {
|
||||
StackResource r = resource("Bucket", "AWS::S3::Bucket");
|
||||
r.setPhysicalId("old-bucket");
|
||||
r.getAttributes().put("BucketName", "old-bucket");
|
||||
r.getAttributes().put("Arn", "arn:aws:s3:::old-bucket");
|
||||
provisioner.provision(r, props("{\"BucketName\": \"new-bucket\"}"), replacingContext("old-bucket"));
|
||||
|
||||
assertEquals("new-bucket", r.getPhysicalId());
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
|
||||
assertEquals("old-bucket", r.getPhysicalId());
|
||||
assertEquals("arn:aws:s3:::old-bucket", r.getAttributes().get("Arn"));
|
||||
verify(s3).deleteBucket("new-bucket");
|
||||
}
|
||||
|
||||
/** A bucket already gone when its replacement is undone is not a rollback failure. */
|
||||
@Test
|
||||
void aReplacementAlreadyGoneWhenRolledBackDoesNotFailTheRollback() {
|
||||
doThrow(new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404))
|
||||
.when(s3).deleteBucket("new-bucket");
|
||||
StackResource r = resource("Bucket", "AWS::S3::Bucket");
|
||||
r.setPhysicalId("old-bucket");
|
||||
provisioner.provision(r, props("{\"BucketName\": \"new-bucket\"}"), replacingContext("old-bucket"));
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
assertEquals("old-bucket", r.getPhysicalId());
|
||||
}
|
||||
|
||||
/**
|
||||
* A rename onto a name the account already owns does not create a bucket, so a rollback points
|
||||
* the resource back without deleting a bucket this update never created. The prior bucket stays
|
||||
* displaced and is still the one a committed cleanup deletes.
|
||||
*/
|
||||
@Test
|
||||
void rollingBackARenameOntoAnOwnedBucketLeavesThatBucketStanding() {
|
||||
when(s3.ownsBucket("new-bucket")).thenReturn(true);
|
||||
StackResource r = resource("Bucket", "AWS::S3::Bucket");
|
||||
r.setPhysicalId("old-bucket");
|
||||
r.getAttributes().put("BucketName", "old-bucket");
|
||||
r.getAttributes().put("Arn", "arn:aws:s3:::old-bucket");
|
||||
provisioner.provision(r, props("{\"BucketName\": \"new-bucket\"}"), replacingContext("old-bucket"));
|
||||
|
||||
assertEquals("new-bucket", r.getPhysicalId());
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
|
||||
assertEquals("old-bucket", r.getPhysicalId());
|
||||
assertEquals("arn:aws:s3:::old-bucket", r.getAttributes().get("Arn"));
|
||||
verify(s3, never()).deleteBucket(anyString());
|
||||
}
|
||||
|
||||
/** A committed rename onto an owned bucket deletes only the bucket the stack owned. */
|
||||
@Test
|
||||
void committingARenameOntoAnOwnedBucketDeletesOnlyThePriorBucket() {
|
||||
when(s3.ownsBucket("new-bucket")).thenReturn(true);
|
||||
StackResource r = resource("Bucket", "AWS::S3::Bucket");
|
||||
r.setPhysicalId("old-bucket");
|
||||
provisioner.provision(r, props("{\"BucketName\": \"new-bucket\"}"), replacingContext("old-bucket"));
|
||||
|
||||
assertEquals(new UpdateCleanupResult(true, true, "old-bucket", 0, null), provisioner.completeUpdate(r));
|
||||
verify(s3).deleteBucket("old-bucket");
|
||||
verify(s3, never()).deleteBucket("new-bucket");
|
||||
}
|
||||
|
||||
private ProvisionContext replacingContext(String priorPhysicalId) {
|
||||
return new ProvisionContext(ctx.engine(), REGION, "000000000000", "my-stack", priorPhysicalId);
|
||||
}
|
||||
|
||||
/** ISO-E publishes no S3 dual-stack endpoint, so the attribute is absent rather than invented. */
|
||||
@Test
|
||||
void aBucketInARegionWithoutS3DualStackHasNoDualStackDomainName() {
|
||||
@@ -582,6 +693,38 @@ class S3CfnProvisionerTest {
|
||||
assertFalse(r.getAttributes().containsKey(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR));
|
||||
}
|
||||
|
||||
/** A committed in-place update reports the snapshot cleanup done, so the engine drops the snapshot. */
|
||||
@Test
|
||||
void completingAnInPlaceUpdateClearsTheSnapshot() {
|
||||
StackResource r = resource("Bucket", "AWS::S3::Bucket");
|
||||
r.setPhysicalId("b");
|
||||
provisioner.provision(r, props("{\"BucketName\": \"b\", \"VersioningConfiguration\": {\"Status\": \"Enabled\"}}"),
|
||||
new ProvisionContext(ctx.engine(), REGION, "000000000000", "my-stack", "b", event -> { },
|
||||
props("{\"BucketName\": \"b\"}")));
|
||||
assertTrue(r.getAttributes().containsKey(CfnRollback.S3_BUCKET_UPDATE_SNAPSHOT_ATTR));
|
||||
|
||||
assertEquals(new UpdateCleanupResult(true, true, null, 0, null), provisioner.completeUpdate(r));
|
||||
provisioner.clearUpdate(r);
|
||||
assertFalse(r.getAttributes().containsKey(CfnRollback.S3_BUCKET_UPDATE_SNAPSHOT_ATTR));
|
||||
}
|
||||
|
||||
/**
|
||||
* A later resource failing an update that changed the bucket in place restores the settings from
|
||||
* the snapshot, the engine calling the same hook a replacement rollback uses.
|
||||
*/
|
||||
@Test
|
||||
void rollingBackAnInPlaceUpdateRestoresTheBucketSnapshot() {
|
||||
StackResource r = resource("Bucket", "AWS::S3::Bucket");
|
||||
r.setPhysicalId("b");
|
||||
provisioner.provision(r, props("{\"BucketName\": \"b\", \"VersioningConfiguration\": {\"Status\": \"Enabled\"}}"),
|
||||
new ProvisionContext(ctx.engine(), REGION, "000000000000", "my-stack", "b", event -> { },
|
||||
props("{\"BucketName\": \"b\"}")));
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
verify(s3).restoreBucketConfiguration("b", "snapshot");
|
||||
assertFalse(r.getAttributes().containsKey(CfnRollback.S3_BUCKET_UPDATE_SNAPSHOT_ATTR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLaterFailureOnCreateDeletesTheBucketItCreated() {
|
||||
doThrow(new AwsException("MalformedXML", "bad", 400)).when(s3).putBucketVersioning("b", "Bogus");
|
||||
@@ -692,6 +835,32 @@ class S3CfnProvisionerTest {
|
||||
verify(s3, never()).deleteBucketPolicy(anyString());
|
||||
}
|
||||
|
||||
/** A bucket already gone is treated as deleted, not as a failure. */
|
||||
@Test
|
||||
void deletingAnAlreadyGoneBucketIsTolerated() {
|
||||
doThrow(new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404))
|
||||
.when(s3).deleteBucket("gone");
|
||||
|
||||
assertDoesNotThrow(() -> provisioner.delete("AWS::S3::Bucket", "gone", REGION));
|
||||
|
||||
verify(s3).deleteBucket("gone");
|
||||
}
|
||||
|
||||
/**
|
||||
* A non-empty bucket cannot be deleted, and that failure has to reach the stack so it reports
|
||||
* DELETE_FAILED rather than a clean deletion over a bucket that is still there.
|
||||
*/
|
||||
@Test
|
||||
void deletingANonEmptyBucketPropagatesBucketNotEmpty() {
|
||||
doThrow(new AwsException("BucketNotEmpty", "The bucket you tried to delete is not empty.", 409))
|
||||
.when(s3).deleteBucket("b");
|
||||
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> provisioner.delete("AWS::S3::Bucket", "b", REGION));
|
||||
|
||||
assertEquals("BucketNotEmpty", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingABucketPolicyClearsItFromTheBucketAndLeavesTheBucket() {
|
||||
provisioner.delete("AWS::S3::BucketPolicy", "b", REGION);
|
||||
|
||||
Reference in new issue
Block a user