feat(kms): add GetKeyRotationStatus, EnableKeyRotation, and DisableKeyRotation (#290) (#322)

Add key rotation management with persisted state on the KmsKey model.
Rotation is only supported for symmetric ENCRYPT_DECRYPT keys, matching
AWS behavior. Includes validation that rejects asymmetric keys with
UnsupportedOperationException.
This commit is contained in:
TiM authored and GitHub committed 2026-04-09 23:51:45 -05:00
1 parent 473fece1c5
commit 1fa7ae7551
5 files changed
+103

No files matched your search

@@ -287,4 +287,43 @@ class KmsServiceTest {
assertThrows(AwsException.class, () ->
kmsService.putKeyPolicy("non-existent", "{}", REGION));
}
// ── Issue #290 — Key Rotation ───────────────────────────────────────────
@Test
void getKeyRotationStatusDefaultFalse() {
KmsKey key = kmsService.createKey(null, REGION);
assertFalse(kmsService.getKeyRotationStatus(key.getKeyId(), REGION));
}
@Test
void enableAndGetKeyRotationStatus() {
KmsKey key = kmsService.createKey(null, REGION);
kmsService.enableKeyRotation(key.getKeyId(), REGION);
assertTrue(kmsService.getKeyRotationStatus(key.getKeyId(), REGION));
}
@Test
void disableKeyRotationAfterEnable() {
KmsKey key = kmsService.createKey(null, REGION);
kmsService.enableKeyRotation(key.getKeyId(), REGION);
kmsService.disableKeyRotation(key.getKeyId(), REGION);
assertFalse(kmsService.getKeyRotationStatus(key.getKeyId(), REGION));
}
@Test
void keyRotationOnNonExistentKeyThrows() {
assertThrows(AwsException.class, () ->
kmsService.getKeyRotationStatus("non-existent", REGION));
}
@Test
void keyRotationOnAsymmetricKeyThrows() {
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));
}
}