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.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-08-24 15:59:44 -04:00
1 parent 1ca19c722a
commit fcd662fb62
3 files changed
+102 -2

No files matched your search

@@ -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);
}
@@ -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()
@@ -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, () ->