mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(kms): return an empty Description when CreateKey omits one (#4349)
* fix(kms): return an empty Description when CreateKey omits one * fix(kms): return an empty Description for stored keys without one
This commit is contained in:
1 parent
0d813adf95
commit
f29c2b1c95
3 files changed
+62
-2
No files matched your search
@@ -761,7 +761,7 @@ public class KmsJsonHandler {
|
||||
keyMetadata.put("Arn", k.getArn());
|
||||
keyMetadata.put("CreationDate", k.getCreationDate());
|
||||
keyMetadata.put("Enabled", k.isEnabled());
|
||||
keyMetadata.put("Description", k.getDescription());
|
||||
keyMetadata.put("Description", k.getDescription() == null ? "" : k.getDescription());
|
||||
keyMetadata.put("KeyUsage", k.getKeyUsage().name());
|
||||
keyMetadata.put("KeyState", k.getKeyState());
|
||||
keyMetadata.put("Origin", k.getOrigin());
|
||||
|
||||
@@ -152,7 +152,7 @@ public class KmsService implements ResourceProvider {
|
||||
KmsKey key = new KmsKey();
|
||||
key.setKeyId(keyId);
|
||||
key.setArn(arn);
|
||||
key.setDescription(description);
|
||||
key.setDescription(description == null ? "" : description);
|
||||
key.setKeyUsage(effectiveUsage);
|
||||
key.setKeySpec(effectiveSpec);
|
||||
key.setPolicy(policy != null ? policy : buildDefaultKeyPolicy());
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.kms;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -39,6 +40,9 @@ class KmsIntegrationTest {
|
||||
|
||||
private static final String KMS_CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
|
||||
@Inject
|
||||
KmsService kmsService;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
@@ -125,6 +129,62 @@ class KmsIntegrationTest {
|
||||
.body("KeyId", equalTo(replicaKeyArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createKeyWithoutDescriptionReturnsEmptyDescription() {
|
||||
String keyId = given()
|
||||
.header("X-Amz-Target", "TrentService.CreateKey")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("KeyMetadata.Description", equalTo(""))
|
||||
.extract().path("KeyMetadata.KeyId");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "TrentService.DescribeKey")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"KeyId": "%s"
|
||||
}
|
||||
""".formatted(keyId))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("KeyMetadata.Description", equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeKeyReturnsEmptyDescriptionForStoredKeyWithoutOne() {
|
||||
String keyId = given()
|
||||
.header("X-Amz-Target", "TrentService.CreateKey")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("KeyMetadata.KeyId");
|
||||
kmsService.describeKey(keyId, "us-east-1").setDescription(null);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "TrentService.DescribeKey")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"KeyId": "%s"
|
||||
}
|
||||
""".formatted(keyId))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("KeyMetadata.Description", equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateKeyDescriptionRoundTripThroughJsonHandler() {
|
||||
var key = given()
|
||||
|
||||
Reference in new issue
Block a user