mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(kms): GetKeyRotationStatus returns false for asymmetric and HMAC keys (#618)
* fix(kms): return false for GetKeyRotationStatus on asymmetric/HMAC keys
AWS updated GetKeyRotationStatus behavior so asymmetric and HMAC keys
return { KeyRotationEnabled: false } instead of UnsupportedOperationException.
EnableKeyRotation and DisableKeyRotation still reject these key types.
* fix(kms): return false for GetKeyRotationStatus on asymmetric/HMAC keys
AWS updated GetKeyRotationStatus behavior so asymmetric and HMAC keys
return { KeyRotationEnabled: false } instead of UnsupportedOperationException.
EnableKeyRotation and DisableKeyRotation still reject these key types.
This commit is contained in:
1 parent
15f51ea7c3
commit
c7152cef8a
11 files changed
+525
-60
No files matched your search
+136
@@ -1,5 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.kinesis;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
@@ -8,8 +10,11 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@@ -909,4 +914,135 @@ class KinesisIntegrationTest {
|
||||
.then().statusCode(200)
|
||||
.body("Records.size()", equalTo(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(60)
|
||||
void subscribeToShard_returnsRecords() throws Exception {
|
||||
given()
|
||||
.header("X-Amz-Target", "Kinesis_20131202.CreateStream")
|
||||
.contentType(KINESIS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"StreamName": "efo-test-stream", "ShardCount": 1}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
String streamArn = given()
|
||||
.header("X-Amz-Target", "Kinesis_20131202.DescribeStreamSummary")
|
||||
.contentType(KINESIS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"StreamName": "efo-test-stream"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.extract().jsonPath().getString("StreamDescriptionSummary.StreamARN");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "Kinesis_20131202.PutRecord")
|
||||
.contentType(KINESIS_CONTENT_TYPE)
|
||||
.body("{\"StreamName\": \"efo-test-stream\", \"Data\": \"aGVsbG8=\", \"PartitionKey\": \"pk1\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
String consumerArn = given()
|
||||
.header("X-Amz-Target", "Kinesis_20131202.RegisterStreamConsumer")
|
||||
.contentType(KINESIS_CONTENT_TYPE)
|
||||
.body("{\"StreamARN\": \"" + streamArn + "\", \"ConsumerName\": \"efo-consumer\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.extract().jsonPath().getString("Consumer.ConsumerARN");
|
||||
|
||||
byte[] body = given()
|
||||
.header("X-Amz-Target", "Kinesis_20131202.SubscribeToShard")
|
||||
.contentType(KINESIS_CONTENT_TYPE)
|
||||
.body("{\"ConsumerARN\": \"" + consumerArn + "\", \"ShardId\": \"shardId-000000000000\","
|
||||
+ "\"StartingPosition\": {\"Type\": \"TRIM_HORIZON\"}}")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Type", containsString("application/vnd.amazon.eventstream"))
|
||||
.extract().asByteArray();
|
||||
|
||||
JsonNode event = decodeFirstEventStreamMessage(body);
|
||||
assertNotNull(event);
|
||||
assertEquals(1, event.path("Records").size());
|
||||
assertEquals("pk1", event.path("Records").get(0).path("PartitionKey").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(61)
|
||||
void subscribeToShard_trimHorizonEmptyShard() throws Exception {
|
||||
given()
|
||||
.header("X-Amz-Target", "Kinesis_20131202.CreateStream")
|
||||
.contentType(KINESIS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"StreamName": "efo-empty-stream", "ShardCount": 1}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
String streamArn = given()
|
||||
.header("X-Amz-Target", "Kinesis_20131202.DescribeStreamSummary")
|
||||
.contentType(KINESIS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"StreamName": "efo-empty-stream"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.extract().jsonPath().getString("StreamDescriptionSummary.StreamARN");
|
||||
|
||||
String consumerArn = given()
|
||||
.header("X-Amz-Target", "Kinesis_20131202.RegisterStreamConsumer")
|
||||
.contentType(KINESIS_CONTENT_TYPE)
|
||||
.body("{\"StreamARN\": \"" + streamArn + "\", \"ConsumerName\": \"efo-empty-consumer\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.extract().jsonPath().getString("Consumer.ConsumerARN");
|
||||
|
||||
byte[] body = given()
|
||||
.header("X-Amz-Target", "Kinesis_20131202.SubscribeToShard")
|
||||
.contentType(KINESIS_CONTENT_TYPE)
|
||||
.body("{\"ConsumerARN\": \"" + consumerArn + "\", \"ShardId\": \"shardId-000000000000\","
|
||||
+ "\"StartingPosition\": {\"Type\": \"TRIM_HORIZON\"}}")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Type", containsString("application/vnd.amazon.eventstream"))
|
||||
.extract().asByteArray();
|
||||
|
||||
JsonNode event = decodeFirstEventStreamMessage(body);
|
||||
assertNotNull(event);
|
||||
assertEquals(0, event.path("Records").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(62)
|
||||
void subscribeToShard_invalidConsumerArn() {
|
||||
given()
|
||||
.header("X-Amz-Target", "Kinesis_20131202.SubscribeToShard")
|
||||
.contentType(KINESIS_CONTENT_TYPE)
|
||||
.body("{\"ConsumerARN\": \"arn:aws:kinesis:us-east-1:000000000000:stream/no-such/consumer/no-such:99999\","
|
||||
+ "\"ShardId\": \"shardId-000000000000\","
|
||||
+ "\"StartingPosition\": {\"Type\": \"TRIM_HORIZON\"}}")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
private JsonNode decodeFirstEventStreamMessage(byte[] data) throws Exception {
|
||||
ByteBuffer buf = ByteBuffer.wrap(data);
|
||||
// Skip the first message (initial-response)
|
||||
int firstTotalLen = buf.getInt();
|
||||
buf.position(buf.position() + firstTotalLen - 4);
|
||||
// Decode second message (SubscribeToShardEvent)
|
||||
int totalLen = buf.getInt();
|
||||
int headersLen = buf.getInt();
|
||||
buf.getInt(); // prelude CRC — skip
|
||||
int payloadLen = totalLen - 12 - headersLen - 4;
|
||||
buf.position(buf.position() + headersLen); // skip headers
|
||||
byte[] payload = new byte[payloadLen];
|
||||
buf.get(payload);
|
||||
return new ObjectMapper().readTree(payload);
|
||||
}
|
||||
}
|
||||
@@ -421,15 +421,30 @@ class KmsServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void keyRotationOnAsymmetricKeyThrows() {
|
||||
void enableKeyRotationOnAsymmetricKeyThrows() {
|
||||
KmsKey key = kmsService.createKey(null, REGION);
|
||||
key.setCustomerMasterKeySpec("RSA_2048");
|
||||
key.setKeyUsage("SIGN_VERIFY");
|
||||
// Persist the modified key
|
||||
assertThrows(AwsException.class, () ->
|
||||
kmsService.enableKeyRotation(key.getKeyId(), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getKeyRotationStatusOnAsymmetricKeyReturnsFalse() {
|
||||
KmsKey key = kmsService.createKey(null, REGION);
|
||||
key.setCustomerMasterKeySpec("ECC_NIST_P256");
|
||||
key.setKeyUsage("SIGN_VERIFY");
|
||||
assertFalse(kmsService.getKeyRotationStatus(key.getKeyId(), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getKeyRotationStatusOnHmacKeyReturnsFalse() {
|
||||
KmsKey key = kmsService.createKey(null, REGION);
|
||||
key.setCustomerMasterKeySpec("HMAC_256");
|
||||
key.setKeyUsage("GENERATE_VERIFY_MAC");
|
||||
assertFalse(kmsService.getKeyRotationStatus(key.getKeyId(), REGION));
|
||||
}
|
||||
|
||||
// ── Issue #497 — HMAC key specs ─────────────────────────────────────────
|
||||
|
||||
@ParameterizedTest
|
||||
|
||||
Reference in new issue
Block a user