mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(dynamodb): reject an unknown ReturnConsumedCapacity on Scan (#5669)
* fix(dynamodb): reject an unknown ReturnConsumedCapacity on Scan * refactor(dynamodb): share the ReturnConsumedCapacity enum message for Query and Scan
This commit is contained in:
1 parent
b395560fe2
commit
f3e1cb6006
2 files changed
+36
-5
No files matched your search
+17
-5
@@ -538,6 +538,15 @@ public class NativeDynamoDbJsonHandler {
|
||||
private static final Set<String> VALID_RETURN_CONSUMED_CAPACITY = Set.of("INDEXES", "TOTAL", "NONE");
|
||||
private static final Set<String> 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"));
|
||||
|
||||
+19
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user