mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(dynamodb): list every CreateTable constraint error in one message (#7974)
* fix(dynamodb): list every CreateTable constraint error in one message DynamoDB checks the members of a CreateTable request in a fixed order, whatever order the request gives them: GlobalSecondaryIndexes, BillingMode, SSESpecification, KeySchema, ProvisionedThroughput, StreamSpecification, AttributeDefinitions and LocalSecondaryIndexes. It lists every constraint error in one ValidationException and reports the first 10. An index name gets its length error before its pattern error. * fix(dynamodb): count null list members in CreateTable constraint positions DynamoDB skips a null list member in the CreateTable constraint checks, but it still counts it in the positions and in the list length. So [null] is not an empty list. A quoted NonKeyAttributes list shows the member as null. * fix(dynamodb): refuse an empty CreateTable KMSMasterKeyId DynamoDB refuses a KMSMasterKeyId outside 1 to 2048 characters, counted in code points, though the API reference gives no length for it. The billing mode and SSE type checks now print their enum sets from the same ordered lists as the CreateTable constraint checks.
This commit is contained in:
1 parent
3d3e94dcc6
commit
809c003614
5 files changed
+247
-14
No files matched your search
@@ -143,9 +143,10 @@ public class DynamoDbService {
|
||||
private static final int MAX_VECTOR_INDEXES_PER_TABLE = 5;
|
||||
private static final int MAX_VECTOR_DIMENSIONS = 4096;
|
||||
private static final int MIN_VECTOR_INDEX_NAME_LENGTH = 3;
|
||||
// The order AWS prints the enum constraint in.
|
||||
static final List<String> BILLING_MODES = List.of("PROVISIONED", "PAY_PER_REQUEST");
|
||||
// The order AWS prints the enum constraint in, which is neither alphabetical nor the order
|
||||
// the API reference lists.
|
||||
private static final Set<String> VALID_BILLING_MODES = Set.of("PROVISIONED", "PAY_PER_REQUEST");
|
||||
private static final List<String> VECTOR_DISTANCE_FUNCTIONS = List.of(
|
||||
DynamoDbVectorScoring.DOT_PRODUCT,
|
||||
DynamoDbVectorScoring.COSINE,
|
||||
@@ -5707,11 +5708,9 @@ public class DynamoDbService {
|
||||
*/
|
||||
static void validateBillingMode(JsonNode request, String memberPrefix) {
|
||||
JsonNode billingMode = request.path("BillingMode");
|
||||
if (billingMode.isTextual() && !VALID_BILLING_MODES.contains(billingMode.asText())) {
|
||||
throw SmithyValidationErrors.validationException(
|
||||
"Value '" + billingMode.asText() + "' at '" + memberPrefix
|
||||
+ "billingMode' failed to satisfy constraint: "
|
||||
+ "Member must satisfy enum value set: [PROVISIONED, PAY_PER_REQUEST]");
|
||||
if (billingMode.isTextual() && !BILLING_MODES.contains(billingMode.asText())) {
|
||||
throw SmithyValidationErrors.validationException(SmithyValidationErrors.notInEnum(
|
||||
billingMode.asText(), memberPrefix + "billingMode", BILLING_MODES));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -73,6 +74,12 @@ public class NativeDynamoDbJsonHandler {
|
||||
private static final List<String> CONTRIBUTOR_INSIGHTS_ACTIONS = List.of("ENABLE", "DISABLE");
|
||||
// The order AWS prints the enum constraint in.
|
||||
private static final List<String> CONTRIBUTOR_INSIGHTS_MODES = List.of("THROTTLED_KEYS", "ACCESSED_AND_THROTTLED_KEYS");
|
||||
// The orders AWS prints the enum constraints in.
|
||||
private static final List<String> KEY_TYPES = List.of("HASH", "RANGE");
|
||||
private static final List<String> STREAM_VIEW_TYPES =
|
||||
List.of("OLD_IMAGE", "KEYS_ONLY", "NEW_AND_OLD_IMAGES", "NEW_IMAGE");
|
||||
private static final List<String> ATTRIBUTE_TYPES = List.of("B", "N", "S");
|
||||
private static final List<String> PROJECTION_TYPES = List.of("ALL", "INCLUDE", "KEYS_ONLY");
|
||||
// The warm throughput a new on-demand table or index starts with.
|
||||
private static final long ON_DEMAND_WARM_READ_UNITS = 12000;
|
||||
private static final long ON_DEMAND_WARM_WRITE_UNITS = 4000;
|
||||
@@ -160,6 +167,8 @@ public class NativeDynamoDbJsonHandler {
|
||||
}
|
||||
|
||||
private Response handleCreateTable(JsonNode request, String region) {
|
||||
DynamoDbTableNames.requireShortName(textOrNull(request, "TableName"));
|
||||
throwValidationErrors(createTableViolations(request));
|
||||
TableDefinition table = createTableFromSpec(request, "", region, "ACTIVE");
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
@@ -2453,7 +2462,7 @@ public class NativeDynamoDbJsonHandler {
|
||||
for (JsonNode gsiOverride : gsiOverrides) {
|
||||
position++;
|
||||
String member = "globalSecondaryIndexOverride." + position + ".member";
|
||||
violations.addAll(restoreIndexNameViolations(gsiOverride.path("IndexName"), member + ".indexName"));
|
||||
violations.addAll(indexNameViolations(gsiOverride.path("IndexName"), member + ".indexName"));
|
||||
violations.addAll(throughputViolations(gsiOverride.path("ProvisionedThroughput"),
|
||||
member + ".provisionedThroughput"));
|
||||
}
|
||||
@@ -2461,6 +2470,119 @@ public class NativeDynamoDbJsonHandler {
|
||||
return violations;
|
||||
}
|
||||
|
||||
// DynamoDB lists the members in this order, whatever order the request gives them, and reports the first 10.
|
||||
private static List<String> createTableViolations(JsonNode request) {
|
||||
List<String> violations = new ArrayList<>();
|
||||
addIndexViolations(request.path("GlobalSecondaryIndexes"), "globalSecondaryIndexes", true, violations);
|
||||
addOlderEnumError(request, "BillingMode", "billingMode", DynamoDbService.BILLING_MODES, violations);
|
||||
JsonNode sse = request.path("SSESpecification");
|
||||
String kmsMasterKeyId = textOrNull(sse, "KMSMasterKeyId");
|
||||
if (kmsMasterKeyId != null) {
|
||||
addIfPresent(violations, SmithyValidationErrors.lengthOutOfRange(
|
||||
"sSESpecification.kMSMasterKeyId", kmsMasterKeyId, 1, 2048));
|
||||
}
|
||||
addOlderEnumError(sse, "SSEType", "sSESpecification.sSEType", NativeDynamoDbTableService.SSE_TYPES,
|
||||
violations);
|
||||
addKeySchemaViolations(request.path("KeySchema"), "keySchema", violations);
|
||||
violations.addAll(throughputViolations(request.path("ProvisionedThroughput"), "provisionedThroughput"));
|
||||
JsonNode stream = request.path("StreamSpecification");
|
||||
addOlderEnumError(stream, "StreamViewType", "streamSpecification.streamViewType", STREAM_VIEW_TYPES,
|
||||
violations);
|
||||
if (stream.isObject() && !stream.hasNonNull("StreamEnabled")) {
|
||||
violations.add(SmithyValidationErrors.notNull("streamSpecification.streamEnabled"));
|
||||
}
|
||||
forEachMember(request.path("AttributeDefinitions"), "attributeDefinitions", (definition, member) -> {
|
||||
addRequiredEnumError(definition, "AttributeType", member + ".attributeType", ATTRIBUTE_TYPES, violations);
|
||||
addAttributeNameError(definition, member + ".attributeName", violations);
|
||||
});
|
||||
addIndexViolations(request.path("LocalSecondaryIndexes"), "localSecondaryIndexes", false, violations);
|
||||
return violations.subList(0, Math.min(violations.size(), 10));
|
||||
}
|
||||
|
||||
// A local secondary index has no ProvisionedThroughput member, so DynamoDB ignores one there.
|
||||
private static void addIndexViolations(JsonNode indexes, String path, boolean global, List<String> violations) {
|
||||
forEachMember(indexes, path, (index, member) -> {
|
||||
violations.addAll(indexNameViolations(index.path("IndexName"), member + ".indexName"));
|
||||
if (index.hasNonNull("KeySchema")) {
|
||||
addKeySchemaViolations(index.get("KeySchema"), member + ".keySchema", violations);
|
||||
} else {
|
||||
violations.add(SmithyValidationErrors.notNull(member + ".keySchema"));
|
||||
}
|
||||
if (index.hasNonNull("Projection")) {
|
||||
addProjectionViolations(index.get("Projection"), member + ".projection", violations);
|
||||
} else {
|
||||
violations.add(SmithyValidationErrors.notNull(member + ".projection"));
|
||||
}
|
||||
if (global) {
|
||||
violations.addAll(throughputViolations(index.path("ProvisionedThroughput"),
|
||||
member + ".provisionedThroughput"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// A table key schema over two elements is refused later, with its own message.
|
||||
private static void addKeySchemaViolations(JsonNode keySchema, String path, List<String> violations) {
|
||||
if (!keySchema.isArray()) {
|
||||
return;
|
||||
}
|
||||
if (keySchema.isEmpty()) {
|
||||
violations.add(SmithyValidationErrors.lengthTooShort(path, "[]", 1));
|
||||
}
|
||||
forEachMember(keySchema, path, (element, member) -> {
|
||||
addAttributeNameError(element, member + ".attributeName", violations);
|
||||
addRequiredEnumError(element, "KeyType", member + ".keyType", KEY_TYPES, violations);
|
||||
});
|
||||
}
|
||||
|
||||
// DynamoDB quotes the whole NonKeyAttributes list in each of its errors.
|
||||
private static void addProjectionViolations(JsonNode projection, String path, List<String> violations) {
|
||||
JsonNode nonKeyAttributes = projection.path("NonKeyAttributes");
|
||||
if (nonKeyAttributes.isArray()) {
|
||||
List<String> names = new ArrayList<>();
|
||||
nonKeyAttributes.forEach(name -> names.add(name.isNull() ? null : name.asText()));
|
||||
String nonKeyPath = path + ".nonKeyAttributes";
|
||||
String value = names.toString();
|
||||
if (names.isEmpty()) {
|
||||
violations.add(SmithyValidationErrors.lengthTooShort(nonKeyPath, value, 1));
|
||||
} else if (20 < names.size()) {
|
||||
violations.add(SmithyValidationErrors.Violations.QUOTED.constraint(nonKeyPath, value,
|
||||
"Member must have length less than or equal to 20"));
|
||||
}
|
||||
if (names.stream().anyMatch(name -> name != null
|
||||
&& (name.isEmpty() || 255 < name.codePointCount(0, name.length())))) {
|
||||
violations.add(SmithyValidationErrors.Violations.QUOTED.constraint(nonKeyPath, value,
|
||||
"Member must satisfy constraint: " + SmithyValidationErrors.constraintSet(1, 255, null, null)));
|
||||
}
|
||||
}
|
||||
addOlderEnumError(projection, "ProjectionType", path + ".projectionType", PROJECTION_TYPES, violations);
|
||||
}
|
||||
|
||||
private static void addAttributeNameError(JsonNode node, String path, List<String> violations) {
|
||||
String name = textOrNull(node, "AttributeName");
|
||||
addIfPresent(violations, name == null
|
||||
? SmithyValidationErrors.notNull(path)
|
||||
: SmithyValidationErrors.lengthOutOfRange(path, name, 1, 255));
|
||||
}
|
||||
|
||||
private static void addRequiredEnumError(JsonNode node, String member, String path, List<String> allowed,
|
||||
List<String> violations) {
|
||||
if (node.hasNonNull(member)) {
|
||||
addOlderEnumError(node, member, path, allowed, violations);
|
||||
} else {
|
||||
violations.add(SmithyValidationErrors.notNull(path));
|
||||
}
|
||||
}
|
||||
|
||||
// DynamoDB skips a null member here, but still counts it in the positions and in the list length.
|
||||
private static void forEachMember(JsonNode list, String path, BiConsumer<JsonNode, String> check) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
JsonNode member = list.get(i);
|
||||
if (member != null && !member.isNull()) {
|
||||
check.accept(member, path + "." + (i + 1) + ".member");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static RestoreOverrides parseRestoreOverrides(JsonNode request) {
|
||||
JsonNode throughputNode = request.path("ProvisionedThroughputOverride");
|
||||
Throughput throughput = throughputNode.isObject()
|
||||
@@ -2557,8 +2679,8 @@ public class NativeDynamoDbJsonHandler {
|
||||
return violations;
|
||||
}
|
||||
|
||||
/** Unlike CreateTable, a restore lists the length violation of an index name before the pattern. */
|
||||
private static List<String> restoreIndexNameViolations(JsonNode indexName, String memberPath) {
|
||||
/** CreateTable and a restore list the length violation of an index name before the pattern. */
|
||||
private static List<String> indexNameViolations(JsonNode indexName, String memberPath) {
|
||||
String constraint = " at '" + memberPath + "' failed to satisfy constraint: ";
|
||||
if (indexName.isMissingNode() || indexName.isNull()) {
|
||||
return List.of(SmithyValidationErrors.notNull(memberPath));
|
||||
|
||||
@@ -38,7 +38,8 @@ public class NativeDynamoDbTableService {
|
||||
|
||||
private static final String DEFAULT_ACCOUNT_ID = "000000000000";
|
||||
private static final String SSE_TYPE_KMS = "KMS";
|
||||
private static final Set<String> VALID_SSE_TYPES = Set.of("AES256", "KMS");
|
||||
// The order AWS prints the enum constraint in.
|
||||
static final List<String> SSE_TYPES = List.of("AES256", "KMS");
|
||||
|
||||
// A null field or throughput record means "not specified in the request". Collections and the
|
||||
// settings record must not be null.
|
||||
@@ -651,11 +652,9 @@ public class NativeDynamoDbTableService {
|
||||
}
|
||||
|
||||
private static void validateSseType(String sseType) {
|
||||
if (!VALID_SSE_TYPES.contains(sseType)) {
|
||||
if (!SSE_TYPES.contains(sseType)) {
|
||||
throw SmithyValidationErrors.validationException(
|
||||
"Value '" + sseType
|
||||
+ "' at 'sSESpecification.sSEType' failed to satisfy constraint: "
|
||||
+ "Member must satisfy enum value set: [AES256, KMS]");
|
||||
SmithyValidationErrors.notInEnum(sseType, "sSESpecification.sSEType", SSE_TYPES));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -648,6 +648,56 @@ class DynamoDbIntegrationTest {
|
||||
+ "failed to satisfy constraint: Member must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTableListsTheGsiErrorsBeforeTheBillingModeAndLsiErrors() {
|
||||
assertIndexNameRejected("CreateTable", """
|
||||
{
|
||||
"TableName": "IndexNameListTable",
|
||||
"KeySchema": [
|
||||
{"AttributeName": "pk", "KeyType": "HASH"},
|
||||
{"AttributeName": "sk", "KeyType": "RANGE"}
|
||||
],
|
||||
"AttributeDefinitions": [
|
||||
{"AttributeName": "pk", "AttributeType": "S"},
|
||||
{"AttributeName": "sk", "AttributeType": "S"},
|
||||
{"AttributeName": "l", "AttributeType": "S"},
|
||||
{"AttributeName": "g", "AttributeType": "S"}
|
||||
],
|
||||
"LocalSecondaryIndexes": [{
|
||||
"IndexName": "aa",
|
||||
"KeySchema": [
|
||||
{"AttributeName": "pk", "KeyType": "HASH"},
|
||||
{"AttributeName": "l", "KeyType": "RANGE"}
|
||||
],
|
||||
"Projection": {"ProjectionType": "ALL"}
|
||||
}],
|
||||
"BillingMode": "BOGUS",
|
||||
"GlobalSecondaryIndexes": [
|
||||
{
|
||||
"IndexName": "zz",
|
||||
"KeySchema": [{"AttributeName": "g", "KeyType": "HASH"}],
|
||||
"Projection": {"ProjectionType": "ALL"}
|
||||
},
|
||||
{
|
||||
"IndexName": "g2",
|
||||
"KeySchema": [{"AttributeName": "g", "KeyType": "HASH"}],
|
||||
"Projection": {"ProjectionType": "BOGUS"}
|
||||
}
|
||||
]
|
||||
}
|
||||
""", "5 validation errors detected: "
|
||||
+ "Value 'zz' at 'globalSecondaryIndexes.1.member.indexName' failed to satisfy constraint: "
|
||||
+ "Member must have length greater than or equal to 3; "
|
||||
+ "Value 'g2' at 'globalSecondaryIndexes.2.member.indexName' failed to satisfy constraint: "
|
||||
+ "Member must have length greater than or equal to 3; "
|
||||
+ "Value 'BOGUS' at 'globalSecondaryIndexes.2.member.projection.projectionType' failed to satisfy "
|
||||
+ "constraint: Member must satisfy enum value set: [ALL, INCLUDE, KEYS_ONLY]; "
|
||||
+ "Value 'BOGUS' at 'billingMode' failed to satisfy constraint: "
|
||||
+ "Member must satisfy enum value set: [PROVISIONED, PAY_PER_REQUEST]; "
|
||||
+ "Value 'aa' at 'localSecondaryIndexes.1.member.indexName' failed to satisfy constraint: "
|
||||
+ "Member must have length greater than or equal to 3");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTableRejectsAnInvalidIndexNameBeforeTheTableLookup() {
|
||||
assertIndexNameRejected("UpdateTable", """
|
||||
|
||||
@@ -6,6 +6,7 @@ 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.AwsException;
|
||||
import io.floci.aws.core.common.SmithyValidationErrors;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.core.storage.PersistentStorage;
|
||||
import io.floci.aws.services.dynamodb.model.AttributeDefinition;
|
||||
@@ -731,6 +732,68 @@ class NativeDynamoDbJsonHandlerTest {
|
||||
return ex;
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', quoteCharacter = '`', textBlock = """
|
||||
{"LocalSecondaryIndexes":[{"IndexName":"l1","KeySchema":[{"AttributeName":"pk","KeyType":"HASH"}],"Projection":{}}],"GlobalSecondaryIndexes":[{"IndexName":"g1","KeySchema":[{"AttributeName":"g","KeyType":"HASH"}],"Projection":{}}]} | 2 validation errors detected: Value 'g1' at 'globalSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must have length greater than or equal to 3; Value 'l1' at 'localSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must have length greater than or equal to 3
|
||||
{"BillingMode":"BOGUS","AttributeDefinitions":[{"AttributeName":"pk","AttributeType":"X"}],"KeySchema":[{"AttributeName":"pk","KeyType":"BOGUS"}],"LocalSecondaryIndexes":[{"IndexName":"l1","KeySchema":[{"AttributeName":"pk","KeyType":"HASH"}],"Projection":{}}],"ProvisionedThroughput":{"ReadCapacityUnits":0,"WriteCapacityUnits":0},"StreamSpecification":{"StreamViewType":"BOGUS"},"SSESpecification":{"SSEType":"BOGUS"},"GlobalSecondaryIndexes":[{"IndexName":"g1","KeySchema":[{"AttributeName":"g","KeyType":"HASH"}],"Projection":{}}]} | 10 validation errors detected: Value 'g1' at 'globalSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must have length greater than or equal to 3; Value 'BOGUS' at 'billingMode' failed to satisfy constraint: Member must satisfy enum value set: [PROVISIONED, PAY_PER_REQUEST]; Value 'BOGUS' at 'sSESpecification.sSEType' failed to satisfy constraint: Member must satisfy enum value set: [AES256, KMS]; Value 'BOGUS' at 'keySchema.1.member.keyType' failed to satisfy constraint: Member must satisfy enum value set: [HASH, RANGE]; Value '0' at 'provisionedThroughput.writeCapacityUnits' failed to satisfy constraint: Member must have value greater than or equal to 1; Value '0' at 'provisionedThroughput.readCapacityUnits' failed to satisfy constraint: Member must have value greater than or equal to 1; Value 'BOGUS' at 'streamSpecification.streamViewType' failed to satisfy constraint: Member must satisfy enum value set: [OLD_IMAGE, KEYS_ONLY, NEW_AND_OLD_IMAGES, NEW_IMAGE]; Value null at 'streamSpecification.streamEnabled' failed to satisfy constraint: Member must not be null; Value 'X' at 'attributeDefinitions.1.member.attributeType' failed to satisfy constraint: Member must satisfy enum value set: [B, N, S]; Value 'l1' at 'localSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must have length greater than or equal to 3
|
||||
{"GlobalSecondaryIndexes":[{"IndexName":"a!","KeySchema":[{"AttributeName":"g","KeyType":"HASH"}],"Projection":{}}]} | 2 validation errors detected: Value 'a!' at 'globalSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must have length greater than or equal to 3; Value 'a!' at 'globalSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+
|
||||
{"GlobalSecondaryIndexes":[{"IndexName":"g1","KeySchema":[{"AttributeName":"g","KeyType":"BOGUS"}],"Projection":{"ProjectionType":"BOGUS","NonKeyAttributes":[]},"ProvisionedThroughput":{"ReadCapacityUnits":0,"WriteCapacityUnits":0}}]} | 6 validation errors detected: Value 'g1' at 'globalSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must have length greater than or equal to 3; Value 'BOGUS' at 'globalSecondaryIndexes.1.member.keySchema.1.member.keyType' failed to satisfy constraint: Member must satisfy enum value set: [HASH, RANGE]; Value '[]' at 'globalSecondaryIndexes.1.member.projection.nonKeyAttributes' failed to satisfy constraint: Member must have length greater than or equal to 1; Value 'BOGUS' at 'globalSecondaryIndexes.1.member.projection.projectionType' failed to satisfy constraint: Member must satisfy enum value set: [ALL, INCLUDE, KEYS_ONLY]; Value '0' at 'globalSecondaryIndexes.1.member.provisionedThroughput.writeCapacityUnits' failed to satisfy constraint: Member must have value greater than or equal to 1; Value '0' at 'globalSecondaryIndexes.1.member.provisionedThroughput.readCapacityUnits' failed to satisfy constraint: Member must have value greater than or equal to 1
|
||||
{"GlobalSecondaryIndexes":[{"IndexName":"g1","KeySchema":[{"AttributeName":"g","KeyType":"HASH"}],"Projection":{"ProjectionType":"INCLUDE","NonKeyAttributes":["","n0","n1","n2","n3","n4","n5","n6","n7","n8","n9","n10","n11","n12","n13","n14","n15","n16","n17","n18","n19"]}}]} | 3 validation errors detected: Value 'g1' at 'globalSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must have length greater than or equal to 3; Value '[, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18, n19]' at 'globalSecondaryIndexes.1.member.projection.nonKeyAttributes' failed to satisfy constraint: Member must have length less than or equal to 20; Value '[, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18, n19]' at 'globalSecondaryIndexes.1.member.projection.nonKeyAttributes' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 255, Member must have length greater than or equal to 1]
|
||||
{"GlobalSecondaryIndexes":[{}]} | 3 validation errors detected: Value null at 'globalSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must not be null; Value null at 'globalSecondaryIndexes.1.member.keySchema' failed to satisfy constraint: Member must not be null; Value null at 'globalSecondaryIndexes.1.member.projection' failed to satisfy constraint: Member must not be null
|
||||
{"KeySchema":[null],"GlobalSecondaryIndexes":[{"IndexName":"g1","KeySchema":[{"AttributeName":"g","KeyType":"HASH"}],"Projection":{"NonKeyAttributes":[null]}}]} | 1 validation error detected: Value 'g1' at 'globalSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must have length greater than or equal to 3
|
||||
{"KeySchema":[null,{"AttributeName":"","KeyType":"BOGUS"}],"GlobalSecondaryIndexes":[null,{"IndexName":"g1","KeySchema":[{"AttributeName":"g","KeyType":"HASH"}],"Projection":{"NonKeyAttributes":[null,""]}}]} | 4 validation errors detected: Value 'g1' at 'globalSecondaryIndexes.2.member.indexName' failed to satisfy constraint: Member must have length greater than or equal to 3; Value '[null, ]' at 'globalSecondaryIndexes.2.member.projection.nonKeyAttributes' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 255, Member must have length greater than or equal to 1]; Value '' at 'keySchema.2.member.attributeName' failed to satisfy constraint: Member must have length greater than or equal to 1; Value 'BOGUS' at 'keySchema.2.member.keyType' failed to satisfy constraint: Member must satisfy enum value set: [HASH, RANGE]
|
||||
{"KeySchema":[],"AttributeDefinitions":[null,{"AttributeName":"","AttributeType":"X"}]} | 3 validation errors detected: Value '[]' at 'keySchema' failed to satisfy constraint: Member must have length greater than or equal to 1; Value 'X' at 'attributeDefinitions.2.member.attributeType' failed to satisfy constraint: Member must satisfy enum value set: [B, N, S]; Value '' at 'attributeDefinitions.2.member.attributeName' failed to satisfy constraint: Member must have length greater than or equal to 1
|
||||
{"KeySchema":[{"AttributeName":"","KeyType":"BOGUS"}]} | 2 validation errors detected: Value '' at 'keySchema.1.member.attributeName' failed to satisfy constraint: Member must have length greater than or equal to 1; Value 'BOGUS' at 'keySchema.1.member.keyType' failed to satisfy constraint: Member must satisfy enum value set: [HASH, RANGE]
|
||||
{"AttributeDefinitions":[{"AttributeName":"","AttributeType":"X"}]} | 2 validation errors detected: Value 'X' at 'attributeDefinitions.1.member.attributeType' failed to satisfy constraint: Member must satisfy enum value set: [B, N, S]; Value '' at 'attributeDefinitions.1.member.attributeName' failed to satisfy constraint: Member must have length greater than or equal to 1
|
||||
{"LocalSecondaryIndexes":[{"IndexName":"l1","KeySchema":[{"AttributeName":"pk","KeyType":"HASH"}],"Projection":{},"ProvisionedThroughput":{"ReadCapacityUnits":0,"WriteCapacityUnits":0}}]} | 1 validation error detected: Value 'l1' at 'localSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must have length greater than or equal to 3
|
||||
""")
|
||||
void createTableListsItsConstraintErrorsInOrder(String members, String message) {
|
||||
ObjectNode request = (ObjectNode) json("""
|
||||
{"TableName":"Tbl","BillingMode":"PAY_PER_REQUEST","KeySchema":[{"AttributeName":"pk","KeyType":"HASH"}],
|
||||
"AttributeDefinitions":[{"AttributeName":"pk","AttributeType":"S"}]}
|
||||
""");
|
||||
request.setAll((ObjectNode) json(members));
|
||||
|
||||
assertEquals(message, expectValidationException("CreateTable", request).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTableReportsTheFirstTenConstraintErrors() {
|
||||
ObjectNode request = (ObjectNode) json("""
|
||||
{"TableName":"Tbl","KeySchema":[{"AttributeName":"pk","KeyType":"HASH"}]}
|
||||
""");
|
||||
ArrayNode indexes = request.putArray("GlobalSecondaryIndexes");
|
||||
List<String> violations = new ArrayList<>();
|
||||
for (int i = 1; i <= 11; i++) {
|
||||
String name = "g" + (char) ('a' + i);
|
||||
indexes.add(json("{\"IndexName\":\"" + name + "\",\"KeySchema\":[{\"AttributeName\":\"g\",\"KeyType\":\"HASH\"}],"
|
||||
+ "\"Projection\":{}}"));
|
||||
violations.add(SmithyValidationErrors.lengthTooShort(
|
||||
"globalSecondaryIndexes." + i + ".member.indexName", name, 3));
|
||||
}
|
||||
|
||||
assertEquals(SmithyValidationErrors.message(violations.subList(0, 10)),
|
||||
expectValidationException("CreateTable", request).getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', quoteCharacter = '`', textBlock = """
|
||||
k | 0 | 2 validation errors detected: Value 'BOGUS' at 'billingMode' failed to satisfy constraint: Member must satisfy enum value set: [PROVISIONED, PAY_PER_REQUEST]; Value '%s' at 'sSESpecification.kMSMasterKeyId' failed to satisfy constraint: Member must have length greater than or equal to 1
|
||||
k | 2048 | 1 validation error detected: Value 'BOGUS' at 'billingMode' failed to satisfy constraint: Member must satisfy enum value set: [PROVISIONED, PAY_PER_REQUEST]
|
||||
k | 2049 | 2 validation errors detected: Value 'BOGUS' at 'billingMode' failed to satisfy constraint: Member must satisfy enum value set: [PROVISIONED, PAY_PER_REQUEST]; Value '%s' at 'sSESpecification.kMSMasterKeyId' failed to satisfy constraint: Member must have length less than or equal to 2048
|
||||
😀 | 1025 | 1 validation error detected: Value 'BOGUS' at 'billingMode' failed to satisfy constraint: Member must satisfy enum value set: [PROVISIONED, PAY_PER_REQUEST]
|
||||
""")
|
||||
void createTableChecksTheKmsMasterKeyIdLength(String character, int count, String message) {
|
||||
String key = character.repeat(count);
|
||||
ObjectNode request = (ObjectNode) json("""
|
||||
{"TableName":"Tbl","BillingMode":"BOGUS","KeySchema":[{"AttributeName":"pk","KeyType":"HASH"}],
|
||||
"AttributeDefinitions":[{"AttributeName":"pk","AttributeType":"S"}]}
|
||||
""");
|
||||
request.putObject("SSESpecification").put("Enabled", true).put("SSEType", "KMS").put("KMSMasterKeyId", key);
|
||||
|
||||
assertEquals(message.formatted(key), expectValidationException("CreateTable", request).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTableRejectsProvisionedThroughputWithPayPerRequest() {
|
||||
AwsException ex = expectValidationException("CreateTable", json("""
|
||||
|
||||
Reference in new issue
Block a user