mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(kms): add GenerateRandom action (#1036)
- Add GenerateRandom action routing and handler in KmsJsonHandler - Add SecureRandom field, constructor overload, and generateRandom() method with bounds validation - Reject unsupported Recipient and CustomKeyStoreId fields - Add integration tests for happy path, boundaries, validation, and unsupported fields - Add SDK compatibility tests for Java, Python, and Node
This commit is contained in:
1 parent
c8b0048bac
commit
30a598f080
6 files changed
+234
-2
No files matched your search
@@ -109,6 +109,170 @@ class KmsIntegrationTest {
|
||||
.body("__type", equalTo("KMSInvalidMacException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateRandomReturnsBase64Plaintext() {
|
||||
// RED phase: This test is expected to fail until GenerateRandom is wired
|
||||
// in KmsJsonHandler.handle(). Currently returns 400 UnsupportedOperation.
|
||||
String plaintextBase64 = given()
|
||||
.header("X-Amz-Target", "TrentService.GenerateRandom")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"NumberOfBytes": 32
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Plaintext", notNullValue())
|
||||
.extract().jsonPath().getString("Plaintext");
|
||||
|
||||
assertEquals(32, Base64.getDecoder().decode(plaintextBase64).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateRandomMissingNumberOfBytesReturnsError() {
|
||||
given()
|
||||
.header("X-Amz-Target", "TrentService.GenerateRandom")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateRandomZeroBytesReturnsError() {
|
||||
given()
|
||||
.header("X-Amz-Target", "TrentService.GenerateRandom")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"NumberOfBytes": 0
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateRandomNegativeBytesReturnsError() {
|
||||
given()
|
||||
.header("X-Amz-Target", "TrentService.GenerateRandom")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"NumberOfBytes": -1
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateRandomTooManyBytesReturnsError() {
|
||||
given()
|
||||
.header("X-Amz-Target", "TrentService.GenerateRandom")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"NumberOfBytes": 1025
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateRandomOneByteReturnsSuccess() {
|
||||
String plaintextBase64 = given()
|
||||
.header("X-Amz-Target", "TrentService.GenerateRandom")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"NumberOfBytes": 1
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Plaintext", notNullValue())
|
||||
.extract().jsonPath().getString("Plaintext");
|
||||
|
||||
assertEquals(1, Base64.getDecoder().decode(plaintextBase64).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateRandomMaxBytesReturnsSuccess() {
|
||||
String plaintextBase64 = given()
|
||||
.header("X-Amz-Target", "TrentService.GenerateRandom")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"NumberOfBytes": 1024
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Plaintext", notNullValue())
|
||||
.extract().jsonPath().getString("Plaintext");
|
||||
|
||||
assertEquals(1024, Base64.getDecoder().decode(plaintextBase64).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateRandomWithRecipientReturnsError() {
|
||||
given()
|
||||
.header("X-Amz-Target", "TrentService.GenerateRandom")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"NumberOfBytes": 32,
|
||||
"Recipient": {}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateRandomWithCustomKeyStoreIdReturnsError() {
|
||||
given()
|
||||
.header("X-Amz-Target", "TrentService.GenerateRandom")
|
||||
.contentType(KMS_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"NumberOfBytes": 32,
|
||||
"CustomKeyStoreId": "cks-1234567890"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rotateKeyOnDemandReturnsKeyId() {
|
||||
String keyId = given()
|
||||
|
||||
Reference in new issue
Block a user