Light, fluffy, and always free - The AWS Local Emulator alternative
fix(kms): return an empty body for operations without output (#5318)
MIdhun63ef2d3a2d63
diff --git a/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.javaindex 1b5263962f..a22e82d8e4 100644--- a/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.java@@ -269,7 +269,7 @@ public class KmsJsonHandler {String grantId = request.path("GrantId").asText(null);service.revokeGrant(keyId, grantId, region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private Response handleRetireGrant(JsonNode request, String region) {@@ -281,7 +281,7 @@ public class KmsJsonHandler {? null : request.path("GrantId").asText(null);service.retireGrant(grantToken, keyId, grantId, region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}// Blob fields arrive base64-encoded on the wire. A value that is not valid base64 is a@@ -450,17 +450,17 @@ public class KmsJsonHandler {private Response handleCreateAlias(JsonNode request, String region) {service.createAlias(request.path("AliasName").asText(), request.path("TargetKeyId").asText(), region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private Response handleUpdateAlias(JsonNode request, String region) {service.updateAlias(request.path("AliasName").asText(), request.path("TargetKeyId").asText(), region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private Response handleDeleteAlias(JsonNode request, String region) {service.deleteAlias(request.path("AliasName").asText(), region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private Response handleListAliases(JsonNode request, String region) {@@ -505,7 +505,7 @@ public class KmsJsonHandler {request.path("Tags").forEach(t -> tags.put(t.path("TagKey").asText(), t.path("TagValue").asText()));ReservedTags.rejectReservedTagsOnUpdate(tags);service.tagResource(keyId, tags, region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private Response handleUntagResource(JsonNode request, String region) {@@ -513,7 +513,7 @@ public class KmsJsonHandler {java.util.List<String> keys = new java.util.ArrayList<>();request.path("TagKeys").forEach(k -> keys.add(k.asText()));service.untagResource(keyId, keys, region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private Response handleListResourceTags(JsonNode request, String region) {@@ -540,7 +540,7 @@ public class KmsJsonHandler {request.path("KeyId").asText(),request.path("Policy").asText(),region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private Response handleListKeyPolicies(JsonNode request, String region) {@@ -556,7 +556,7 @@ public class KmsJsonHandler {request.path("KeyId").asText(),requiredText(request, "Description"),region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private String requiredText(JsonNode request, String field) {@@ -581,22 +581,22 @@ public class KmsJsonHandler {validateRange("rotationPeriodInDays", rotationPeriod.asInt(), 90, 2560);}service.enableKeyRotation(request.path("KeyId").asText(), region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private Response handleDisableKeyRotation(JsonNode request, String region) {service.disableKeyRotation(request.path("KeyId").asText(), region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private Response handleEnableKey(JsonNode request, String region) {service.enableKey(request.path("KeyId").asText(), region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private Response handleDisableKey(JsonNode request, String region) {service.disableKey(request.path("KeyId").asText(), region);- return Response.ok(objectMapper.createObjectNode()).build();+ return Response.ok().build();}private Response handleRotateKeyOnDemand(JsonNode request, String region) {diff --git a/src/test/java/io/github/hectorvent/floci/services/kms/KmsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/kms/KmsIntegrationTest.javaindex cb3bed93d2..346cfd987e 100644--- a/src/test/java/io/github/hectorvent/floci/services/kms/KmsIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/kms/KmsIntegrationTest.java@@ -27,6 +27,7 @@ import java.util.Base64;import java.util.List;import static io.restassured.RestAssured.given;+import static org.hamcrest.Matchers.emptyString;import static org.hamcrest.Matchers.equalTo;import static org.hamcrest.Matchers.hasKey;import static org.hamcrest.Matchers.hasItem;@@ -3383,6 +3384,45 @@ class KmsIntegrationTest {.body("KeyMetadata.KeyState", equalTo("Enabled"));}+ @Test+ void operationsWithoutOutputReturnEmptyBody() {+ String keyArn = createKeyArn("SYMMETRIC_DEFAULT", "ENCRYPT_DECRYPT");+ String otherKeyArn = createKeyArn("SYMMETRIC_DEFAULT", "ENCRYPT_DECRYPT");+ String keyBody = "{\"KeyId\":\"%s\"}".formatted(keyArn);+ String grantBody = """+ {"KeyId":"%s","GranteePrincipal":"arn:aws:iam::000000000000:user/grantee","Operations":["Encrypt"]}+ """.formatted(keyArn);+ String revokableGrantId = callKms("CreateGrant", grantBody).then().statusCode(200).extract().path("GrantId");+ String retirableGrantToken = callKms("CreateGrant", grantBody).then().statusCode(200).extract().path("GrantToken");++ assertEmptyBody("DisableKey", keyBody);+ assertEmptyBody("EnableKey", keyBody);+ assertEmptyBody("EnableKeyRotation", keyBody);+ assertEmptyBody("DisableKeyRotation", keyBody);+ assertEmptyBody("UpdateKeyDescription",+ "{\"KeyId\":\"%s\",\"Description\":\"updated\"}".formatted(keyArn));+ assertEmptyBody("PutKeyPolicy", """+ {"KeyId":"%s","PolicyName":"default","Policy":"{\\"Version\\":\\"2012-10-17\\",\\"Statement\\":[]}"}+ """.formatted(keyArn));+ assertEmptyBody("TagResource",+ "{\"KeyId\":\"%s\",\"Tags\":[{\"TagKey\":\"env\",\"TagValue\":\"test\"}]}".formatted(keyArn));+ assertEmptyBody("UntagResource", "{\"KeyId\":\"%s\",\"TagKeys\":[\"env\"]}".formatted(keyArn));+ assertEmptyBody("CreateAlias",+ "{\"AliasName\":\"alias/empty-body\",\"TargetKeyId\":\"%s\"}".formatted(keyArn));+ assertEmptyBody("UpdateAlias",+ "{\"AliasName\":\"alias/empty-body\",\"TargetKeyId\":\"%s\"}".formatted(otherKeyArn));+ assertEmptyBody("DeleteAlias", "{\"AliasName\":\"alias/empty-body\"}");+ assertEmptyBody("RevokeGrant",+ "{\"KeyId\":\"%s\",\"GrantId\":\"%s\"}".formatted(keyArn, revokableGrantId));+ assertEmptyBody("RetireGrant", "{\"GrantToken\":\"%s\"}".formatted(retirableGrantToken));+ }++ private static void assertEmptyBody(String operation, String body) {+ callKms(operation, body).then()+ .statusCode(200)+ .body(emptyString());+ }+/*** Wraps key material exactly as a caller would: the point of the round trip is that the* emulator unwraps what a standard RSAES-OAEP-SHA-256 client produces, not a shape of its own.