diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java index 7c024c70e7..b5a8cdc73f 100644 --- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java @@ -538,6 +538,15 @@ public class NativeDynamoDbJsonHandler { private static final Set VALID_RETURN_CONSUMED_CAPACITY = Set.of("INDEXES", "TOTAL", "NONE"); private static final Set VALID_RETURN_ITEM_COLLECTION_METRICS = Set.of("SIZE", "NONE"); + private static String returnConsumedCapacityError(JsonNode request) { + String value = request.has("ReturnConsumedCapacity") ? request.get("ReturnConsumedCapacity").asText() : null; + if (value == null || VALID_RETURN_CONSUMED_CAPACITY.contains(value)) { + return null; + } + return "Value '" + value + "' at 'returnConsumedCapacity' failed to satisfy constraint: " + + "Member must satisfy enum value set: [INDEXES, TOTAL, NONE]"; + } + private Response handlePutItem(JsonNode request, String region) { String tableName = request.has("TableName") ? request.path("TableName").asText() : null; DynamoDbTableNames.resolve(tableName); // validate tableName before other params @@ -1091,11 +1100,9 @@ public class NativeDynamoDbJsonHandler { } // Validate ReturnConsumedCapacity before Select - String rccQuery = request.has("ReturnConsumedCapacity") ? request.get("ReturnConsumedCapacity").asText() : null; - if (rccQuery != null && !VALID_RETURN_CONSUMED_CAPACITY.contains(rccQuery)) { - throw new AwsException("ValidationException", - "1 validation error detected: Value '" + rccQuery + "' at 'returnConsumedCapacity' failed to satisfy constraint: " - + "Member must satisfy enum value set: [INDEXES, TOTAL, NONE]", 400); + String rccQueryError = returnConsumedCapacityError(request); + if (rccQueryError != null) { + throw new AwsException("ValidationException", "1 validation error detected: " + rccQueryError, 400); } // DynamoDB counts KeyConditions as a non-expression parameter only next to a KeyConditionExpression. @@ -1259,6 +1266,11 @@ public class NativeDynamoDbJsonHandler { } throwValidationErrors(rangeErrors); + String rccScanError = returnConsumedCapacityError(request); + if (rccScanError != null) { + throw new AwsException("ValidationException", "1 validation error detected: " + rccScanError, 400); + } + rejectMixedParameters(request, List.of("AttributesToGet", "ScanFilter", "ConditionalOperator"), List.of("ProjectionExpression", "FilterExpression")); diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandlerTest.java index e0c78ce95a..32a56ea847 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandlerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandlerTest.java @@ -1233,6 +1233,25 @@ class NativeDynamoDbJsonHandlerTest { + "Member must have value greater than or equal to 1", ex.getMessage()); } + @Test + void scanRejectsAnUnknownReturnConsumedCapacityBeforeTheTableLookup() { + AwsException ex = expectValidationException("Scan", json(""" + {"TableName": "Missing", "ReturnConsumedCapacity": "BOGUS", "Select": "BOGUS"} + """)); + assertEquals("1 validation error detected: Value 'BOGUS' at 'returnConsumedCapacity' " + + "failed to satisfy constraint: Member must satisfy enum value set: [INDEXES, TOTAL, NONE]", + ex.getMessage()); + } + + @Test + void scanReportsTheLimitBeforeReturnConsumedCapacity() { + AwsException ex = expectValidationException("Scan", json(""" + {"TableName": "Users", "Limit": 0, "ReturnConsumedCapacity": "BOGUS"} + """)); + assertEquals("1 validation error detected: Value at 'Limit' failed to satisfy constraint: " + + "Member must have value greater than or equal to 1", ex.getMessage()); + } + @Test void scanAcceptsSegmentsAtTheBounds() throws Exception { createUsersTable("eu-west-1");