Light, fluffy, and always free - The AWS Local Emulator alternative
feat(s3): apply VersioningConfiguration in CloudFormation S3 bucket provisioning (#2626)
takahiro64c38c77b9ee
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.javaindex 31d96e435c..9228593017 100644--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java@@ -677,6 +677,7 @@ public class CloudFormationResourceProvisioner {}s3Service.createBucket(bucketName, region);applyBucketCorsConfiguration(bucketName, props, engine);+ applyBucketVersioningConfiguration(bucketName, props, engine);r.setPhysicalId(bucketName);r.getAttributes().put("Arn", AwsArnUtils.Arn.of("s3", "", "", bucketName).toString());r.getAttributes().put("DomainName", bucketName + ".s3.amazonaws.com");@@ -722,6 +723,18 @@ public class CloudFormationResourceProvisioner {s3Service.putBucketCors(bucketName, xml.build());}+ private void applyBucketVersioningConfiguration(String bucketName, JsonNode props,+ CloudFormationTemplateEngine engine) {+ if (props == null || !props.has("VersioningConfiguration")+ || props.get("VersioningConfiguration").isNull()) {+ return;+ }+ String status = resolveOptional(props.get("VersioningConfiguration"), "Status", engine);+ if (status != null && !status.isBlank()) {+ s3Service.putBucketVersioning(bucketName, status);+ }+ }+private void appendCorsRuleElements(XmlBuilder xml, JsonNode values, String elementName,CloudFormationTemplateEngine engine) {if (values == null || !values.isArray()) {diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.javaindex 314f5b9dc6..74511cc1cd 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java@@ -513,6 +513,150 @@ class CloudFormationIntegrationTest {.body(containsString("NoSuchCORSConfiguration"));}+ @Test+ void createStack_s3BucketWithVersioningConfiguration() {+ String template = """+ {+ "Resources": {+ "MyBucket": {+ "Type": "AWS::S3::Bucket",+ "Properties": {+ "BucketName": "cfn-versioning-test-bucket",+ "VersioningConfiguration": {+ "Status": "Enabled"+ }+ }+ }+ }+ }+ """;++ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "CreateStack")+ .formParam("StackName", "cfn-versioning-stack")+ .formParam("TemplateBody", template)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("<StackId>"));++ // The bucket's ?versioning subresource should reflect the CloudFormation VersioningConfiguration.+ given()+ .when()+ .get("/cfn-versioning-test-bucket?versioning")+ .then()+ .statusCode(200)+ .body(containsString("<Status>Enabled</Status>"));+ }++ @Test+ void createStack_s3BucketWithoutVersioningConfigurationLeavesVersioningUnset() {+ String template = """+ {+ "Resources": {+ "MyBucket": {+ "Type": "AWS::S3::Bucket",+ "Properties": {+ "BucketName": "cfn-versioning-unset-bucket"+ }+ }+ }+ }+ """;++ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "CreateStack")+ .formParam("StackName", "cfn-versioning-unset-stack")+ .formParam("TemplateBody", template)+ .when()+ .post("/")+ .then()+ .statusCode(200);++ // No VersioningConfiguration in the template → versioning must stay unset (no <Status> element),+ // matching real AWS behavior for a bucket that was never versioned.+ given()+ .when()+ .get("/cfn-versioning-unset-bucket?versioning")+ .then()+ .statusCode(200)+ .body(not(containsString("<Status>")));+ }++ @Test+ void updateStack_s3BucketVersioningConfigurationIsReconciled() {+ String stackName = "cfn-versioning-update-stack";+ String bucketName = "cfn-versioning-update-bucket";+ String enabled = """+ {+ "Resources": {+ "MyBucket": {+ "Type": "AWS::S3::Bucket",+ "Properties": {+ "BucketName": "%s",+ "VersioningConfiguration": {+ "Status": "Enabled"+ }+ }+ }+ }+ }+ """.formatted(bucketName);+ String suspended = """+ {+ "Resources": {+ "MyBucket": {+ "Type": "AWS::S3::Bucket",+ "Properties": {+ "BucketName": "%s",+ "VersioningConfiguration": {+ "Status": "Suspended"+ }+ }+ }+ }+ }+ """.formatted(bucketName);++ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "CreateStack")+ .formParam("StackName", stackName)+ .formParam("TemplateBody", enabled)+ .when()+ .post("/")+ .then()+ .statusCode(200);++ given()+ .when()+ .get("/" + bucketName + "?versioning")+ .then()+ .statusCode(200)+ .body(containsString("<Status>Enabled</Status>"));++ // Update: Status changes to Suspended → versioning is reconciled to match the template.+ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "UpdateStack")+ .formParam("StackName", stackName)+ .formParam("TemplateBody", suspended)+ .when()+ .post("/")+ .then()+ .statusCode(200);++ given()+ .when()+ .get("/" + bucketName + "?versioning")+ .then()+ .statusCode(200)+ .body(containsString("<Status>Suspended</Status>"));+ }+@Testvoid createStack_lambdaWithS3Code() {byte[] zipBytes = buildHandlerZip();