mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): check the ListTables ExclusiveStartTableName (#8539)
ListTables now checks its ExclusiveStartTableName against the table name length and pattern, counted in characters, and lists those errors in one message with a bad Limit, the limit first. A JSON null start name reads as absent instead of as the name "null".
This commit is contained in:
1 parent
678bd347af
commit
fc141d12d6
2 files changed
+36
-12
No files matched your search
@@ -573,23 +573,22 @@ public class NativeDynamoDbJsonHandler {
|
||||
|
||||
private Response handleListTables(JsonNode request, String region) {
|
||||
Integer limit = request.has("Limit") ? request.get("Limit").asInt() : null;
|
||||
String exclusiveStart = request.has("ExclusiveStartTableName")
|
||||
String exclusiveStart = request.hasNonNull("ExclusiveStartTableName")
|
||||
? request.get("ExclusiveStartTableName").asText() : null;
|
||||
|
||||
List<String> violations = new ArrayList<>();
|
||||
if (limit != null) {
|
||||
if (limit < 1) {
|
||||
throw SmithyValidationErrors.validationException(
|
||||
"Value '" + limit
|
||||
+ "' at 'limit' failed to satisfy constraint: "
|
||||
+ "Member must have value greater than or equal to 1");
|
||||
}
|
||||
if (limit > 100) {
|
||||
throw SmithyValidationErrors.validationException(
|
||||
"Value '" + limit
|
||||
+ "' at 'limit' failed to satisfy constraint: "
|
||||
+ "Member must have value less than or equal to 100");
|
||||
addIfPresent(violations, SmithyValidationErrors.outOfRange("limit", limit, 1, 100));
|
||||
}
|
||||
if (exclusiveStart != null) {
|
||||
addIfPresent(violations,
|
||||
SmithyValidationErrors.lengthOutOfRange("exclusiveStartTableName", exclusiveStart, 3, 255));
|
||||
if (!INDEX_NAME_CHARS.matcher(exclusiveStart).matches()) {
|
||||
violations.add(SmithyValidationErrors.pattern("exclusiveStartTableName", exclusiveStart,
|
||||
"[a-zA-Z0-9_.-]+"));
|
||||
}
|
||||
}
|
||||
throwValidationErrors(violations);
|
||||
|
||||
DynamoDbService.ListTablesResult result = dynamoDbService.listTables(region, limit, exclusiveStart);
|
||||
|
||||
|
||||
@@ -3362,6 +3362,31 @@ class NativeDynamoDbJsonHandlerTest {
|
||||
+ "Member must have length greater than or equal to 1", ex.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', textBlock = """
|
||||
{"ExclusiveStartTableName":"ab"} | 1 validation error detected: Value 'ab' at 'exclusiveStartTableName' failed to satisfy constraint: Member must have length greater than or equal to 3
|
||||
{"ExclusiveStartTableName":"😀😀"} | 2 validation errors detected: Value '😀😀' at 'exclusiveStartTableName' failed to satisfy constraint: Member must have length greater than or equal to 3; Value '😀😀' at 'exclusiveStartTableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+
|
||||
{"ExclusiveStartTableName":""} | 2 validation errors detected: Value '' at 'exclusiveStartTableName' failed to satisfy constraint: Member must have length greater than or equal to 3; Value '' at 'exclusiveStartTableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+
|
||||
{"ExclusiveStartTableName":"arn:aws:dynamodb:eu-west-2:123456789012:table/abc"} | 1 validation error detected: Value 'arn:aws:dynamodb:eu-west-2:123456789012:table/abc' at 'exclusiveStartTableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+
|
||||
{"ExclusiveStartTableName":"ab","Limit":0} | 2 validation errors detected: Value '0' at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1; Value 'ab' at 'exclusiveStartTableName' failed to satisfy constraint: Member must have length greater than or equal to 3
|
||||
{"ExclusiveStartTableName":"a!","Limit":101} | 3 validation errors detected: Value '101' at 'limit' failed to satisfy constraint: Member must have value less than or equal to 100; Value 'a!' at 'exclusiveStartTableName' failed to satisfy constraint: Member must have length greater than or equal to 3; Value 'a!' at 'exclusiveStartTableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+
|
||||
""")
|
||||
void listTablesChecksItsStartNameBesideItsLimit(String request, String message) throws Exception {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> handler.handle("ListTables", mapper.readTree(request), "eu-west-1"));
|
||||
assertEquals("ValidationException", ex.getErrorCode());
|
||||
assertEquals(message, ex.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"{\"ExclusiveStartTableName\":\"Aaa\"}", "{\"ExclusiveStartTableName\":null}"})
|
||||
void listTablesAcceptsAStartNameNoTableHasAndANullOne(String request) throws Exception {
|
||||
createUsersTable("eu-west-1");
|
||||
|
||||
Response response = handler.handle("ListTables", mapper.readTree(request), "eu-west-1");
|
||||
assertTrue(response.getEntity().toString().contains("Users"), response.getEntity().toString());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', quoteCharacter = '`', textBlock = """
|
||||
PutItem | {"TableName":"Missing","Item":{},"ReturnValues":"ALL_NEW"} | 1 validation error detected: ReturnValues can only be ALL_OLD or NONE
|
||||
|
||||
Reference in new issue
Block a user