mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix: count Unicode code points in Smithy length validation (#6456)
* fix: count Unicode code points in Smithy length validation Count supplementary characters once, align existing formatter guards, and migrate remaining DynamoDB string messages while preserving validation order and operation-specific errors. Signed-off-by: Andre Kurait <AndreKurait@gmail.com> * fix: centralize length checks in the Smithy helper Use the helper null return in CloudWatch, EventBridge and DynamoDB vector-index validation. Preserve null, whitespace and aggregation errors. Signed-off-by: Andre Kurait <AndreKurait@gmail.com> --------- Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
f6126964aa
commit
452633fe7d
9 files changed
+113
-30
No files matched your search
@@ -65,4 +65,15 @@ class SmithyValidationErrorsTest {
|
||||
+ "Member must have length greater than or equal to 1",
|
||||
SmithyValidationErrors.lengthTooShort("name", " ", 1));
|
||||
}
|
||||
@Test
|
||||
void lengthBoundsCountSupplementaryCharactersOnce() {
|
||||
String value = "\uD83D\uDE00";
|
||||
assertNull(SmithyValidationErrors.lengthOutOfRange("name", value, 1, 1));
|
||||
assertEquals(SmithyValidationErrors.lengthTooShort("name", value, 2),
|
||||
SmithyValidationErrors.lengthOutOfRange("name", value, 2, 3));
|
||||
assertEquals("Value '" + value.repeat(2) + "' at 'name' failed to satisfy constraint: "
|
||||
+ "Member must have length less than or equal to 1",
|
||||
SmithyValidationErrors.lengthOutOfRange("name", value.repeat(2), 0, 1));
|
||||
}
|
||||
|
||||
}
|
||||
+33
@@ -259,6 +259,39 @@ class CompositeAlarmServiceTest {
|
||||
assertEquals(remove ? Map.of() : Map.of("team", "new"), result.getTags());
|
||||
}
|
||||
|
||||
@Test
|
||||
void supplementaryCharactersRespectAlarmAndRuleLengthBounds() {
|
||||
String scalar = "\uD83D\uDE00";
|
||||
put(scalar.repeat(255), "TRUE");
|
||||
assertThrows(AwsException.class, () -> put(scalar.repeat(256), "TRUE"));
|
||||
String rule = "ALARM(\"" + scalar.repeat(10231) + "\")";
|
||||
assertDoesNotThrow(() -> CompositeAlarmRule.parse(rule));
|
||||
assertThrows(AwsException.class, () -> CompositeAlarmRule.parse(rule + " "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void blankAlarmFieldsRetainLengthErrorPrecedence() {
|
||||
for (String name : List.of("", " ", " ".repeat(256))) {
|
||||
AwsException error = assertThrows(AwsException.class, () -> put(name, "TRUE"));
|
||||
String bound = name.length() > 255 ? "less than or equal to 255" : "greater than or equal to 1";
|
||||
assertEquals("1 validation error detected: Value '" + name
|
||||
+ "' at 'alarmName' failed to satisfy constraint: Member must have length " + bound,
|
||||
error.getMessage());
|
||||
}
|
||||
for (String rule : List.of("", " ", " ".repeat(10241))) {
|
||||
AwsException error = assertThrows(AwsException.class, () -> CompositeAlarmRule.parse(rule));
|
||||
String bound = rule.length() > 10240 ? "less than or equal to 10240" : "greater than or equal to 1";
|
||||
assertEquals("1 validation error detected: Value '" + rule
|
||||
+ "' at 'alarmRule' failed to satisfy constraint: Member must have length " + bound,
|
||||
error.getMessage());
|
||||
}
|
||||
assertEquals("1 validation error detected: Value null at 'alarmName' failed to satisfy constraint: "
|
||||
+ "Member must not be null", assertThrows(AwsException.class, () -> put(null, "TRUE")).getMessage());
|
||||
assertEquals("1 validation error detected: Value null at 'alarmRule' failed to satisfy constraint: "
|
||||
+ "Member must not be null", assertThrows(AwsException.class,
|
||||
() -> CompositeAlarmRule.parse(null)).getMessage());
|
||||
}
|
||||
|
||||
private CompositeAlarm put(String name, String rule) {
|
||||
CompositeAlarm alarm = new CompositeAlarm();
|
||||
alarm.setAlarmName(name);
|
||||
|
||||
+15
@@ -381,6 +381,21 @@ class DynamoDbExportIntegrationTest {
|
||||
.body("ExportDescription.S3Prefix", equalTo("ends-with/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void s3PrefixLengthCountsSupplementaryCharactersOnce() {
|
||||
String scalar = "\uD83D\uDE00";
|
||||
String shortPrefix = scalar.repeat(2);
|
||||
expectError(exportWithPrefix("ExportPrefixMissing", shortPrefix), "ValidationException",
|
||||
"Invalid Request: 1 validation error detected: Value '" + shortPrefix
|
||||
+ "' at 's3Prefix' failed to satisfy constraint: Member must have length greater than or equal to 3");
|
||||
expectError(exportWithPrefix("ExportPrefixMissing", scalar.repeat(1024)), "TableNotFoundException",
|
||||
"Table not found: " + TABLE_ARN_PREFIX + "ExportPrefixMissing");
|
||||
String longPrefix = scalar.repeat(1025);
|
||||
expectError(exportWithPrefix("ExportPrefixMissing", longPrefix), "ValidationException",
|
||||
"1 validation error detected: Value '" + longPrefix
|
||||
+ "' at 's3Prefix' failed to satisfy constraint: Member must have length less than or equal to 1024");
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
private static ValidatableResponse exportWithPrefix(String table, String prefix) {
|
||||
|
||||
+12
@@ -308,6 +308,18 @@ class EventBridgeServiceTest {
|
||||
.getEventSourceArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void archiveLengthBoundsCountSupplementaryCharactersOnce() {
|
||||
String scalar = "\uD83D\uDE00";
|
||||
String pattern = "{\"detail\":[\"" + scalar.repeat(4081) + "\"]}";
|
||||
assertDoesNotThrow(() -> service.createArchive(
|
||||
"unicode-archive", DEFAULT_BUS, scalar.repeat(512), pattern, 0, REGION));
|
||||
assertThrows(AwsException.class, () -> service.createArchive(
|
||||
"long-description", DEFAULT_BUS, scalar.repeat(513), null, 0, REGION));
|
||||
assertThrows(AwsException.class, () -> service.createArchive(
|
||||
"long-pattern", DEFAULT_BUS, null, pattern + " ", 0, REGION));
|
||||
}
|
||||
|
||||
/** The messages AWS returns; the account is checked before the region. */
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', value = {
|
||||
|
||||
Reference in new issue
Block a user