diff --git a/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java b/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java index f1748cc36a..e26e41bbbf 100644 --- a/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java +++ b/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java @@ -134,7 +134,10 @@ public class MskService { throw new AwsException("BadRequestException", "Configuration name must match the pattern \"^[0-9A-Za-z][0-9A-Za-z-]{0,}$\".", 400); } - if (serverProperties == null || serverProperties.isBlank()) { + // Only an absent member (null) is rejected. A zero-length blob is a legitimate value + // meaning "no property overrides": Terraform modules that build serverProperties by + // joining a map defaulting to {} send exactly that, and real MSK accepts it. + if (serverProperties == null) { throw new AwsException("BadRequestException", "serverProperties is required.", 400); } if (configurationStorage.scan(k -> true).stream().anyMatch(c -> c.getName().equals(name))) { @@ -178,7 +181,9 @@ public class MskService { } public MskConfiguration updateConfiguration(String arn, String description, String serverProperties) { - if (serverProperties == null || serverProperties.isBlank()) { + // Same absent-vs-empty distinction as createConfiguration: "" is a valid revision + // body that clears every override, only a missing member is an error. + if (serverProperties == null) { throw new AwsException("BadRequestException", "serverProperties is required.", 400); } diff --git a/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java index 24758a51f6..a713c00b68 100644 --- a/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java @@ -133,6 +133,60 @@ class MskControllerIntegrationTest { .statusCode(404); } + // An empty base64 blob decodes to "" and means "no property overrides". Absent and + // present-but-empty stay distinguishable at the REST layer: a missing member arrives as + // null, an empty one as a zero-length String, so only the former is rejected. + @Test + void createAndUpdateConfigurationAcceptEmptyServerProperties() { + String arn = given() + .contentType("application/json") + .body(""" + {"name": "empty-props-%s", "kafkaVersions": ["3.6.0"], "serverProperties": ""} + """.formatted(UUID.randomUUID().toString().substring(0, 8))) + .when() + .post("/v1/configurations") + .then() + .statusCode(200) + .body("state", equalTo("ACTIVE")) + .body("latestRevision.revision", equalTo(1)) + .extract().path("arn"); + + given() + .contentType("application/json") + .body(""" + {"description": "still empty", "serverProperties": ""} + """) + .when() + .put("/v1/configurations/{arn}", arn) + .then() + .statusCode(200) + .body("latestRevision.revision", equalTo(2)); + + // Both revisions, not just the one create wrote: an empty update has to store "" + // rather than silently carry the previous revision's properties forward. + for (int revision : new int[] { 1, 2 }) { + given() + .when() + .get("/v1/configurations/{arn}/revisions/{revision}", arn, revision) + .then() + .statusCode(200) + .body("serverProperties", equalTo("")); + } + } + + @Test + void createConfigurationRejectsMissingServerProperties() { + given() + .contentType("application/json") + .body(""" + {"name": "no-props-config", "kafkaVersions": ["3.6.0"]} + """) + .when() + .post("/v1/configurations") + .then() + .statusCode(400); + } + @Test void createConfigurationRejectsNonBase64ServerProperties() { given() diff --git a/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java index ab43ebd189..4c0568ef2a 100644 --- a/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java @@ -148,6 +148,25 @@ class MskServiceTest { mskService.createConfiguration("test-config", "desc", List.of("3.6.0"), null)); } + @Test + void createConfigurationAcceptsEmptyServerProperties() { + // A zero-length blob means "no property overrides" - Gruntwork's msk module joins a + // map that defaults to {} and creates aws_msk_configuration unconditionally. + MskConfiguration configuration = mskService.createConfiguration( + "empty-props-config", "desc", List.of("3.6.0"), ""); + + assertEquals("", configuration.getServerPropertiesByRevision().get(1L)); + assertEquals(ConfigurationState.ACTIVE, configuration.getState()); + } + + @Test + void createConfigurationAcceptsNonEmptyServerProperties() { + MskConfiguration configuration = mskService.createConfiguration( + "props-config", "desc", List.of("3.6.0"), "num.partitions=3"); + + assertEquals("num.partitions=3", configuration.getServerPropertiesByRevision().get(1L)); + } + @Test void createConfigurationRejectsDuplicateName() { mskService.createConfiguration("test-config", "desc", List.of("3.6.0"), "props"); @@ -242,6 +261,28 @@ class MskServiceTest { mskService.updateConfiguration(created.getArn(), "desc", null)); } + @Test + void updateConfigurationAcceptsEmptyServerProperties() { + MskConfiguration created = mskService.createConfiguration( + "test-config", "desc", List.of("3.6.0"), "num.partitions=3"); + + MskConfiguration updated = mskService.updateConfiguration(created.getArn(), "cleared", ""); + + assertEquals(2L, updated.getLatestRevision().getRevision()); + assertEquals("", updated.getServerPropertiesByRevision().get(2L)); + } + + @Test + void updateConfigurationAcceptsNonEmptyServerProperties() { + MskConfiguration created = mskService.createConfiguration( + "test-config", "desc", List.of("3.6.0"), ""); + + MskConfiguration updated = mskService.updateConfiguration( + created.getArn(), "desc", "num.partitions=3"); + + assertEquals("num.partitions=3", updated.getServerPropertiesByRevision().get(2L)); + } + @Test void updateConfigurationNotFoundThrows() { assertThrows(AwsException.class, () ->