fix(dynamodb): refuse a null or omitted required SearchVectors member (#8044)

This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-11 17:55:09 -04:00
1 parent d8978fddf4
commit 3b4cae7387
10 files changed
+543 -30

No files matched your search

@@ -177,7 +177,7 @@ public class AwsJsonController {
if (targetMatch.jsonOnly()) {
yield dynamoDbJsonHandler.handleLegacy(action, request, region);
}
DynamoDbRequestShapes.check(action, request);
DynamoDbRequestShapes.check(action, request, body);
yield dynamoDbJsonHandler.handle(action, request, region);
}
case "sqs" -> sqsJsonHandler.handle(action, request, region);
@@ -1,11 +1,22 @@
package io.floci.aws.services.dynamodb;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JsonNode;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.RequestShapeCheck;
import io.floci.aws.core.common.RequestShapeCheck.ByPosition;
import io.floci.aws.core.common.RequestShapeModel;
import io.floci.aws.core.common.RequestShapeModel.Shape;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
/**
* Rejects a DynamoDB request member of the wrong JSON type with the SerializationException
@@ -20,6 +31,11 @@ public final class DynamoDbRequestShapes {
static final String RESOURCE_NAME = "aws/dynamodb-request-shapes.json";
private static final String UNKNOWN_ERROR = "UnknownError";
private static final String SEARCH_VECTORS = "SearchVectors";
// How the SearchVectors frontend names the type a null required member should have had.
private static final Map<String, String> SEARCH_VECTORS_TYPE_NAMES = Map.of(
"string", "a string", "list", "a sequence", "integer", "i32");
private static final JsonFactory JSON = new JsonFactory();
private static final ByPosition SCALAR_FOR_CONTAINER = new ByPosition("Unexpected field type", UNKNOWN_ERROR);
private static final RequestShapeCheck.Messages MESSAGES = new RequestShapeCheck.Messages(
@@ -53,4 +69,75 @@ public final class DynamoDbRequestShapes {
RequestShapeCheck.check(model, input, request, MESSAGES);
}
}
/**
* As {@link #check(String, JsonNode)}, given the body as sent. SearchVectors has its own frontend,
* which also refuses a null or omitted required member and names the line and byte column where
* it stopped reading.
*/
public static void check(String action, JsonNode request, String body) {
if (SEARCH_VECTORS.equals(action) && !hasSearchVectorsMembers(Holder.MODEL, request)) {
readSearchVectors(Holder.MODEL, request, body == null ? "" : body, true);
} else {
check(action, request);
}
}
/**
* Refuses a null or omitted required SearchVectors member of a request that reached the operation
* without a JSON body, from AppSync, Step Functions or CBOR. The positions are those of the compact
* JSON an SDK sends.
*/
public static void requireSearchVectorsMembers(JsonNode request) {
if (!hasSearchVectorsMembers(Holder.MODEL, request)) {
readSearchVectors(Holder.MODEL, request, request.toString(), false);
}
}
private static boolean hasSearchVectorsMembers(RequestShapeModel model, JsonNode request) {
return searchVectorsInput(model).required().stream().allMatch(request::hasNonNull);
}
private static Shape searchVectorsInput(RequestShapeModel model) {
return model.shapes().get(model.operations().get(SEARCH_VECTORS));
}
/** Reads {@code body} in order, checking each member's JSON type as well when {@code memberTypes}. */
private static void readSearchVectors(RequestShapeModel model, JsonNode request, String body,
boolean memberTypes) {
if (body.isBlank()) {
throw new AwsException("ValidationException", "EOF while parsing a value at line "
+ (body.chars().filter(c -> c == '\n').count() + 1)
+ " column " + (body.length() - body.lastIndexOf('\n') - 1), 400);
}
Shape input = searchVectorsInput(model);
try (JsonParser parser = JSON.createParser(body.getBytes(StandardCharsets.UTF_8))) {
parser.nextToken();
while (parser.nextToken() == JsonToken.FIELD_NAME) {
String name = parser.currentName();
String memberShape = input.members().get(name);
if (parser.nextToken() == JsonToken.VALUE_NULL && input.required().contains(name)) {
throw new AwsException("SerializationException", "invalid type: null, expected "
+ SEARCH_VECTORS_TYPE_NAMES.get(model.shapes().get(memberShape).type())
+ " at " + position(parser.currentTokenLocation(), "null".length() - 1), 400);
}
parser.skipChildren();
if (memberTypes && memberShape != null) {
RequestShapeCheck.check(model, memberShape, request.get(name), MESSAGES);
}
}
for (String member : new TreeSet<>(input.required())) {
if (!request.has(member)) {
throw new AwsException("ValidationException", "missing field `" + member + "` at "
+ position(parser.currentTokenLocation(), 0), 400);
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
private static String position(JsonLocation location, int columnOffset) {
return "line " + location.getLineNr() + " column " + (location.getColumnNr() + columnOffset);
}
}
@@ -1617,8 +1617,7 @@ public class NativeDynamoDbJsonHandler {
private static final int MAX_VECTOR_SEARCH_TOP_K = 100;
private Response handleSearchVectors(JsonNode request, String region) {
requireSearchVectorsMember(request, "SearchVector");
requireSearchVectorsMember(request, "IndexName");
DynamoDbRequestShapes.requireSearchVectorsMembers(request);
String tableName = request.path("TableName").asText();
String indexName = request.get("IndexName").asText();
String rccSearchError = returnConsumedCapacityError(request);
@@ -1627,7 +1626,6 @@ public class NativeDynamoDbJsonHandler {
throw new AwsException("ValidationException", rccSearchError, 400);
}
String rccSearch = request.path("ReturnConsumedCapacity").asText("NONE");
requireSearchVectorsMember(request, "TopK");
int topK = request.get("TopK").asInt();
if (topK < 1) {
// AWS names this member TopK and quotes no value, unlike every other member of this
@@ -1676,19 +1674,6 @@ public class NativeDynamoDbJsonHandler {
return Response.ok(response).build();
}
/**
* Rejects an omitted required member of SearchVectors the way the AWS frontend does: as a
* deserialisation failure quoting the offset of the body's closing brace, which for the
* compact JSON an SDK sends is the body length. Measured in eu-west-2, 2026-09-23.
*/
private static void requireSearchVectorsMember(JsonNode request, String member) {
if (!request.hasNonNull(member)) {
throw new AwsException("ValidationException",
"missing field `" + member + "` at line 1 column "
+ request.toString().length(), 400);
}
}
/**
* The vector index a search may run against.
*
@@ -1,7 +1,7 @@
{
"_source": {
"generator": "tools/aws/regen_dynamodb_shapes.py",
"botocore": "botocore 1.43.118 (local/aws/botocore)"
"botocore": "botocore 1.43.118 (installed package)"
},
"operations": {
"BatchExecuteStatement": "BatchExecuteStatementInput",
@@ -72,6 +72,10 @@
},
"AttributeDefinition": {
"type": "structure",
"required": [
"AttributeName",
"AttributeType"
],
"members": {
"AttributeName": "KeySchemaAttributeName",
"AttributeType": "ScalarAttributeType"
@@ -123,6 +127,9 @@
},
"AutoScalingPolicyUpdate": {
"type": "structure",
"required": [
"TargetTrackingScalingPolicyConfiguration"
],
"members": {
"PolicyName": "AutoScalingPolicyName",
"TargetTrackingScalingPolicyConfiguration": "AutoScalingTargetTrackingScalingPolicyConfigurationUpdate"
@@ -143,6 +150,9 @@
},
"AutoScalingTargetTrackingScalingPolicyConfigurationUpdate": {
"type": "structure",
"required": [
"TargetValue"
],
"members": {
"DisableScaleIn": "BooleanObject",
"ScaleInCooldown": "IntegerObject",
@@ -164,6 +174,9 @@
},
"BatchExecuteStatementInput": {
"type": "structure",
"required": [
"Statements"
],
"members": {
"Statements": "PartiQLBatchRequest",
"ReturnConsumedCapacity": "ReturnConsumedCapacity"
@@ -171,6 +184,9 @@
},
"BatchGetItemInput": {
"type": "structure",
"required": [
"RequestItems"
],
"members": {
"RequestItems": "BatchGetRequestMap",
"ReturnConsumedCapacity": "ReturnConsumedCapacity"
@@ -182,6 +198,9 @@
},
"BatchStatementRequest": {
"type": "structure",
"required": [
"Statement"
],
"members": {
"Statement": "PartiQLStatement",
"Parameters": "PreparedStatementParameters",
@@ -191,6 +210,9 @@
},
"BatchWriteItemInput": {
"type": "structure",
"required": [
"RequestItems"
],
"members": {
"RequestItems": "BatchWriteItemRequestMap",
"ReturnConsumedCapacity": "ReturnConsumedCapacity",
@@ -228,6 +250,9 @@
},
"Condition": {
"type": "structure",
"required": [
"ComparisonOperator"
],
"members": {
"AttributeValueList": "AttributeValueList",
"ComparisonOperator": "ComparisonOperator"
@@ -235,6 +260,11 @@
},
"ConditionCheck": {
"type": "structure",
"required": [
"Key",
"TableName",
"ConditionExpression"
],
"members": {
"Key": "Key",
"TableName": "TableArn",
@@ -264,6 +294,10 @@
},
"CreateBackupInput": {
"type": "structure",
"required": [
"TableName",
"BackupName"
],
"members": {
"TableName": "TableArn",
"BackupName": "BackupName"
@@ -271,6 +305,11 @@
},
"CreateGlobalSecondaryIndexAction": {
"type": "structure",
"required": [
"IndexName",
"KeySchema",
"Projection"
],
"members": {
"IndexName": "IndexName",
"KeySchema": "KeySchema",
@@ -282,6 +321,10 @@
},
"CreateGlobalTableInput": {
"type": "structure",
"required": [
"GlobalTableName",
"ReplicationGroup"
],
"members": {
"GlobalTableName": "TableName",
"ReplicationGroup": "ReplicaList"
@@ -289,18 +332,27 @@
},
"CreateGlobalTableWitnessGroupMemberAction": {
"type": "structure",
"required": [
"RegionName"
],
"members": {
"RegionName": "RegionName"
}
},
"CreateReplicaAction": {
"type": "structure",
"required": [
"RegionName"
],
"members": {
"RegionName": "RegionName"
}
},
"CreateReplicationGroupMemberAction": {
"type": "structure",
"required": [
"RegionName"
],
"members": {
"RegionName": "RegionName",
"KMSMasterKeyId": "KMSMasterKeyId",
@@ -312,6 +364,9 @@
},
"CreateTableInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"AttributeDefinitions": "AttributeDefinitions",
"TableName": "TableArn",
@@ -335,6 +390,13 @@
},
"CreateVectorIndexAction": {
"type": "structure",
"required": [
"IndexName",
"VectorAttribute",
"Projection",
"Dimensions",
"DistanceFunction"
],
"members": {
"IndexName": "IndexName",
"VectorAttribute": "VectorAttributeDefinition",
@@ -366,6 +428,10 @@
},
"Delete": {
"type": "structure",
"required": [
"Key",
"TableName"
],
"members": {
"Key": "Key",
"TableName": "TableArn",
@@ -377,24 +443,37 @@
},
"DeleteBackupInput": {
"type": "structure",
"required": [
"BackupArn"
],
"members": {
"BackupArn": "BackupArn"
}
},
"DeleteGlobalSecondaryIndexAction": {
"type": "structure",
"required": [
"IndexName"
],
"members": {
"IndexName": "IndexName"
}
},
"DeleteGlobalTableWitnessGroupMemberAction": {
"type": "structure",
"required": [
"RegionName"
],
"members": {
"RegionName": "RegionName"
}
},
"DeleteItemInput": {
"type": "structure",
"required": [
"TableName",
"Key"
],
"members": {
"TableName": "TableArn",
"Key": "Key",
@@ -411,24 +490,36 @@
},
"DeleteReplicaAction": {
"type": "structure",
"required": [
"RegionName"
],
"members": {
"RegionName": "RegionName"
}
},
"DeleteReplicationGroupMemberAction": {
"type": "structure",
"required": [
"RegionName"
],
"members": {
"RegionName": "RegionName"
}
},
"DeleteRequest": {
"type": "structure",
"required": [
"Key"
],
"members": {
"Key": "Key"
}
},
"DeleteResourcePolicyInput": {
"type": "structure",
"required": [
"ResourceArn"
],
"members": {
"ResourceArn": "ResourceArnString",
"ExpectedRevisionId": "PolicyRevisionId"
@@ -436,12 +527,18 @@
},
"DeleteTableInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"TableName": "TableArn"
}
},
"DeleteVectorIndexAction": {
"type": "structure",
"required": [
"IndexName"
],
"members": {
"IndexName": "IndexName"
}
@@ -451,18 +548,27 @@
},
"DescribeBackupInput": {
"type": "structure",
"required": [
"BackupArn"
],
"members": {
"BackupArn": "BackupArn"
}
},
"DescribeContinuousBackupsInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"TableName": "TableArn"
}
},
"DescribeContributorInsightsInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"TableName": "TableArn",
"IndexName": "IndexName"
@@ -474,30 +580,45 @@
},
"DescribeExportInput": {
"type": "structure",
"required": [
"ExportArn"
],
"members": {
"ExportArn": "ExportArn"
}
},
"DescribeGlobalTableInput": {
"type": "structure",
"required": [
"GlobalTableName"
],
"members": {
"GlobalTableName": "TableName"
}
},
"DescribeGlobalTableSettingsInput": {
"type": "structure",
"required": [
"GlobalTableName"
],
"members": {
"GlobalTableName": "TableName"
}
},
"DescribeImportInput": {
"type": "structure",
"required": [
"ImportArn"
],
"members": {
"ImportArn": "ImportArn"
}
},
"DescribeKinesisStreamingDestinationInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"TableName": "TableArn"
}
@@ -508,24 +629,37 @@
},
"DescribeTableInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"TableName": "TableArn"
}
},
"DescribeTableReplicaAutoScalingInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"TableName": "TableArn"
}
},
"DescribeTimeToLiveInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"TableName": "TableArn"
}
},
"DisassociateReplicationGroupMemberAction": {
"type": "structure",
"required": [
"RegionName",
"DisassociationMode"
],
"members": {
"RegionName": "RegionName",
"DisassociationMode": "DisassociationMode"
@@ -548,6 +682,9 @@
},
"ExecuteStatementInput": {
"type": "structure",
"required": [
"Statement"
],
"members": {
"Statement": "PartiQLStatement",
"Parameters": "PreparedStatementParameters",
@@ -560,6 +697,9 @@
},
"ExecuteTransactionInput": {
"type": "structure",
"required": [
"TransactStatements"
],
"members": {
"TransactStatements": "ParameterizedStatements",
"ClientRequestToken": "ClientRequestToken",
@@ -593,6 +733,10 @@
},
"ExportTableToPointInTimeInput": {
"type": "structure",
"required": [
"TableArn",
"S3Bucket"
],
"members": {
"TableArn": "TableArn",
"ExportTime": "ExportTime",
@@ -644,6 +788,10 @@
},
"Get": {
"type": "structure",
"required": [
"Key",
"TableName"
],
"members": {
"Key": "Key",
"TableName": "TableArn",
@@ -653,6 +801,10 @@
},
"GetItemInput": {
"type": "structure",
"required": [
"TableName",
"Key"
],
"members": {
"TableName": "TableArn",
"Key": "Key",
@@ -665,12 +817,20 @@
},
"GetResourcePolicyInput": {
"type": "structure",
"required": [
"ResourceArn"
],
"members": {
"ResourceArn": "ResourceArnString"
}
},
"GlobalSecondaryIndex": {
"type": "structure",
"required": [
"IndexName",
"KeySchema",
"Projection"
],
"members": {
"IndexName": "IndexName",
"KeySchema": "KeySchema",
@@ -709,6 +869,9 @@
},
"GlobalTableGlobalSecondaryIndexSettingsUpdate": {
"type": "structure",
"required": [
"IndexName"
],
"members": {
"IndexName": "IndexName",
"ProvisionedWriteCapacityUnits": "PositiveLongObject",
@@ -741,6 +904,11 @@
},
"ImportTableInput": {
"type": "structure",
"required": [
"S3BucketSource",
"InputFormat",
"TableCreationParameters"
],
"members": {
"ClientToken": "ClientToken",
"S3BucketSource": "S3BucketSource",
@@ -803,6 +971,10 @@
},
"KeySchemaElement": {
"type": "structure",
"required": [
"AttributeName",
"KeyType"
],
"members": {
"AttributeName": "KeySchemaAttributeName",
"KeyType": "KeyType"
@@ -813,6 +985,9 @@
},
"KeysAndAttributes": {
"type": "structure",
"required": [
"Keys"
],
"members": {
"Keys": "KeyList",
"AttributesToGet": "AttributeNameList",
@@ -823,6 +998,10 @@
},
"KinesisStreamingDestinationInput": {
"type": "structure",
"required": [
"TableName",
"StreamArn"
],
"members": {
"TableName": "TableArn",
"StreamArn": "StreamArn",
@@ -897,6 +1076,9 @@
},
"ListTagsOfResourceInput": {
"type": "structure",
"required": [
"ResourceArn"
],
"members": {
"ResourceArn": "ResourceArnString",
"NextToken": "NextTokenString"
@@ -904,6 +1086,11 @@
},
"LocalSecondaryIndex": {
"type": "structure",
"required": [
"IndexName",
"KeySchema",
"Projection"
],
"members": {
"IndexName": "IndexName",
"KeySchema": "KeySchema",
@@ -959,6 +1146,9 @@
},
"ParameterizedStatement": {
"type": "structure",
"required": [
"Statement"
],
"members": {
"Statement": "PartiQLStatement",
"Parameters": "PreparedStatementParameters",
@@ -981,6 +1171,9 @@
},
"PointInTimeRecoverySpecification": {
"type": "structure",
"required": [
"PointInTimeRecoveryEnabled"
],
"members": {
"PointInTimeRecoveryEnabled": "BooleanObject",
"RecoveryPeriodInDays": "RecoveryPeriodInDays"
@@ -1014,6 +1207,10 @@
},
"ProvisionedThroughput": {
"type": "structure",
"required": [
"ReadCapacityUnits",
"WriteCapacityUnits"
],
"members": {
"ReadCapacityUnits": "PositiveLongObject",
"WriteCapacityUnits": "PositiveLongObject"
@@ -1027,6 +1224,10 @@
},
"Put": {
"type": "structure",
"required": [
"Item",
"TableName"
],
"members": {
"Item": "PutItemInputAttributeMap",
"TableName": "TableArn",
@@ -1038,6 +1239,10 @@
},
"PutItemInput": {
"type": "structure",
"required": [
"TableName",
"Item"
],
"members": {
"TableName": "TableArn",
"Item": "PutItemInputAttributeMap",
@@ -1058,12 +1263,19 @@
},
"PutRequest": {
"type": "structure",
"required": [
"Item"
],
"members": {
"Item": "PutItemInputAttributeMap"
}
},
"PutResourcePolicyInput": {
"type": "structure",
"required": [
"ResourceArn",
"Policy"
],
"members": {
"ResourceArn": "ResourceArnString",
"Policy": "ResourcePolicy",
@@ -1073,6 +1285,9 @@
},
"QueryInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"TableName": "TableArn",
"IndexName": "IndexName",
@@ -1107,6 +1322,9 @@
},
"ReplicaAutoScalingUpdate": {
"type": "structure",
"required": [
"RegionName"
],
"members": {
"RegionName": "RegionName",
"ReplicaGlobalSecondaryIndexUpdates": "ReplicaGlobalSecondaryIndexAutoScalingUpdateList",
@@ -1119,6 +1337,9 @@
},
"ReplicaGlobalSecondaryIndex": {
"type": "structure",
"required": [
"IndexName"
],
"members": {
"IndexName": "IndexName",
"ProvisionedThroughputOverride": "ProvisionedThroughputOverride",
@@ -1142,6 +1363,9 @@
},
"ReplicaGlobalSecondaryIndexSettingsUpdate": {
"type": "structure",
"required": [
"IndexName"
],
"members": {
"IndexName": "IndexName",
"ProvisionedReadCapacityUnits": "PositiveLongObject",
@@ -1158,6 +1382,9 @@
},
"ReplicaSettingsUpdate": {
"type": "structure",
"required": [
"RegionName"
],
"members": {
"RegionName": "RegionName",
"ReplicaProvisionedReadCapacityUnits": "PositiveLongObject",
@@ -1202,6 +1429,10 @@
},
"RestoreTableFromBackupInput": {
"type": "structure",
"required": [
"TargetTableName",
"BackupArn"
],
"members": {
"TargetTableName": "TableName",
"BackupArn": "BackupArn",
@@ -1216,6 +1447,9 @@
},
"RestoreTableToPointInTimeInput": {
"type": "structure",
"required": [
"TargetTableName"
],
"members": {
"SourceTableArn": "TableArn",
"SourceTableName": "TableName",
@@ -1251,6 +1485,9 @@
},
"S3BucketSource": {
"type": "structure",
"required": [
"S3Bucket"
],
"members": {
"S3BucketOwner": "S3BucketOwner",
"S3Bucket": "S3Bucket",
@@ -1285,6 +1522,9 @@
},
"ScanInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"TableName": "TableArn",
"IndexName": "IndexName",
@@ -1316,6 +1556,10 @@
},
"SearchSchemaElement": {
"type": "structure",
"required": [
"AttributeName",
"SearchSchemaElementType"
],
"members": {
"AttributeName": "AttributeName",
"SearchSchemaElementType": "SearchSchemaElementType"
@@ -1330,6 +1574,12 @@
},
"SearchVectorsInput": {
"type": "structure",
"required": [
"TableName",
"IndexName",
"SearchVector",
"TopK"
],
"members": {
"TableName": "TableArn",
"IndexName": "IndexName",
@@ -1353,6 +1603,9 @@
},
"StreamSpecification": {
"type": "structure",
"required": [
"StreamEnabled"
],
"members": {
"StreamEnabled": "StreamEnabled",
"StreamViewType": "StreamViewType"
@@ -1379,6 +1632,11 @@
},
"TableCreationParameters": {
"type": "structure",
"required": [
"TableName",
"AttributeDefinitions",
"KeySchema"
],
"members": {
"TableName": "TableName",
"AttributeDefinitions": "AttributeDefinitions",
@@ -1396,6 +1654,10 @@
},
"Tag": {
"type": "structure",
"required": [
"Key",
"Value"
],
"members": {
"Key": "TagKeyString",
"Value": "TagValueString"
@@ -1414,6 +1676,10 @@
},
"TagResourceInput": {
"type": "structure",
"required": [
"ResourceArn",
"Tags"
],
"members": {
"ResourceArn": "ResourceArnString",
"Tags": "TagList"
@@ -1436,6 +1702,10 @@
},
"TimeToLiveSpecification": {
"type": "structure",
"required": [
"Enabled",
"AttributeName"
],
"members": {
"Enabled": "TimeToLiveEnabled",
"AttributeName": "TimeToLiveAttributeName"
@@ -1446,6 +1716,9 @@
},
"TransactGetItem": {
"type": "structure",
"required": [
"Get"
],
"members": {
"Get": "Get"
}
@@ -1456,6 +1729,9 @@
},
"TransactGetItemsInput": {
"type": "structure",
"required": [
"TransactItems"
],
"members": {
"TransactItems": "TransactGetItemList",
"ReturnConsumedCapacity": "ReturnConsumedCapacity"
@@ -1476,6 +1752,9 @@
},
"TransactWriteItemsInput": {
"type": "structure",
"required": [
"TransactItems"
],
"members": {
"TransactItems": "TransactWriteItemList",
"ReturnConsumedCapacity": "ReturnConsumedCapacity",
@@ -1485,6 +1764,10 @@
},
"UntagResourceInput": {
"type": "structure",
"required": [
"ResourceArn",
"TagKeys"
],
"members": {
"ResourceArn": "ResourceArnString",
"TagKeys": "TagKeyList"
@@ -1492,6 +1775,11 @@
},
"Update": {
"type": "structure",
"required": [
"Key",
"UpdateExpression",
"TableName"
],
"members": {
"Key": "Key",
"UpdateExpression": "UpdateExpression",
@@ -1504,6 +1792,10 @@
},
"UpdateContinuousBackupsInput": {
"type": "structure",
"required": [
"TableName",
"PointInTimeRecoverySpecification"
],
"members": {
"TableName": "TableArn",
"PointInTimeRecoverySpecification": "PointInTimeRecoverySpecification"
@@ -1511,6 +1803,10 @@
},
"UpdateContributorInsightsInput": {
"type": "structure",
"required": [
"TableName",
"ContributorInsightsAction"
],
"members": {
"TableName": "TableArn",
"IndexName": "IndexName",
@@ -1523,6 +1819,9 @@
},
"UpdateGlobalSecondaryIndexAction": {
"type": "structure",
"required": [
"IndexName"
],
"members": {
"IndexName": "IndexName",
"ProvisionedThroughput": "ProvisionedThroughput",
@@ -1532,6 +1831,10 @@
},
"UpdateGlobalTableInput": {
"type": "structure",
"required": [
"GlobalTableName",
"ReplicaUpdates"
],
"members": {
"GlobalTableName": "TableName",
"ReplicaUpdates": "ReplicaUpdateList"
@@ -1539,6 +1842,9 @@
},
"UpdateGlobalTableSettingsInput": {
"type": "structure",
"required": [
"GlobalTableName"
],
"members": {
"GlobalTableName": "TableName",
"GlobalTableBillingMode": "BillingMode",
@@ -1550,6 +1856,10 @@
},
"UpdateItemInput": {
"type": "structure",
"required": [
"TableName",
"Key"
],
"members": {
"TableName": "TableArn",
"Key": "Key",
@@ -1574,6 +1884,10 @@
},
"UpdateKinesisStreamingDestinationInput": {
"type": "structure",
"required": [
"TableName",
"StreamArn"
],
"members": {
"TableName": "TableArn",
"StreamArn": "StreamArn",
@@ -1582,6 +1896,9 @@
},
"UpdateReplicationGroupMemberAction": {
"type": "structure",
"required": [
"RegionName"
],
"members": {
"RegionName": "RegionName",
"KMSMasterKeyId": "KMSMasterKeyId",
@@ -1593,6 +1910,9 @@
},
"UpdateTableInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"AttributeDefinitions": "AttributeDefinitions",
"TableName": "TableArn",
@@ -1615,6 +1935,9 @@
},
"UpdateTableReplicaAutoScalingInput": {
"type": "structure",
"required": [
"TableName"
],
"members": {
"GlobalSecondaryIndexUpdates": "GlobalSecondaryIndexAutoScalingUpdateList",
"TableName": "TableArn",
@@ -1624,6 +1947,10 @@
},
"UpdateTimeToLiveInput": {
"type": "structure",
"required": [
"TableName",
"TimeToLiveSpecification"
],
"members": {
"TableName": "TableArn",
"TimeToLiveSpecification": "TimeToLiveSpecification"
@@ -1631,6 +1958,9 @@
},
"VectorAttributeDefinition": {
"type": "structure",
"required": [
"AttributeName"
],
"members": {
"AttributeName": "VectorAttributeName"
}
@@ -1643,6 +1973,13 @@
},
"VectorIndex": {
"type": "structure",
"required": [
"IndexName",
"VectorAttribute",
"Projection",
"Dimensions",
"DistanceFunction"
],
"members": {
"IndexName": "IndexName",
"VectorAttribute": "VectorAttributeDefinition",
@@ -105,6 +105,50 @@ class DynamoDbRequestShapesTest {
assertAccepted("NoSuchOperation", "{\"TableName\":5}");
}
@Test
void searchVectorsNamesTheLineAndByteColumnOfTheBodyAsSent() {
assertSearchVectorsRejected("{\n \"TableName\": \"sv-probe-absent-table\",\n \"IndexName\": null,\n"
+ " \"SearchVector\": [{\"N\": \"1\"}],\n \"TopK\": 1\n}",
"SerializationException", "invalid type: null, expected a string at line 3 column 19");
assertSearchVectorsRejected("{\"X\":\"\u65e5\u672c\",\"IndexName\":null,\"TableName\":\"sv-probe-absent-table\","
+ "\"SearchVector\":[{\"N\":\"1\"}],\"TopK\":1}",
"SerializationException", "invalid type: null, expected a string at line 1 column 30");
assertSearchVectorsRejected("{\"X\":\"\\u65e5\\u672c\",\"IndexName\":null,\"TableName\":\"sv-probe-absent-table\","
+ "\"SearchVector\":[{\"N\":\"1\"}],\"TopK\":1}",
"SerializationException", "invalid type: null, expected a string at line 1 column 36");
assertSearchVectorsRejected("{\n \"IndexName\": \"vix\",\n \"SearchVector\": [{\"N\": \"1\"}],\n \"TopK\": 1\n}",
"ValidationException", "missing field `TableName` at line 5 column 1");
assertSearchVectorsRejected("\n{\"IndexName\":\"vix\",\"SearchVector\":[{\"N\":\"1\"}],\"TopK\":1}",
"ValidationException", "missing field `TableName` at line 2 column 55");
assertSearchVectorsRejected("{\"X\":\"\u65e5\u672c\",\"IndexName\":\"vix\",\"SearchVector\":[{\"N\":\"1\"}],\"TopK\":1}",
"ValidationException", "missing field `TableName` at line 1 column 68");
assertSearchVectorsRejected("{\"X\":\"\\u65e5\",\"IndexName\":\"vix\",\"SearchVector\":[{\"N\":\"1\"}],\"TopK\":1}",
"ValidationException", "missing field `TableName` at line 1 column 68");
}
@Test
void searchVectorsRefusesABlankBodyAtItsEnd() {
assertSearchVectorsRejected("", "ValidationException", "EOF while parsing a value at line 1 column 0");
assertSearchVectorsRejected(" ", "ValidationException", "EOF while parsing a value at line 1 column 2");
assertSearchVectorsRejected("\t", "ValidationException", "EOF while parsing a value at line 1 column 1");
assertSearchVectorsRejected("\n", "ValidationException", "EOF while parsing a value at line 2 column 0");
assertSearchVectorsRejected(" \n ", "ValidationException", "EOF while parsing a value at line 2 column 2");
}
@Test
void searchVectorsWithEveryRequiredMemberIsLeftToTheOperation() {
String body = "{\"TableName\":\"t\",\"IndexName\":\"vix\",\"SearchVector\":[{\"N\":\"1\"}],\"TopK\":1}";
assertDoesNotThrow(() -> DynamoDbRequestShapes.check("SearchVectors", json(body), body));
}
private static void assertSearchVectorsRejected(String body, String type, String message) {
AwsException error = assertThrows(AwsException.class, () -> DynamoDbRequestShapes.check("SearchVectors",
body.isBlank() ? MAPPER.createObjectNode() : json(body), body));
assertEquals(type, error.getErrorCode());
assertEquals(400, error.getHttpStatus());
assertEquals(message, error.getMessage());
}
private static void assertRejected(String action, String body, String message) {
AwsException error = assertThrows(AwsException.class, () -> DynamoDbRequestShapes.check(action, json(body)));
assertEquals("SerializationException", error.getErrorCode());
@@ -13,6 +13,8 @@ import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import java.util.ArrayList;
import java.util.List;
@@ -1005,4 +1007,36 @@ class DynamoDbVectorSearchIntegrationTest {
+ "path is not defined; attribute name: #undef");
}
@ParameterizedTest
@Order(45)
@CsvSource(delimiter = '|', quoteCharacter = '`', textBlock = """
{"TableName":"sv-probe-absent-table","IndexName":null,"SearchVector":[{"N":"1"}],"TopK":1} | SerializationException | invalid type: null, expected a string at line 1 column 53
{"TableName":null,"IndexName":"vix","SearchVector":[{"N":"1"}],"TopK":1} | SerializationException | invalid type: null, expected a string at line 1 column 17
{"TableName":"sv-probe-absent-table","IndexName":"vix","SearchVector":null,"TopK":1} | SerializationException | invalid type: null, expected a sequence at line 1 column 74
{"TableName":"sv-probe-absent-table","IndexName":"vix","SearchVector":[{"N":"1"}],"TopK":null} | SerializationException | invalid type: null, expected i32 at line 1 column 93
{"TopK":null,"IndexName":null,"TableName":"sv-probe-absent-table","SearchVector":[{"N":"1"}]} | SerializationException | invalid type: null, expected i32 at line 1 column 12
{"Foo":1,"TableName":"sv-probe-absent-table","IndexName":null,"SearchVector":[{"N":"1"}],"TopK":1} | SerializationException | invalid type: null, expected a string at line 1 column 61
{"IndexName":null,"SearchVector":[{"N":"1"}],"TopK":1} | SerializationException | invalid type: null, expected a string at line 1 column 17
{"TableName":null,"IndexName":1,"SearchVector":[{"N":"1"}],"TopK":1} | SerializationException | invalid type: null, expected a string at line 1 column 17
{"IndexName":null,"TableName":"sv-probe-absent-table","SearchVector":[{"N":"1"}],"TopK":"1"} | SerializationException | invalid type: null, expected a string at line 1 column 17
{"TableName":"a\\u0062","IndexName":null,"SearchVector":[{"N":"1"}],"TopK":1} | SerializationException | invalid type: null, expected a string at line 1 column 39
{"TableName": "sv-probe-absent-table", "IndexName": null, "SearchVector": [{"N": "1"}], "TopK": 1} | SerializationException | invalid type: null, expected a string at line 1 column 56
{"TableName" : null ,"IndexName":"vix","SearchVector":[{"N":"1"}],"TopK":1} | SerializationException | invalid type: null, expected a string at line 1 column 19
{"X":{"a":[1,2,{"b":"c"}]},"TableName":null,"IndexName":"vix","SearchVector":[{"N":"1"}],"TopK":1} | SerializationException | invalid type: null, expected a string at line 1 column 43
{"IndexName":"ab","SearchVector":[{"N":"1"}],"TopK":1} | ValidationException | missing field `TableName` at line 1 column 54
{"IndexName":"vix","SearchVector":[{"N":"1"}],"TopK":0} | ValidationException | missing field `TableName` at line 1 column 55
{"IndexName":"vix","SearchVector":[{"N":"1"}],"TopK":1,"ReturnConsumedCapacity":"BOGUS"} | ValidationException | missing field `TableName` at line 1 column 88
{"IndexName":"vix","SearchVector":[{"N":"1"}]} | ValidationException | missing field `TableName` at line 1 column 46
{"IndexName": "vix", "SearchVector": [{"N": "1"}], "TopK": 1} | ValidationException | missing field `TableName` at line 1 column 61
`{"IndexName":"vix","SearchVector":[{"N":"1"}],"TopK":1} ` | ValidationException | missing field `TableName` at line 1 column 55
{"IndexName":"vix","TopK":1} | ValidationException | missing field `SearchVector` at line 1 column 28
{} | ValidationException | missing field `IndexName` at line 1 column 2
""")
void searchVectorsRejectsANullRequiredMemberBeforeAnOmittedOne(String body, String type, String message) {
call("SearchVectors", body)
.statusCode(400)
.body("__type", equalTo(type))
.body("message", equalTo(message));
}
}
@@ -3220,4 +3220,17 @@ class NativeDynamoDbJsonHandlerTest {
+ "Expected: S Actual: N IndexName: TitleIndex", onlyValidationErrorMessage(response));
assertEquals("Old", service.getItem("Movies", item("id", "m1"), "eu-west-1").get("title").get("S").asText());
}
@ParameterizedTest
@CsvSource(delimiter = '|', quoteCharacter = '`', textBlock = """
{"TableName":"t","SearchVector":[{"N":"1"}],"TopK":1} | ValidationException | missing field `IndexName` at line 1 column 53
{"TableName":"t","IndexName":"vix","SearchVector":[{"N":"1"}]} | ValidationException | missing field `TopK` at line 1 column 62
{"TableName":"t","IndexName":"vix","SearchVector":[{"N":"1"}],"TopK":null} | SerializationException | invalid type: null, expected i32 at line 1 column 73
""")
void searchVectorsWithoutAJsonBodyStillRefusesANullOrOmittedRequiredMember(String body, String type,
String message) {
AwsException ex = assertThrows(AwsException.class, () -> handler.handle("SearchVectors", json(body), "eu-west-1"));
assertEquals(type, ex.getErrorCode());
assertEquals(message, ex.getMessage());
}
}
+4 -2
View File
@@ -5,7 +5,8 @@ DynamoDB rejects a request member of the wrong JSON type with a SerializationExc
it runs the operation. The Java side (`DynamoDbRequestShapes`) needs each operation's input
shapes to do the same, so this script keeps only what that check reads: the input shape of
every operation, and for every shape reachable from one, its type and the shapes of its
members, list elements or map values.
members, list elements or map values. It also keeps the members each structure requires,
which SearchVectors refuses when null or omitted.
The model is botocore's `dynamodb/2012-08-10/service-2.json` (Apache-2.0,
https://github.com/boto/botocore). It is located, in order, at `--botocore-data`, the
@@ -28,7 +29,8 @@ MODEL = Path("dynamodb/2012-08-10")
def main(argv: list[str] | None = None) -> int:
return request_shapes.main(argv, script=__file__, model=MODEL, output=OUTPUT, description=__doc__)
return request_shapes.main(argv, script=__file__, model=MODEL, output=OUTPUT, description=__doc__,
required=True)
if __name__ == "__main__":
+6 -3
View File
@@ -7,6 +7,7 @@
shape of every operation, reduced to the members carried in the JSON body, and for every shape
reachable from one, its type and the shapes of its members, list elements or map values.
`regen_emr_serverless_shapes.py` keeps every operation's output shape too, with `outputs=True`.
`regen_dynamodb_shapes.py` keeps the members each structure requires too, with `required=True`.
`regen_iam_shapes.py` and `regen_sts_shapes.py` name their operations instead, which switches
`main()` to `build_constraints()`.
@@ -35,7 +36,7 @@ def load_model(data: Path, model: Path) -> dict:
return load_json_model(source)
def build(model: dict, provenance: str, generator: str, outputs: bool = False) -> dict:
def build(model: dict, provenance: str, generator: str, outputs: bool = False, required: bool = False) -> dict:
shapes = model["shapes"]
kept: dict[str, dict] = {}
@@ -49,6 +50,8 @@ def build(model: dict, provenance: str, generator: str, outputs: bool = False) -
if kind == "structure":
members = {member: spec for member, spec in shape.get("members", {}).items()
if not (body_only and "location" in spec)}
if required and "required" in shape:
entry["required"] = [member for member in shape["required"] if member in members]
entry["members"] = {member: spec["shape"] for member, spec in members.items()}
for spec in members.values():
keep(spec["shape"])
@@ -150,7 +153,7 @@ def generator_name(script: str) -> str:
def main(argv: list[str] | None, *, script: str, model: Path, output: Path, description: str,
outputs: bool = False, operations: tuple[str, ...] | None = None,
outputs: bool = False, required: bool = False, operations: tuple[str, ...] | None = None,
constraints: bool = False,
prepare: Callable[[dict], dict] | None = None) -> int:
"""Drives one generator: parse the flags, read the model, write or check the vendored file.
@@ -181,7 +184,7 @@ def main(argv: list[str] | None, *, script: str, model: Path, output: Path, desc
operations = tuple(name for name, operation in sorted(loaded["operations"].items()) if "input" in operation)
generator = generator_name(script)
fresh = render(build_constraints(loaded, operations, provenance, generator) if operations is not None
else build(loaded, provenance, generator, outputs))
else build(loaded, provenance, generator, outputs, required))
if args.check:
current = args.output.read_text(encoding="utf-8") if args.output.exists() else ""
+15 -7
View File
@@ -41,7 +41,7 @@ DYNAMODB_MODEL = {
"NoInput": {},
},
"shapes": {
"ScanInput": {"type": "structure", "members": {
"ScanInput": {"type": "structure", "required": ["TableName"], "members": {
"TableName": {"shape": "TableName"},
"AttributesToGet": {"shape": "AttributeNameList"},
"ExclusiveStartKey": {"shape": "Key"},
@@ -101,6 +101,13 @@ def test_keeps_only_input_shapes_and_their_types():
assert doc["shapes"]["Key"] == {"type": "map", "value": "AttributeValue"}
def test_keeps_required_members_only_when_asked():
doc = r.build(DYNAMODB_MODEL, "botocore test", "tools/aws/regen_dynamodb_shapes.py", required=True)
assert doc["shapes"]["ScanInput"]["required"] == ["TableName"]
assert "required" not in doc["shapes"]["DescribeLimitsInput"]
def test_keeps_only_body_members_of_input_shapes():
doc = r.build(SESV2_MODEL, "botocore test", "tools/aws/regen_sesv2_shapes.py")
@@ -204,13 +211,13 @@ def test_load_model_without_a_service_model_exits(tmp_path):
r.load_model(tmp_path, Path("svc/2020-01-01"))
@pytest.mark.parametrize("script, model, output", [
(regen_dynamodb_shapes, "dynamodb/2012-08-10", "dynamodb-request-shapes.json"),
(regen_sesv2_shapes, "sesv2/2019-09-27", "sesv2-request-shapes.json"),
(regen_apigateway_shapes, "apigateway/2015-07-09", "apigateway-request-shapes.json"),
(regen_ecs_shapes, "ecs/2014-11-13", "ecs-request-shapes.json"),
@pytest.mark.parametrize("script, model, output, options", [
(regen_dynamodb_shapes, "dynamodb/2012-08-10", "dynamodb-request-shapes.json", {"required": True}),
(regen_sesv2_shapes, "sesv2/2019-09-27", "sesv2-request-shapes.json", {}),
(regen_apigateway_shapes, "apigateway/2015-07-09", "apigateway-request-shapes.json", {}),
(regen_ecs_shapes, "ecs/2014-11-13", "ecs-request-shapes.json", {}),
])
def test_each_script_runs_the_shared_main_with_its_model_and_output(script, model, output, monkeypatch):
def test_each_script_runs_the_shared_main_with_its_model_and_output(script, model, output, options, monkeypatch):
calls = []
monkeypatch.setattr(r, "main", lambda argv, **kwargs: calls.append((argv, kwargs)) or 0)
@@ -220,6 +227,7 @@ def test_each_script_runs_the_shared_main_with_its_model_and_output(script, mode
"model": Path(model),
"output": r.REPO_ROOT / "src/main/resources/aws" / output,
"description": script.__doc__,
**options,
})]