From fcd662fb623531a6e98b15f5aa44b7eb0768cf05 Mon Sep 17 00:00:00 2001 From: Allen Sanborn Date: Mon, 24 Aug 2026 14:59:44 -0500 Subject: [PATCH] fix(msk): accept an empty serverProperties on Create/UpdateConfiguration (#2491) * fix(msk): accept an empty serverProperties on Create/UpdateConfiguration CreateConfiguration and UpdateConfiguration both validated serverProperties with `== null || isBlank()`, which conflates "member absent" with "member present but empty". A zero-length blob is a legitimate value in MSK: it means "no property overrides". Terraform modules hit this routinely. Gruntwork's msk module builds serverProperties by joining a map that defaults to {} and creates aws_msk_configuration unconditionally, so an unconfigured module sends an empty blob and the emulator answered BadRequestException "serverProperties is required." Three terraform-aws-messaging roots failed on it. Both call sites now reject only null. Absent and empty stay distinguishable at the REST layer: MskController.asString returns null for a missing member and decodeServerProperties turns the empty base64 string into "". * test(msk): read back both revisions, and match the class's naming The round-trip test read back only revision 1, so an update that stored "" and one that silently carried the previous revision's properties forward would both have passed. It now checks both revisions. Renames createConfigurationRejectsAbsentServerProperties to ...RejectsMissingServerProperties, which is what every neighbouring missing-member test in these two classes is already called. --- .../floci/services/msk/MskService.java | 9 +++- .../msk/MskControllerIntegrationTest.java | 54 +++++++++++++++++++ .../floci/services/msk/MskServiceTest.java | 41 ++++++++++++++ 3 files changed, 102 insertions(+), 2 deletions(-) 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, () ->