mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(dynamodb): honor customer-supplied KMS key for table SSE (#1923)
* fix(dynamodb): honor customer-supplied KMS key for table SSE
CreateTable discarded SSESpecification.KMSMasterKeyId and always stored
the default AWS-managed key ARN, so CreateTable/DescribeTable responses
never reflected a customer-managed key. It also hardcoded SSEType to
KMS, ignoring AES256. UpdateTable had no SSESpecification handling at
all, so a table's encryption could not be enabled, rotated to a new
key, or disabled after creation.
* fix(dynamodb): persist post-create/update SSE state and validate SSEType
Address PR review feedback: CreateTable/UpdateTable mutated the table's
SSE fields after the service layer's own persistence call, so a
persistent/WAL storage backend would silently drop the encryption
settings (along with other post-create/update fields) on reload. Both
handlers now re-persist the fully mutated table before responding.
SSEType was also accepted verbatim with no enum check, letting an
invalid value be stored and echoed back in SSEDescription. Both
handlers now validate it against {KMS, AES256}.
Adds a reload test proving SSE settings survive a fresh
PersistentStorage instance reading the same file, an AES256 coverage
test, and validation-failure tests for both CreateTable and
UpdateTable.
* fix(dynamodb): validate SSEType before mutating, not after
Closes the remaining review items on this PR:
- Resolved the merge conflict with #1811 (global table v2 replicas) in
handleUpdateTable. Also found and fixed a duplicate: main had
independently added its own persistTable(...) flush for the same
stream-persistence reason this PR added one for SSE, so the two
collapse into one call.
- Moved SSEType validation ahead of createTable/updateTable in both
handlers, mirroring the existing validateReplicaUpdates-before-
updateTable pattern already used in handleUpdateTable. Previously an
invalid SSEType threw only after the table (and possibly its stream)
were already created/mutated, leaving real side effects behind a
ValidationException -- real DynamoDB rejects the whole request first.
- The merge resolution deliberately does NOT follow the literal
"replica block first" suggestion from review: applyReplicaUpdates
re-fetches the table from storage for its own persist, and a
persistent backend does not hold the live object (confirmed by
reading both applyReplicaUpdates itself and the comment already on
main's persistTable call). Running it before the stream/SSE
mutations are flushed would silently drop them, not just SSE's.
Kept main's original persistTable-then-applyReplicaUpdates ordering
instead, with the SSE block slotted in before the flush, matching
the same stream-then-SSE-then-persist shape CreateTable already uses.
- Added DescribeTable assertions to both existing invalid-SSEType
tests confirming no side effects survive the failed request (no
table for CreateTable, no SSEDescription change for UpdateTable) --
meaningful now that validation actually runs first.
AES256 test coverage (createTableWithAes256SseOmitsKmsMasterKeyArn)
was already present as of the second commit on this branch; no
further gap there.
---------
Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
Co-authored-by: Priamo <pgermosen@gmail.com>
This commit is contained in:
3 files changed
+435
-12
No files matched your search
+72
-12
@@ -25,6 +25,7 @@ public class DynamoDbJsonHandler {
|
||||
|
||||
private static final String DEFAULT_ACCOUNT_ID = "000000000000";
|
||||
private static final String SSE_TYPE_KMS = "KMS";
|
||||
private static final Set<String> VALID_SSE_TYPES = Set.of("AES256", "KMS");
|
||||
|
||||
private final DynamoDbService dynamoDbService;
|
||||
private final DynamoDbStreamService dynamoDbStreamService;
|
||||
@@ -186,6 +187,16 @@ public class DynamoDbJsonHandler {
|
||||
|
||||
boolean deletionProtection = request.path("DeletionProtectionEnabled").asBoolean(false);
|
||||
|
||||
// Parsed and validated before createTable below: that call and the stream-enable that
|
||||
// follows it both have side effects, so an invalid SSEType must fail before either runs
|
||||
// rather than after, or ValidationException would leave a real table (and stream) behind.
|
||||
JsonNode sseSpec = request.path("SSESpecification");
|
||||
boolean sseEnabled = !sseSpec.isMissingNode() && sseSpec.path("Enabled").asBoolean(false);
|
||||
String sseType = sseEnabled ? sseSpec.path("SSEType").asText(SSE_TYPE_KMS) : null;
|
||||
if (sseEnabled) {
|
||||
validateSseType(sseType);
|
||||
}
|
||||
|
||||
TableDefinition table = dynamoDbService.createTable(tableName, keySchema, attrDefs,
|
||||
readCapacity, writeCapacity, gsis, lsis, region);
|
||||
table.setTableStatus(initialStatus);
|
||||
@@ -232,11 +243,15 @@ public class DynamoDbJsonHandler {
|
||||
table.setStreamViewType(viewType);
|
||||
}
|
||||
|
||||
JsonNode sseSpec = request.path("SSESpecification");
|
||||
if (!sseSpec.isMissingNode() && sseSpec.path("Enabled").asBoolean(false)) {
|
||||
if (sseEnabled) {
|
||||
table.setSseEnabled(true);
|
||||
table.setSseType(SSE_TYPE_KMS);
|
||||
table.setKmsMasterKeyArn(defaultKmsMasterKeyArn(region));
|
||||
table.setSseType(sseType);
|
||||
if (SSE_TYPE_KMS.equals(sseType)) {
|
||||
JsonNode kmsMasterKeyId = sseSpec.path("KMSMasterKeyId");
|
||||
table.setKmsMasterKeyArn(!kmsMasterKeyId.isMissingNode() && !kmsMasterKeyId.isNull()
|
||||
? kmsMasterKeyId.asText()
|
||||
: defaultKmsMasterKeyArn(region));
|
||||
}
|
||||
}
|
||||
|
||||
// Everything above mutates the table AFTER createTable stored it, and a persistent
|
||||
@@ -247,6 +262,15 @@ public class DynamoDbJsonHandler {
|
||||
return table;
|
||||
}
|
||||
|
||||
private void validateSseType(String sseType) {
|
||||
if (!VALID_SSE_TYPES.contains(sseType)) {
|
||||
throw new AwsException("ValidationException",
|
||||
"1 validation error detected: Value '" + sseType
|
||||
+ "' at 'sSESpecification.sSEType' failed to satisfy constraint: "
|
||||
+ "Member must satisfy enum value set: [AES256, KMS]", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private Response handleDeleteTable(JsonNode request, String region) {
|
||||
String tableName = request.path("TableName").asText();
|
||||
TableDefinition table = dynamoDbService.describeTable(tableName, region);
|
||||
@@ -1349,6 +1373,18 @@ public class DynamoDbJsonHandler {
|
||||
tableName, addRegions, removeRegions, updateRegions, region);
|
||||
}
|
||||
|
||||
// Parsed and validated up front, same as the replica check above: updateTable and the
|
||||
// mutations that follow it have side effects (persisted throughput/GSI changes, stream
|
||||
// enable/disable), so an invalid SSEType must fail before any of them run rather than
|
||||
// after, or ValidationException would leave a partially-applied update behind.
|
||||
JsonNode sseSpec = request.path("SSESpecification");
|
||||
boolean sseSpecified = !sseSpec.isMissingNode();
|
||||
boolean sseEnabled = sseSpecified && sseSpec.path("Enabled").asBoolean(false);
|
||||
String sseType = sseEnabled ? sseSpec.path("SSEType").asText(SSE_TYPE_KMS) : null;
|
||||
if (sseEnabled) {
|
||||
validateSseType(sseType);
|
||||
}
|
||||
|
||||
TableDefinition table = dynamoDbService.updateTable(tableName, readCapacity, writeCapacity,
|
||||
gsiCreates, gsiDeletes, newAttrDefs, region);
|
||||
|
||||
@@ -1419,15 +1455,36 @@ public class DynamoDbJsonHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// Same flush as CreateTable: the stream mutations above land after updateTable's write,
|
||||
// so without this a retargeted view type is rebuilt from the stale persisted value on
|
||||
// restart and records resume the old image shape.
|
||||
if (sseSpecified) {
|
||||
if (sseEnabled) {
|
||||
table.setSseEnabled(true);
|
||||
table.setSseType(sseType);
|
||||
if (SSE_TYPE_KMS.equals(sseType)) {
|
||||
JsonNode kmsMasterKeyId = sseSpec.path("KMSMasterKeyId");
|
||||
table.setKmsMasterKeyArn(!kmsMasterKeyId.isMissingNode() && !kmsMasterKeyId.isNull()
|
||||
? kmsMasterKeyId.asText()
|
||||
: defaultKmsMasterKeyArn(region));
|
||||
} else {
|
||||
table.setKmsMasterKeyArn(null);
|
||||
}
|
||||
} else {
|
||||
table.setSseEnabled(false);
|
||||
table.setSseType(null);
|
||||
table.setKmsMasterKeyArn(null);
|
||||
}
|
||||
}
|
||||
|
||||
// Same flush as CreateTable: the stream and SSE mutations above land after updateTable's
|
||||
// write, so without this a retargeted view type or SSE change is rebuilt from the stale
|
||||
// persisted value on restart. Must run before applyReplicaUpdates below, which re-fetches
|
||||
// the table from storage for its own persist -- a persistent backend serializes on write
|
||||
// rather than holding the live object, so without this flush first, that re-fetch would
|
||||
// see neither the stream nor the SSE mutations above.
|
||||
dynamoDbService.persistTable(tableName, table, region);
|
||||
|
||||
if (!addRegions.isEmpty() || !removeRegions.isEmpty() || !updateRegions.isEmpty()) {
|
||||
table = dynamoDbService.applyReplicaUpdates(tableName, addRegions, removeRegions, updateRegions, region);
|
||||
}
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("TableDescription", tableToNode(table));
|
||||
return Response.ok(response).build();
|
||||
@@ -2243,10 +2300,13 @@ public class DynamoDbJsonHandler {
|
||||
if (table.isSseEnabled()) {
|
||||
ObjectNode sseDescription = objectMapper.createObjectNode();
|
||||
sseDescription.put("Status", "ENABLED");
|
||||
sseDescription.put("SSEType", table.getSseType() != null ? table.getSseType() : SSE_TYPE_KMS);
|
||||
sseDescription.put("KMSMasterKeyArn", table.getKmsMasterKeyArn() != null
|
||||
? table.getKmsMasterKeyArn()
|
||||
: defaultKmsMasterKeyArn(AwsArnUtils.regionOrDefault(table.getTableArn(), "us-east-1")));
|
||||
String sseType = table.getSseType() != null ? table.getSseType() : SSE_TYPE_KMS;
|
||||
sseDescription.put("SSEType", sseType);
|
||||
if (SSE_TYPE_KMS.equals(sseType)) {
|
||||
sseDescription.put("KMSMasterKeyArn", table.getKmsMasterKeyArn() != null
|
||||
? table.getKmsMasterKeyArn()
|
||||
: defaultKmsMasterKeyArn(AwsArnUtils.regionOrDefault(table.getTableArn(), "us-east-1")));
|
||||
}
|
||||
node.set("SSEDescription", sseDescription);
|
||||
}
|
||||
|
||||
|
||||
+314
@@ -163,6 +163,320 @@ class DynamoDbIntegrationTest {
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTableWithCustomKmsKeyRetainsItOnDescribe() {
|
||||
String customKeyArn = "arn:aws:kms:us-east-1:000000000000:key/custom-key-id";
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "CustomKmsKeyTable",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST",
|
||||
"SSESpecification": {"Enabled": true, "SSEType": "KMS", "KMSMasterKeyId": "%s"}
|
||||
}
|
||||
""".formatted(customKeyArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TableDescription.SSEDescription.Status", equalTo("ENABLED"))
|
||||
.body("TableDescription.SSEDescription.SSEType", equalTo("KMS"))
|
||||
.body("TableDescription.SSEDescription.KMSMasterKeyArn", equalTo(customKeyArn));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DescribeTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "CustomKmsKeyTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Table.SSEDescription.Status", equalTo("ENABLED"))
|
||||
.body("Table.SSEDescription.SSEType", equalTo("KMS"))
|
||||
.body("Table.SSEDescription.KMSMasterKeyArn", equalTo(customKeyArn));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "CustomKmsKeyTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTableCanEnableRotateAndDisableSse() {
|
||||
String firstKeyArn = "arn:aws:kms:us-east-1:000000000000:key/first-key-id";
|
||||
String rotatedKeyArn = "arn:aws:kms:us-east-1:000000000000:key/rotated-key-id";
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "UpdateSseTable",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TableDescription.SSEDescription", nullValue());
|
||||
|
||||
// Enable SSE with a customer-supplied KMS key via UpdateTable.
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.UpdateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "UpdateSseTable",
|
||||
"SSESpecification": {"Enabled": true, "SSEType": "KMS", "KMSMasterKeyId": "%s"}
|
||||
}
|
||||
""".formatted(firstKeyArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TableDescription.SSEDescription.Status", equalTo("ENABLED"))
|
||||
.body("TableDescription.SSEDescription.SSEType", equalTo("KMS"))
|
||||
.body("TableDescription.SSEDescription.KMSMasterKeyArn", equalTo(firstKeyArn));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DescribeTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "UpdateSseTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Table.SSEDescription.Status", equalTo("ENABLED"))
|
||||
.body("Table.SSEDescription.SSEType", equalTo("KMS"))
|
||||
.body("Table.SSEDescription.KMSMasterKeyArn", equalTo(firstKeyArn));
|
||||
|
||||
// Rotate to a different customer-supplied KMS key via UpdateTable.
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.UpdateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "UpdateSseTable",
|
||||
"SSESpecification": {"Enabled": true, "SSEType": "KMS", "KMSMasterKeyId": "%s"}
|
||||
}
|
||||
""".formatted(rotatedKeyArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TableDescription.SSEDescription.KMSMasterKeyArn", equalTo(rotatedKeyArn));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DescribeTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "UpdateSseTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Table.SSEDescription.KMSMasterKeyArn", equalTo(rotatedKeyArn));
|
||||
|
||||
// Disable SSE via UpdateTable.
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.UpdateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "UpdateSseTable",
|
||||
"SSESpecification": {"Enabled": false}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TableDescription.SSEDescription", nullValue());
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DescribeTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "UpdateSseTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Table.SSEDescription", nullValue());
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "UpdateSseTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTableWithAes256SseOmitsKmsMasterKeyArn() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "Aes256SseTable",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST",
|
||||
"SSESpecification": {"Enabled": true, "SSEType": "AES256"}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TableDescription.SSEDescription.Status", equalTo("ENABLED"))
|
||||
.body("TableDescription.SSEDescription.SSEType", equalTo("AES256"))
|
||||
.body("TableDescription.SSEDescription.KMSMasterKeyArn", nullValue());
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DescribeTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "Aes256SseTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Table.SSEDescription.Status", equalTo("ENABLED"))
|
||||
.body("Table.SSEDescription.SSEType", equalTo("AES256"))
|
||||
.body("Table.SSEDescription.KMSMasterKeyArn", nullValue());
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "Aes256SseTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTableWithInvalidSseTypeFailsValidation() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "InvalidSseTypeTable",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST",
|
||||
"SSESpecification": {"Enabled": true, "SSEType": "BOGUS"}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
// SSEType is validated before CreateTable runs, so the table must not exist at all --
|
||||
// a real DynamoDB rejects the whole request rather than leaving a table behind.
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DescribeTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "InvalidSseTypeTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTableWithInvalidSseTypeFailsValidation() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "UpdateInvalidSseTypeTable",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.UpdateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "UpdateInvalidSseTypeTable",
|
||||
"SSESpecification": {"Enabled": true, "SSEType": "BOGUS"}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
// SSEType is validated before UpdateTable applies anything, so the table must still
|
||||
// show no SSEDescription at all -- the failed request must not have partially applied.
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DescribeTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "UpdateInvalidSseTypeTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Table.SSEDescription", nullValue());
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "UpdateInvalidSseTypeTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTableWithGsiAndLsi() {
|
||||
given()
|
||||
|
||||
+49
@@ -1,11 +1,13 @@
|
||||
package io.github.hectorvent.floci.services.dynamodb;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.PersistentStorage;
|
||||
import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition;
|
||||
import io.github.hectorvent.floci.services.dynamodb.model.GlobalSecondaryIndex;
|
||||
import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
|
||||
@@ -13,8 +15,11 @@ import io.github.hectorvent.floci.services.dynamodb.model.TableDefinition;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -352,6 +357,50 @@ class DynamoDbJsonHandlerTest {
|
||||
assertNull(reasons.get(0).get("Message"), "non failed item must not have a Message field");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sseSettingsSurvivePersistentStorageReload(@TempDir Path tempDir) throws Exception {
|
||||
Path tableFile = tempDir.resolve("dynamodb-tables.json");
|
||||
TypeReference<Map<String, TableDefinition>> typeReference = new TypeReference<>() {};
|
||||
|
||||
DynamoDbService persistentService = new DynamoDbService(new PersistentStorage<>(tableFile, typeReference));
|
||||
DynamoDbJsonHandler persistentHandler = new DynamoDbJsonHandler(persistentService, null, null, mapper);
|
||||
|
||||
ObjectNode createRequest = mapper.createObjectNode();
|
||||
createRequest.put("TableName", "PersistedSseTable");
|
||||
ObjectNode keySchemaElement = mapper.createObjectNode();
|
||||
keySchemaElement.put("AttributeName", "pk");
|
||||
keySchemaElement.put("KeyType", "HASH");
|
||||
createRequest.putArray("KeySchema").add(keySchemaElement);
|
||||
ObjectNode attrDef = mapper.createObjectNode();
|
||||
attrDef.put("AttributeName", "pk");
|
||||
attrDef.put("AttributeType", "S");
|
||||
createRequest.putArray("AttributeDefinitions").add(attrDef);
|
||||
createRequest.put("BillingMode", "PAY_PER_REQUEST");
|
||||
|
||||
persistentHandler.handle("CreateTable", createRequest, "us-east-1");
|
||||
|
||||
ObjectNode updateRequest = mapper.createObjectNode();
|
||||
updateRequest.put("TableName", "PersistedSseTable");
|
||||
ObjectNode sseSpec = updateRequest.putObject("SSESpecification");
|
||||
sseSpec.put("Enabled", true);
|
||||
sseSpec.put("SSEType", "KMS");
|
||||
sseSpec.put("KMSMasterKeyId", "arn:aws:kms:us-east-1:000000000000:key/reload-test-key");
|
||||
|
||||
persistentHandler.handle("UpdateTable", updateRequest, "us-east-1");
|
||||
|
||||
// Simulate a process restart: a brand new storage backend instance reading the same file,
|
||||
// independent of the in-memory table object mutated above.
|
||||
PersistentStorage<String, TableDefinition> reloadedStorage = new PersistentStorage<>(tableFile, typeReference);
|
||||
reloadedStorage.load();
|
||||
DynamoDbService reloadedService = new DynamoDbService(reloadedStorage);
|
||||
|
||||
TableDefinition reloadedTable = reloadedService.describeTable("PersistedSseTable", "us-east-1");
|
||||
assertTrue(reloadedTable.isSseEnabled(), "SSE must survive a storage reload");
|
||||
assertEquals("KMS", reloadedTable.getSseType());
|
||||
assertEquals("arn:aws:kms:us-east-1:000000000000:key/reload-test-key",
|
||||
reloadedTable.getKmsMasterKeyArn());
|
||||
}
|
||||
|
||||
// PutResourcePolicy/GetResourcePolicy/DeleteResourcePolicy previously fell through to the
|
||||
// default 400 UnknownOperationException branch, which blocks the Terraform provider's
|
||||
// aws_dynamodb_resource_policy resource at apply time.
|
||||
|
||||
Reference in new issue
Block a user