diff --git a/src/main/java/io/floci/aws/services/eventbridgev2/EventBridgeV2RequestShapes.java b/src/main/java/io/floci/aws/services/eventbridgev2/EventBridgeV2RequestShapes.java index 262cedba79..b0dfaf626d 100644 --- a/src/main/java/io/floci/aws/services/eventbridgev2/EventBridgeV2RequestShapes.java +++ b/src/main/java/io/floci/aws/services/eventbridgev2/EventBridgeV2RequestShapes.java @@ -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 violations = check.violations(operation, withoutWhsecPrefix(request)); + List violations = CHECK.violations(operation, withoutWhsecPrefix(request)); if (!violations.isEmpty()) { throw SmithyValidationErrors.exception("InvalidInputException", violations.subList(0, Math.min(violations.size(), MAX_VIOLATIONS))); diff --git a/src/test/java/io/floci/aws/services/eventbridgev2/EventBridgeV2RequestShapesTest.java b/src/test/java/io/floci/aws/services/eventbridgev2/EventBridgeV2RequestShapesTest.java index 4779dfe1cf..9fdb7a918a 100644 --- a/src/test/java/io/floci/aws/services/eventbridgev2/EventBridgeV2RequestShapesTest.java +++ b/src/test/java/io/floci/aws/services/eventbridgev2/EventBridgeV2RequestShapesTest.java @@ -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}"; diff --git a/src/test/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurationsTest.java b/src/test/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurationsTest.java index 54d2cd78e1..48188d35cf 100644 --- a/src/test/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurationsTest.java +++ b/src/test/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurationsTest.java @@ -73,10 +73,10 @@ class WebhookEventsConfigurationsTest { List 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));