mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(eventbridgev2): report a string's length before its pattern (#9507)
An event source request member that broke both its length and its pattern answered the pattern violation first, except in RotateWebhookCredentials. AWS now answers the length first in every event source operation (measured in us-east-1), so EventBridgeV2RequestShapes checks them all in that order.
This commit is contained in:
1 parent
1f86733b1c
commit
4469e51f6f
3 files changed
+37
-23
No files matched your search
@@ -19,11 +19,6 @@ final class EventBridgeV2RequestShapes {
|
||||
private static final int MAX_VIOLATIONS = 10;
|
||||
|
||||
private static final RequestConstraintCheck CHECK = RequestConstraintCheck.load(
|
||||
"aws/eventbridgev2-request-shapes.json", "EventBridge V2 request shapes", new Messages(),
|
||||
new RequestConstraintCheck.ViolationOrder(true, true));
|
||||
|
||||
/** Every string member of RotateWebhookCredentials reports its length before its pattern. */
|
||||
private static final RequestConstraintCheck LENGTH_FIRST_CHECK = RequestConstraintCheck.load(
|
||||
"aws/eventbridgev2-request-shapes.json", "EventBridge V2 request shapes", new Messages(),
|
||||
new RequestConstraintCheck.ViolationOrder(false, true));
|
||||
|
||||
@@ -36,8 +31,7 @@ final class EventBridgeV2RequestShapes {
|
||||
}
|
||||
|
||||
static void check(String operation, JsonNode request) {
|
||||
RequestConstraintCheck check = "RotateWebhookCredentials".equals(operation) ? LENGTH_FIRST_CHECK : CHECK;
|
||||
List<String> violations = check.violations(operation, withoutWhsecPrefix(request));
|
||||
List<String> violations = CHECK.violations(operation, withoutWhsecPrefix(request));
|
||||
if (!violations.isEmpty()) {
|
||||
throw SmithyValidationErrors.exception("InvalidInputException",
|
||||
violations.subList(0, Math.min(violations.size(), MAX_VIOLATIONS)));
|
||||
|
||||
+33
-13
@@ -23,6 +23,9 @@ class EventBridgeV2RequestShapesTest {
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private static final String BUS_ARN =
|
||||
"arn:aws:events:us-east-1:123456789012:event-busv2/orders/abcdefghijklmnopqrstuvwxy";
|
||||
|
||||
private static final String REQUEST = "{\"Name\":\"n\",\"EventBusArn\":"
|
||||
+ "\"arn:aws:events:us-east-1:123456789012:event-busv2/orders/abcdefghijklmnopqrstuvwxy\","
|
||||
+ "\"Configuration\":{\"WebhookEventsConfiguration\":{\"RoleArn\":"
|
||||
@@ -155,8 +158,8 @@ class EventBridgeV2RequestShapesTest {
|
||||
"Value 'X' at 'configuration.webhookEventsConfiguration.logConfiguration.includePayload' failed to satisfy constraint: Member must satisfy enum value set: [ON_ERROR_ONLY, FULL]",
|
||||
"Value '[bad header]' at 'configuration.webhookEventsConfiguration.metadataHttpHeaders' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 128, Member must have length greater than or equal to 1, Member must satisfy regular expression pattern: [!#$%&'*+\\-.^_`|~0-9A-Za-z]+, Member must not be null]",
|
||||
"Value 'X' at 'configuration.webhookEventsConfiguration.authConfiguration.hmacAuthConfiguration.secretEncoding' failed to satisfy constraint: Member must satisfy enum value set: [RAW, BASE64]",
|
||||
"Value '' at 'configuration.webhookEventsConfiguration.authConfiguration.hmacAuthConfiguration.timestampPrefix' failed to satisfy constraint: Member must satisfy regular expression pattern: [\\u0020-\\u007E]+",
|
||||
"Value '' at 'configuration.webhookEventsConfiguration.authConfiguration.hmacAuthConfiguration.timestampPrefix' failed to satisfy constraint: Member must have length greater than or equal to 1",
|
||||
"Value '' at 'configuration.webhookEventsConfiguration.authConfiguration.hmacAuthConfiguration.timestampPrefix' failed to satisfy constraint: Member must satisfy regular expression pattern: [\\u0020-\\u007E]+",
|
||||
"Value 'bad header' at 'configuration.webhookEventsConfiguration.authConfiguration.hmacAuthConfiguration.messageIdHttpHeader' failed to satisfy constraint: Member must satisfy regular expression pattern: [!#$%&'*+\\-.^_`|~0-9A-Za-z]+");
|
||||
}
|
||||
|
||||
@@ -226,10 +229,24 @@ class EventBridgeV2RequestShapesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listEmptyNamePrefixBreaksPatternThenLength() {
|
||||
void createEmptyNameBreaksLengthThenPattern() {
|
||||
assertAnswers("CreateEventSource", "{\"Name\":\"\",\"EventBusArn\":\"" + BUS_ARN + "\",\"Configuration\":{}}",
|
||||
"Value '' at 'name' failed to satisfy constraint: Member must have length greater than or equal to 1",
|
||||
"Value '' at 'name' failed to satisfy constraint: Member must satisfy regular expression pattern: (?!aws\\.)[A-Za-z0-9][\\.\\-_A-Za-z0-9]*");
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeEmptyEventSourceArnBreaksLengthThenPattern() {
|
||||
assertAnswers("DescribeEventSource", "{\"EventSourceArn\":\"\"}",
|
||||
"Value '' at 'eventSourceArn' failed to satisfy constraint: Member must have length greater than or equal to 1",
|
||||
"Value '' at 'eventSourceArn' failed to satisfy constraint: Member must satisfy regular expression pattern: " + DESCRIBE_ARN_PATTERN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void listEmptyNamePrefixBreaksLengthThenPattern() {
|
||||
assertAnswers("ListEventSources", "{\"NamePrefix\":\"\"}",
|
||||
"Value '' at 'namePrefix' failed to satisfy constraint: Member must satisfy regular expression pattern: (?!aws\\.)[A-Za-z0-9][\\.\\-_A-Za-z0-9]*",
|
||||
"Value '' at 'namePrefix' failed to satisfy constraint: Member must have length greater than or equal to 1");
|
||||
"Value '' at 'namePrefix' failed to satisfy constraint: Member must have length greater than or equal to 1",
|
||||
"Value '' at 'namePrefix' failed to satisfy constraint: Member must satisfy regular expression pattern: (?!aws\\.)[A-Za-z0-9][\\.\\-_A-Za-z0-9]*");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -492,29 +509,29 @@ class EventBridgeV2RequestShapesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void nameBreakingPatternAndLengthAnswersThePatternFirst() {
|
||||
void nameBreakingPatternAndLengthAnswersTheLengthFirst() {
|
||||
assertAnswers("CreateEventSource", "{\"Name\":\" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"EventBusArn\":\"arn:aws:events:u" +
|
||||
"s-east-1:123456789012:event-busv2/orders/abcdefghijklmnopqrstuvwxy\",\"Configuration\":{\"WebhookEventsC" +
|
||||
"onfiguration\":{\"RoleArn\":\"arn:aws:iam::123456789012:role/probe\",\"AuthConfiguration\":{\"BasicHttpAuthC" +
|
||||
"onfiguration\":{}}}}}",
|
||||
"Value ' aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' at 'name' failed to satisfy constraint: Member must satisfy regular expression pattern: (?!aws\\.)[A-Za-z0-9][\\.\\-_A-Za-z0-9]*",
|
||||
"Value ' aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' at 'name' failed to satisfy constraint: Member must have length less than or equal to 256");
|
||||
"Value ' aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' at 'name' failed to satisfy constraint: Member must have length less than or equal to 256",
|
||||
"Value ' aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' at 'name' failed to satisfy constraint: Member must satisfy regular expression pattern: (?!aws\\.)[A-Za-z0-9][\\.\\-_A-Za-z0-9]*");
|
||||
}
|
||||
|
||||
@Test
|
||||
void clientTokenBreakingPatternAndLengthAnswersThePatternFirst() {
|
||||
void clientTokenBreakingPatternAndLengthAnswersTheLengthFirst() {
|
||||
assertAnswers("CreateEventSource", "{\"Name\":\"n\",\"EventBusArn\":\"arn:aws:events:us-east-1:123456789012:event-busv2/orders/abcdefghijklmnop" +
|
||||
"qrstuvwxy\",\"Configuration\":{\"WebhookEventsConfiguration\":{\"RoleArn\":\"arn:aws:iam::123456789012:role/" +
|
||||
"probe\",\"AuthConfiguration\":{\"BasicHttpAuthConfiguration\":{}}}},\"ClientToken\":\" " +
|
||||
" \"}",
|
||||
"Value ' ' at 'clientToken' failed to satisfy constraint: Member must satisfy regular expression pattern: [\\u0021-\\u007E]+",
|
||||
"Value ' ' at 'clientToken' failed to satisfy constraint: Member must have length less than or equal to 64");
|
||||
"Value ' ' at 'clientToken' failed to satisfy constraint: Member must have length less than or equal to 64",
|
||||
"Value ' ' at 'clientToken' failed to satisfy constraint: Member must satisfy regular expression pattern: [\\u0021-\\u007E]+");
|
||||
}
|
||||
|
||||
@Test
|
||||
void tokenHeaderBreakingPatternAndLengthAnswersThePatternFirst() {
|
||||
void tokenHeaderBreakingPatternAndLengthAnswersTheLengthFirst() {
|
||||
assertAnswers("CreateEventSource", "{\"Name\":\"n\",\"EventBusArn\":\"arn:aws:events:us-east-1:123456789012:event-busv2/orders/abcdefghijklmnop" +
|
||||
"qrstuvwxy\",\"Configuration\":{\"WebhookEventsConfiguration\":{\"RoleArn\":\"arn:aws:iam::123456789012:role/" +
|
||||
"probe\",\"AuthConfiguration\":{\"StaticTokenAuthConfiguration\":{\"TokenHttpHeader\":\" " +
|
||||
@@ -523,8 +540,8 @@ class EventBridgeV2RequestShapesTest {
|
||||
" " +
|
||||
" " +
|
||||
" \"}}}}}",
|
||||
"Value ' ' at 'configuration.webhookEventsConfiguration.authConfiguration.staticTokenAuthConfiguration.tokenHttpHeader' failed to satisfy constraint: Member must satisfy regular expression pattern: [!#$%&'*+\\-.^_`|~0-9A-Za-z]+",
|
||||
"Value ' ' at 'configuration.webhookEventsConfiguration.authConfiguration.staticTokenAuthConfiguration.tokenHttpHeader' failed to satisfy constraint: Member must have length less than or equal to 512");
|
||||
"Value ' ' at 'configuration.webhookEventsConfiguration.authConfiguration.staticTokenAuthConfiguration.tokenHttpHeader' failed to satisfy constraint: Member must have length less than or equal to 512",
|
||||
"Value ' ' at 'configuration.webhookEventsConfiguration.authConfiguration.staticTokenAuthConfiguration.tokenHttpHeader' failed to satisfy constraint: Member must satisfy regular expression pattern: [!#$%&'*+\\-.^_`|~0-9A-Za-z]+");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -559,6 +576,9 @@ class EventBridgeV2RequestShapesTest {
|
||||
assertTrue(found.get(2).endsWith("' at 'tags' failed to satisfy constraint: " + "Map value must satisfy constraint: [Member must have length less than or equal to 256, Member must have length greater than or equal to 0, Member must satisfy regular expression pattern: (\\S([\\s\\S]*\\S)?)?(?![\\s\\S]).*, Member must not be null]"), found.get(2));
|
||||
}
|
||||
|
||||
private static final String DESCRIBE_ARN_PATTERN = "arn:aws(-[a-z0-9]+)*:events:[a-z][a-z0-9]*(-[a-z0-9]+)*:([0-9]{12}):"
|
||||
+ "event-sourcev2\\/(aws\\.service|aws\\.partner|webhook)\\/[A-Za-z0-9][\\.\\-_A-Za-z0-9]{0,255}\\/[a-z0-9]{25}";
|
||||
|
||||
private static final String ROTATE_ARN_PATTERN = "arn:aws(-[a-z0-9]+)*:events:[a-z][a-z0-9]*(-[a-z0-9]+)*:"
|
||||
+ "([0-9]{12}):event-sourcev2\\/webhook\\/[A-Za-z0-9][\\.\\-_A-Za-z0-9]{0,255}\\/[a-z0-9]{25}";
|
||||
|
||||
|
||||
+3
-3
@@ -73,10 +73,10 @@ class WebhookEventsConfigurationsTest {
|
||||
List<String> violations = violations("CreateEventSource", create("{\"Name\":\"-x\","
|
||||
+ "\"EventBusArn\":\"nope\",\"ClientToken\":\"\",\"Configuration\":{}}"));
|
||||
assertEquals(4, violations.size());
|
||||
assertTrue(violations.get(0).contains("at 'clientToken' failed to satisfy constraint: Member must satisfy "
|
||||
+ "regular expression pattern: [\\u0021-\\u007E]+"));
|
||||
assertEquals("Value '' at 'clientToken' failed to satisfy constraint: Member must have length greater than "
|
||||
+ "or equal to 1", violations.get(1));
|
||||
+ "or equal to 1", violations.get(0));
|
||||
assertTrue(violations.get(1).contains("at 'clientToken' failed to satisfy constraint: Member must satisfy "
|
||||
+ "regular expression pattern: [\\u0021-\\u007E]+"));
|
||||
assertTrue(violations.get(2).contains("at 'name'"));
|
||||
assertTrue(violations.get(3).contains("at 'eventBusArn' failed to satisfy constraint: Member must satisfy "
|
||||
+ "regular expression pattern: arn:aws(-[a-z0-9]+)*:events:"), violations.get(3));
|
||||
|
||||
Reference in new issue
Block a user