mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
chore(eventbridgev2): vendor event source request constraints (#9333)
This commit is contained in:
1 parent
85a63055be
commit
924040aaa1
8 files changed
+1321
-5
No files matched your search
@@ -0,0 +1,351 @@
|
||||
package io.floci.aws.core.common;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/** The collecting walk: every violation at once, worded as Smithy words them. */
|
||||
class RequestConstraintCheckViolationsTest {
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private static final String MODEL = """
|
||||
{"operations": {"Put": "PutInput", "Blobby": "BlobbyInput", "Listy": "ListyInput", "Mappy": "MappyInput",
|
||||
"Loop": "LoopInput", "Bounded": "BoundedInput"},
|
||||
"shapes": {
|
||||
"PutInput": {"type": "structure", "required": ["Name", "Inner"],
|
||||
"members": {"Name": "Name", "Inner": "Inner", "Kind": "Kind", "Count": "Count",
|
||||
"Ratio": "Ratio", "Flag": "Flag", "Secret": "Secret", "Wide": "Wide",
|
||||
"Tags": "Tags", "Names": "Names", "Pairs": "Pairs"}},
|
||||
"Inner": {"type": "structure", "required": ["Leaf"], "members": {"Leaf": "Name", "Other": "Name"}},
|
||||
"Name": {"type": "string", "min": 2, "max": 5, "pattern": "[a-z]+"},
|
||||
"Kind": {"type": "string", "enum": ["B", "A"]},
|
||||
"Count": {"type": "integer", "min": 1, "max": 900},
|
||||
"Wide": {"type": "long", "min": 1},
|
||||
"Ratio": {"type": "double", "min": 0, "max": 1},
|
||||
"Flag": {"type": "boolean"},
|
||||
"Secret": {"type": "string", "min": 6, "sensitive": true},
|
||||
"Tags": {"type": "map", "min": 0, "max": 2, "key": "TagKey", "value": "TagValue"},
|
||||
"TagKey": {"type": "string", "min": 1, "max": 3, "pattern": "[a-z]+"},
|
||||
"TagValue": {"type": "string", "min": 0, "max": 4, "pattern": "[a-z]*"},
|
||||
"Names": {"type": "list", "min": 1, "max": 2, "member": "Name"},
|
||||
"Pairs": {"type": "list", "member": "Flag"},
|
||||
"Longs": {"type": "list", "member": "Wide"},
|
||||
"BoundedInput": {"type": "structure", "members": {"Longs": "Longs"}},
|
||||
"BlobbyInput": {"type": "structure", "members": {"Data": "Data"}},
|
||||
"Data": {"type": "blob"},
|
||||
"ListyInput": {"type": "structure", "members": {"Items": "Items"}},
|
||||
"Items": {"type": "list", "member": "Inner"},
|
||||
"MappyInput": {"type": "structure", "members": {"Marks": "Marks"}},
|
||||
"Marks": {"type": "map", "key": "Name", "value": "Inner"},
|
||||
"LoopInput": {"type": "structure", "members": {"Self": "LoopInput", "Name": "Name"}}
|
||||
}}
|
||||
""";
|
||||
|
||||
private static final RequestConstraintCheck CHECK = RequestConstraintCheck.of(json(MODEL),
|
||||
RequestConstraintCheck.standardMessages("InvalidInputException"));
|
||||
|
||||
private static final String REQUIRED_OK = "\"Name\": \"abc\", \"Inner\": {\"Leaf\": \"abc\"}";
|
||||
|
||||
@Test
|
||||
void emptyRequestReportsEveryRequiredMemberInModelOrder() {
|
||||
assertEquals(List.of(
|
||||
"Value null at 'name' failed to satisfy constraint: Member must not be null",
|
||||
"Value null at 'inner' failed to satisfy constraint: Member must not be null"),
|
||||
CHECK.violations("Put", json("{}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullAndMissingRequestsAreEmptyStructures() {
|
||||
List<String> expected = CHECK.violations("Put", json("{}"));
|
||||
|
||||
assertEquals(expected, CHECK.violations("Put", null));
|
||||
assertEquals(expected, CHECK.violations("Put", json("null")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void jsonNullMemberIsAbsentAndUnknownMembersAreIgnored() {
|
||||
assertEquals(List.of("Value null at 'inner' failed to satisfy constraint: Member must not be null"),
|
||||
CHECK.violations("Put", json("{\"Name\": \"abc\", \"Inner\": null, \"Kind\": null, \"Extra\": 1}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nestedMemberPathLowerCasesEachFirstLetter() {
|
||||
assertEquals(List.of(
|
||||
"Value null at 'inner.leaf' failed to satisfy constraint: Member must not be null"),
|
||||
CHECK.violations("Put", json("{\"Name\": \"abc\", \"Inner\": {}}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void stringReportsLengthThenPatternThenEnumEachIndependently() {
|
||||
assertEquals(List.of(
|
||||
"Value 'A' at 'name' failed to satisfy constraint: Member must have length greater than or equal to 2",
|
||||
"Value 'A' at 'name' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-z]+"),
|
||||
CHECK.violations("Put", json("{\"Name\": \"A\", \"Inner\": {\"Leaf\": \"abc\"}}")));
|
||||
assertEquals(List.of(
|
||||
"Value 'abcdef' at 'name' failed to satisfy constraint: Member must have length less than or equal to 5"),
|
||||
CHECK.violations("Put", json("{\"Name\": \"abcdef\", \"Inner\": {\"Leaf\": \"abc\"}}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void stringLengthCountsCodePoints() {
|
||||
String sixEmoji = "\\ud83d\\ude00".repeat(6);
|
||||
|
||||
assertEquals(List.of(), CHECK.violations("Put",
|
||||
json("{" + REQUIRED_OK + ", \"Secret\": \"" + sixEmoji + "\"}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void enumValuesKeepTheVendoredOrder() {
|
||||
assertEquals(List.of(
|
||||
"Value 'C' at 'kind' failed to satisfy constraint: Member must satisfy enum value set: [B, A]"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Kind\": \"C\"}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sensitiveStringLeavesItsValueOut() {
|
||||
assertEquals(List.of(
|
||||
"Value at 'secret' failed to satisfy constraint: Member must have length greater than or equal to 6"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Secret\": \"abc\"}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void integerAboveMaxAndBelowMinAreRangeViolations() {
|
||||
assertEquals(List.of("Value '901' at 'count' failed to satisfy constraint: "
|
||||
+ "Member must have value less than or equal to 900"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Count\": 901}")));
|
||||
assertEquals(List.of("Value '0' at 'count' failed to satisfy constraint: "
|
||||
+ "Member must have value greater than or equal to 1"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Count\": 0}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void integerTooBigForLongIsStillARangeViolation() {
|
||||
assertEquals(List.of("Value '99999999999999999999' at 'count' failed to satisfy constraint: "
|
||||
+ "Member must have value less than or equal to 900"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Count\": 99999999999999999999}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void integerWithoutDeclaredBoundThatDoesNotFitTheTypeIsATypeError() {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Wide\": 99999999999999999999}")));
|
||||
|
||||
assertEquals("Invalid parameter at 'Wide' failed to satisfy constraint: 'Member must be a long'",
|
||||
error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fractionalNumberWhereIntegerIsModeledIsATypeError() {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Count\": 1.5}")));
|
||||
|
||||
assertEquals("Invalid parameter at 'Count' failed to satisfy constraint: 'Member must be a integer'",
|
||||
error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void doubleUsesTheNumbersTextAgainstItsBounds() {
|
||||
assertEquals(List.of("Value '1.5' at 'ratio' failed to satisfy constraint: "
|
||||
+ "Member must have value less than or equal to 1"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Ratio\": 1.5}")));
|
||||
assertEquals(List.of("Value '-0.5' at 'ratio' failed to satisfy constraint: "
|
||||
+ "Member must have value greater than or equal to 0"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Ratio\": -0.5}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void booleanChecksTheTypeOnly() {
|
||||
assertEquals(List.of(), CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Flag\": false}")));
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Flag\": \"yes\"}")));
|
||||
|
||||
assertEquals("Invalid parameter at 'Flag' failed to satisfy constraint: 'Member must be a boolean'",
|
||||
error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void wrongTypeThrowsAtOnceWithTheModelSpelledPath() {
|
||||
AwsException structure = assertThrows(AwsException.class,
|
||||
() -> CHECK.violations("Put", json("{\"Name\": \"abc\", \"Inner\": \"x\"}")));
|
||||
AwsException element = assertThrows(AwsException.class,
|
||||
() -> CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Names\": [\"abc\", 3]}")));
|
||||
AwsException root = assertThrows(AwsException.class, () -> CHECK.violations("Put", json("[]")));
|
||||
|
||||
assertEquals("Invalid parameter at 'Inner' failed to satisfy constraint: 'Member must be a structure'",
|
||||
structure.getMessage());
|
||||
assertEquals("Invalid parameter at 'Names' failed to satisfy constraint: 'Member must be a string'",
|
||||
element.getMessage());
|
||||
assertEquals("Invalid parameter at '' failed to satisfy constraint: 'Member must be a structure'",
|
||||
root.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listSizeViolationQuotesTheWholeListAndDropsNullAsText() {
|
||||
assertEquals(List.of("Value '[abc, abc, null]' at 'names' failed to satisfy constraint: "
|
||||
+ "Member must have length less than or equal to 2",
|
||||
"Value '[abc, abc, null]' at 'names' failed to satisfy constraint: "
|
||||
+ "Member must satisfy constraint: [Member must have length less than or equal to 5, "
|
||||
+ "Member must have length greater than or equal to 2, "
|
||||
+ "Member must satisfy regular expression pattern: [a-z]+, Member must not be null]"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Names\": [\"abc\", \"abc\", null]}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listBelowItsMinimumSizeIsReported() {
|
||||
assertEquals(List.of("Value '[]' at 'names' failed to satisfy constraint: "
|
||||
+ "Member must have length greater than or equal to 1"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Names\": []}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listMemberBreakingItsShapeIsOneViolationForTheWholeList() {
|
||||
assertEquals(List.of("Value '[ok, B]' at 'names' failed to satisfy constraint: "
|
||||
+ "Member must satisfy constraint: [Member must have length less than or equal to 5, "
|
||||
+ "Member must have length greater than or equal to 2, "
|
||||
+ "Member must satisfy regular expression pattern: [a-z]+, Member must not be null]"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Names\": [\"ok\", \"B\"]}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOfBooleansWithANullMemberHasOnlyTheNullRule() {
|
||||
assertEquals(List.of("Value '[true, null]' at 'pairs' failed to satisfy constraint: "
|
||||
+ "Member must satisfy constraint: [Member must not be null]"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Pairs\": [true, null]}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapSizeViolationQuotesTheWholeMapInRequestOrder() {
|
||||
assertEquals(List.of("Value '{b=x, a=y, c=z}' at 'tags' failed to satisfy constraint: "
|
||||
+ "Member must have length less than or equal to 2"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Tags\": {\"b\": \"x\", \"a\": \"y\", \"c\": \"z\"}}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapKeyThenValueViolationsAreOneEachAndOnlyValuesCarryNotNull() {
|
||||
assertEquals(List.of(
|
||||
"Value '{ k= v}' at 'tags' failed to satisfy constraint: Map keys must satisfy constraint: "
|
||||
+ "[Member must have length less than or equal to 3, "
|
||||
+ "Member must have length greater than or equal to 1, "
|
||||
+ "Member must satisfy regular expression pattern: [a-z]+]",
|
||||
"Value '{ k= v}' at 'tags' failed to satisfy constraint: Map value must satisfy constraint: "
|
||||
+ "[Member must have length less than or equal to 4, "
|
||||
+ "Member must have length greater than or equal to 0, "
|
||||
+ "Member must satisfy regular expression pattern: [a-z]*, Member must not be null]"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Tags\": {\" k\": \" v\"}}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapValueThatIsNullIsAValueViolation() {
|
||||
assertEquals(List.of(
|
||||
"Value '{k=null}' at 'tags' failed to satisfy constraint: Map value must satisfy constraint: "
|
||||
+ "[Member must have length less than or equal to 4, "
|
||||
+ "Member must have length greater than or equal to 0, "
|
||||
+ "Member must satisfy regular expression pattern: [a-z]*, Member must not be null]"),
|
||||
CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Tags\": {\"k\": null}}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapValueOfTheWrongTypeThrowsWithTheKeyInThePath() {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> CHECK.violations("Put", json("{" + REQUIRED_OK + ", \"Tags\": {\"k\": 1}}")));
|
||||
|
||||
assertEquals("Invalid parameter at 'Tags.k' failed to satisfy constraint: 'Member must be a string'",
|
||||
error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void everyViolationIsCollectedInMemberOrder() {
|
||||
List<String> found = CHECK.violations("Put",
|
||||
json("{\"Name\": \"A\", \"Kind\": \"C\", \"Count\": 0, \"Secret\": \"x\"}"));
|
||||
|
||||
assertEquals(List.of(
|
||||
"Value 'A' at 'name' failed to satisfy constraint: Member must have length greater than or equal to 2",
|
||||
"Value 'A' at 'name' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-z]+",
|
||||
"Value null at 'inner' failed to satisfy constraint: Member must not be null",
|
||||
"Value 'C' at 'kind' failed to satisfy constraint: Member must satisfy enum value set: [B, A]",
|
||||
"Value '0' at 'count' failed to satisfy constraint: Member must have value greater than or equal to 1",
|
||||
"Value at 'secret' failed to satisfy constraint: Member must have length greater than or equal to 6"),
|
||||
found);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownOperationIsRefused() {
|
||||
assertThrows(IllegalArgumentException.class, () -> CHECK.violations("Nope", json("{}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void operationHoldingABlobIsRefusedNamingTheMember() {
|
||||
IllegalStateException error = assertThrows(IllegalStateException.class,
|
||||
() -> CHECK.violations("Blobby", json("{}")));
|
||||
|
||||
assertEquals("Blobby's Data is a blob, which this check does not word yet", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOfStructuresIsRefused() {
|
||||
IllegalStateException error = assertThrows(IllegalStateException.class,
|
||||
() -> CHECK.violations("Listy", json("{}")));
|
||||
|
||||
assertEquals("Listy's Items[] is a structure, which this check does not word yet", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapWithStructureValuesIsRefused() {
|
||||
IllegalStateException error = assertThrows(IllegalStateException.class,
|
||||
() -> CHECK.violations("Mappy", json("{}")));
|
||||
|
||||
assertEquals("Mappy's Marks.value is a structure, which this check does not word yet", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOfBoundedNumbersIsRefused() {
|
||||
IllegalStateException error = assertThrows(IllegalStateException.class,
|
||||
() -> CHECK.violations("Bounded", json("{}")));
|
||||
assertEquals("Bounded's Longs[] is a long, which this check does not word yet", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOrMapHoldingASensitiveStringIsRefused() {
|
||||
RequestConstraintCheck check = RequestConstraintCheck.of(json("""
|
||||
{"operations": {"Listy": "ListyInput", "Mappy": "MappyInput"},
|
||||
"shapes": {
|
||||
"ListyInput": {"type": "structure", "members": {"Tokens": "Tokens"}},
|
||||
"Tokens": {"type": "list", "member": "Token"},
|
||||
"MappyInput": {"type": "structure", "members": {"Marks": "Marks"}},
|
||||
"Marks": {"type": "map", "key": "Plain", "value": "Token"},
|
||||
"Plain": {"type": "string"},
|
||||
"Token": {"type": "string", "sensitive": true}}}
|
||||
"""), RequestConstraintCheck.standardMessages("InvalidInputException"));
|
||||
|
||||
assertEquals("Listy's Tokens[] is a sensitive string, which this check does not word yet",
|
||||
assertThrows(IllegalStateException.class, () -> check.violations("Listy", json("{}"))).getMessage());
|
||||
assertEquals("Mappy's Marks.value is a sensitive string, which this check does not word yet",
|
||||
assertThrows(IllegalStateException.class, () -> check.violations("Mappy", json("{}"))).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shapeHoldingItselfIsWalkedOnce() {
|
||||
assertEquals(List.of(), CHECK.violations("Loop",
|
||||
json("{\"Name\": \"abc\", \"Self\": {\"Name\": \"abc\", \"Self\": {}}}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void refusalDoesNotAffectCheckOrOtherOperations() {
|
||||
CHECK.check("Blobby", json("{}"));
|
||||
assertEquals(List.of(), CHECK.violations("Put", json("{" + REQUIRED_OK + "}")));
|
||||
}
|
||||
|
||||
private static JsonNode json(String text) {
|
||||
try {
|
||||
return MAPPER.readTree(text);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
package io.floci.aws.services.eventbridgev2;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.core.common.RequestConstraintCheck;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/** The measured AWS answers for CreateEventSource, read through the vendored request shapes. */
|
||||
class EventBridgeV2RequestShapesTest {
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private static final RequestConstraintCheck CHECK = RequestConstraintCheck.load(
|
||||
"aws/eventbridgev2-request-shapes.json", "EventBridge V2 request shapes",
|
||||
RequestConstraintCheck.standardMessages("InvalidInputException"));
|
||||
|
||||
private static final String WEBHOOK = "configuration.webhookEventsConfiguration";
|
||||
|
||||
@Test
|
||||
void emptyRequestNamesEveryRequiredMember() {
|
||||
assertEquals(List.of(
|
||||
"Value null at 'name' failed to satisfy constraint: Member must not be null",
|
||||
"Value null at 'eventBusArn' failed to satisfy constraint: Member must not be null",
|
||||
"Value null at 'configuration' failed to satisfy constraint: Member must not be null"),
|
||||
CHECK.violations("CreateEventSource", MAPPER.createObjectNode()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void descriptionWithAControlCharacterBreaksItsPattern() {
|
||||
ObjectNode request = validRequest();
|
||||
request.put("Description", "a\u0001b");
|
||||
|
||||
assertEquals(List.of("Value 'a\u0001b' at 'description' failed to satisfy constraint: "
|
||||
+ "Member must satisfy regular expression pattern: "
|
||||
+ "[^\\u0000-\\u001F\\u007F-\\u009F\\u2028\\u2029]*(?![\\s\\S]).*"),
|
||||
CHECK.violations("CreateEventSource", request));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagsBreakingTheirKeyAndValueShapesAreTwoViolations() {
|
||||
ObjectNode request = validRequest();
|
||||
request.putObject("Tags").put(" k", " v");
|
||||
|
||||
assertEquals(List.of(
|
||||
"Value '{ k= v}' at 'tags' failed to satisfy constraint: Map keys 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: \\S([\\s\\S]*\\S)?(?![\\s\\S]).*]",
|
||||
"Value '{ k= v}' 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]"),
|
||||
CHECK.violations("CreateEventSource", request));
|
||||
}
|
||||
|
||||
@Test
|
||||
void moreThanTwoHundredTagsIsOneSizeViolation() {
|
||||
ObjectNode request = validRequest();
|
||||
ObjectNode tags = request.putObject("Tags");
|
||||
for (int i = 0; i < 201; i++) {
|
||||
tags.put("k" + i, "v");
|
||||
}
|
||||
|
||||
List<String> found = CHECK.violations("CreateEventSource", request);
|
||||
|
||||
assertEquals(1, found.size());
|
||||
assertTrue(found.get(0).endsWith("' at 'tags' failed to satisfy constraint: "
|
||||
+ "Member must have length less than or equal to 200"), found.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void logLevelOutsideItsEnumListsTheValuesSorted() {
|
||||
ObjectNode request = validRequest();
|
||||
webhook(request).putObject("LogConfiguration").put("Level", "DEBUG");
|
||||
|
||||
assertEquals(List.of("Value 'DEBUG' at '" + WEBHOOK + ".logConfiguration.level' failed to satisfy "
|
||||
+ "constraint: Member must satisfy enum value set: [ERROR, INFO, OFF]"),
|
||||
CHECK.violations("CreateEventSource", request));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shortSecretLeavesItsValueOut() {
|
||||
ObjectNode request = validRequest();
|
||||
ObjectNode token = auth(request).putObject("StaticTokenAuthConfiguration");
|
||||
token.put("TokenHttpHeader", "x-token");
|
||||
token.put("SecretValue", "abc");
|
||||
|
||||
assertEquals(List.of("Value at '" + WEBHOOK + ".authConfiguration.staticTokenAuthConfiguration.secretValue' "
|
||||
+ "failed to satisfy constraint: Member must have length greater than or equal to 6"),
|
||||
CHECK.violations("CreateEventSource", request));
|
||||
}
|
||||
|
||||
@Test
|
||||
void metadataHeaderBreakingItsShapeIsOneViolationForTheList() {
|
||||
ObjectNode request = validRequest();
|
||||
webhook(request).set("MetadataHttpHeaders", strings("ok", "bad header"));
|
||||
|
||||
assertEquals(List.of("Value '[ok, bad header]' at '" + WEBHOOK + ".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]"),
|
||||
CHECK.violations("CreateEventSource", request));
|
||||
}
|
||||
|
||||
@Test
|
||||
void twentyOneMetadataHeadersAreOneSizeViolation() {
|
||||
ObjectNode request = validRequest();
|
||||
String[] names = new String[21];
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
names[i] = "h" + (i + 1);
|
||||
}
|
||||
webhook(request).set("MetadataHttpHeaders", strings(names));
|
||||
|
||||
assertEquals(List.of("Value '[" + String.join(", ", names) + "]' at '" + WEBHOOK
|
||||
+ ".metadataHttpHeaders' failed to satisfy constraint: Member must have length less than or equal to 20"),
|
||||
CHECK.violations("CreateEventSource", request));
|
||||
}
|
||||
|
||||
@Test
|
||||
void timestampToleranceOutsideItsRangeIsReportedWithItsValue() {
|
||||
String path = WEBHOOK + ".authConfiguration.hmacAuthConfiguration.timestampToleranceInSeconds";
|
||||
for (int value : new int[] {901, 0}) {
|
||||
ObjectNode request = validRequest();
|
||||
ObjectNode hmac = auth(request).putObject("HmacAuthConfiguration");
|
||||
hmac.put("Algorithm", "SHA256");
|
||||
hmac.put("Encoding", "HEX");
|
||||
hmac.put("SignatureHttpHeader", "x-signature");
|
||||
hmac.put("SignedMessageComposition", "BODY");
|
||||
hmac.put("TimestampToleranceInSeconds", value);
|
||||
|
||||
String bound = value > 900
|
||||
? "less than or equal to 900"
|
||||
: "greater than or equal to 1";
|
||||
assertEquals(List.of("Value '" + value + "' at '" + path + "' failed to satisfy constraint: "
|
||||
+ "Member must have value " + bound), CHECK.violations("CreateEventSource", request));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void longNameStartingWithASpaceBreaksLengthThenPattern() {
|
||||
ObjectNode request = validRequest();
|
||||
String name = " " + "a".repeat(256);
|
||||
request.put("Name", name);
|
||||
|
||||
assertEquals(List.of(
|
||||
"Value '" + name + "' at 'name' failed to satisfy constraint: "
|
||||
+ "Member must have length less than or equal to 256",
|
||||
"Value '" + name + "' at 'name' failed to satisfy constraint: "
|
||||
+ "Member must satisfy regular expression pattern: (?!aws\\.)[A-Za-z0-9][\\.\\-_A-Za-z0-9]*"),
|
||||
CHECK.violations("CreateEventSource", request));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validRequestHasNoViolations() {
|
||||
assertEquals(List.of(), CHECK.violations("CreateEventSource", validRequest()));
|
||||
}
|
||||
|
||||
private static ObjectNode validRequest() {
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
request.put("Name", "source");
|
||||
request.put("EventBusArn", "arn:aws:events:us-east-1:123456789012:event-busv2/bus/abcdefghijklmnopqrstuvwxy");
|
||||
ObjectNode webhook = request.putObject("Configuration").putObject("WebhookEventsConfiguration");
|
||||
webhook.put("RoleArn", "arn:aws:iam::123456789012:role/role");
|
||||
webhook.putObject("AuthConfiguration");
|
||||
return request;
|
||||
}
|
||||
|
||||
private static ObjectNode webhook(ObjectNode request) {
|
||||
return (ObjectNode) request.path("Configuration").path("WebhookEventsConfiguration");
|
||||
}
|
||||
|
||||
private static ObjectNode auth(ObjectNode request) {
|
||||
return (ObjectNode) webhook(request).path("AuthConfiguration");
|
||||
}
|
||||
|
||||
private static JsonNode strings(String... values) {
|
||||
ArrayNode array = MAPPER.createArrayNode();
|
||||
for (String value : values) {
|
||||
array.add(value);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user