From dffe34e1333e67b3ce03db93b8876ebbd2c710d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TATSUNO=20=E2=80=9CTaz=E2=80=9D=20Yasuhiro?= Date: Fri, 11 Sep 2026 22:53:13 +0900 Subject: [PATCH] fix(dynamodb): match AWS wording and order for Select rejections (#3410) * fix(dynamodb): match AWS wording and order for Select rejections Query and Scan share one Select validator. It reported Floci wording and checked the rules in the wrong order, so a request breaking both the ProjectionExpression rule and the IndexName rule named the wrong one. The ProjectionExpression conflict is now reported first, and each message names the Select value the way AWS does. The SPECIFIC_ATTRIBUTES message without a projection also matches AWS, which prefixes the error count on Query but not on Scan. Closes 8 TIER 1 and 2 TIER 3 cases in the dynamodb-conformance suite. * test(dynamodb): cover the bare Select message on Scan Scan returns the message without the validation count prefix, Query keeps it. Only the Query side had a handler-level test. --- .../dynamodb/DynamoDbAccessPathValidator.java | 9 +++--- .../dynamodb/DynamoDbJsonHandler.java | 9 ++++-- .../DynamoDbAccessPathValidatorTest.java | 30 +++++++++++++++++++ .../dynamodb/DynamoDbIntegrationTest.java | 24 ++++++++++++++- 4 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidator.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidator.java index d24be78779..45a5d77d75 100644 --- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidator.java +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidator.java @@ -55,11 +55,12 @@ final class DynamoDbAccessPathValidator { static void validateSelection(TableDefinition table, DynamoDbAccessPath accessPath, String select, String projectionExpression, JsonNode attributesToGet, JsonNode expressionAttributeNames) { - if ("ALL_PROJECTED_ATTRIBUTES".equals(select) && !accessPath.isIndex()) { - throw validationException("Select type ALL_PROJECTED_ATTRIBUTES is not supported for query on a table"); - } if (projectionExpression != null && select != null && !"SPECIFIC_ATTRIBUTES".equals(select)) { - throw validationException("Cannot use both Select and ProjectionExpression unless Select is SPECIFIC_ATTRIBUTES"); + throw validationException("Cannot specify the ProjectionExpression when choosing to get " + + ("COUNT".equals(select) ? "only the Count" : select)); + } + if ("ALL_PROJECTED_ATTRIBUTES".equals(select) && !accessPath.isIndex()) { + throw validationException("ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an IndexName"); } if (attributesToGet != null && select != null && !"SPECIFIC_ATTRIBUTES".equals(select)) { throw validationException("Cannot use both Select and AttributesToGet unless Select is SPECIFIC_ATTRIBUTES"); diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java index 3b44e52589..9908704605 100644 --- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java @@ -838,6 +838,9 @@ public class DynamoDbJsonHandler { private static final Set VALID_SELECT = Set.of( "ALL_ATTRIBUTES", "ALL_PROJECTED_ATTRIBUTES", "SPECIFIC_ATTRIBUTES", "COUNT"); + private static final String SELECT_NEEDS_PROJECTION = + "Must specify the AttributesToGet or ProjectionExpression when choosing to get SPECIFIC_ATTRIBUTES"; + private Response handleQuery(JsonNode request, String region) { String tableName = request.path("TableName").asText(); DynamoDbTableNames.resolve(tableName); // validate tableName first @@ -921,8 +924,9 @@ public class DynamoDbJsonHandler { boolean hasAttributesToGet = attributesToGet != null && attributesToGet.size() > 0; if ("SPECIFIC_ATTRIBUTES".equals(select) && projectionExpression == null && !hasAttributesToGet) { + // Query prefixes the count here, Scan does not. throw new AwsException("ValidationException", - "Select type SPECIFIC_ATTRIBUTES requires the ProjectionExpression to be provided.", 400); + "1 validation error detected: " + SELECT_NEEDS_PROJECTION, 400); } TableDefinition queryTable = dynamoDbService.describeTable(tableName, region); @@ -1096,8 +1100,7 @@ public class DynamoDbJsonHandler { boolean hasAttributesToGetScan = attributesToGetScan != null && attributesToGetScan.size() > 0; if ("SPECIFIC_ATTRIBUTES".equals(select) && projectionExpressionScan == null && !hasAttributesToGetScan) { - throw new AwsException("ValidationException", - "Select type SPECIFIC_ATTRIBUTES requires the ProjectionExpression to be provided.", 400); + throw new AwsException("ValidationException", SELECT_NEEDS_PROJECTION, 400); } TableDefinition scanTable = dynamoDbService.describeTable(tableName, region); diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidatorTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidatorTest.java index 8c4a4bcfc5..76d39a8714 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidatorTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidatorTest.java @@ -387,6 +387,36 @@ class DynamoDbAccessPathValidatorTest { assertEquals("Query key condition not supported", error.getMessage()); } + @Test + void namesTheSelectValueWhenRejectingAProjectionExpression() { + AwsException allAttributes = assertThrows(AwsException.class, + () -> DynamoDbAccessPathValidator.validateSelection( + table, tablePath, "ALL_ATTRIBUTES", "sk", null, null)); + assertEquals("Cannot specify the ProjectionExpression when choosing to get ALL_ATTRIBUTES", + allAttributes.getMessage()); + + AwsException count = assertThrows(AwsException.class, + () -> DynamoDbAccessPathValidator.validateSelection( + table, tablePath, "COUNT", "sk", null, null)); + assertEquals("Cannot specify the ProjectionExpression when choosing to get only the Count", + count.getMessage()); + } + + @Test + void reportsTheProjectionExpressionConflictBeforeTheMissingIndex() { + AwsException both = assertThrows(AwsException.class, + () -> DynamoDbAccessPathValidator.validateSelection( + table, tablePath, "ALL_PROJECTED_ATTRIBUTES", "sk", null, null)); + assertEquals("Cannot specify the ProjectionExpression when choosing to get ALL_PROJECTED_ATTRIBUTES", + both.getMessage()); + + AwsException indexOnly = assertThrows(AwsException.class, + () -> DynamoDbAccessPathValidator.validateSelection( + table, tablePath, "ALL_PROJECTED_ATTRIBUTES", null, null, null)); + assertEquals("ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an IndexName", + indexOnly.getMessage()); + } + private void validateExpression(DynamoDbAccessPath accessPath, String expression) { DynamoDbAccessPathValidator.validateQuery( table, accessPath, null, expression, null, null, null, diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java index d759dd7136..4170fac621 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java @@ -804,7 +804,29 @@ class DynamoDbIntegrationTest { .then() .statusCode(400) .body("__type", equalTo("ValidationException")) - .body("message", equalTo("Select type SPECIFIC_ATTRIBUTES requires the ProjectionExpression to be provided.")); + .body("message", equalTo("1 validation error detected: Must specify the AttributesToGet or " + + "ProjectionExpression when choosing to get SPECIFIC_ATTRIBUTES")); + } + + @Test + @Order(10) + void scanWithSelectSpecificAttributesRequiresProjectionParameters() { + given() + .header("X-Amz-Target", "DynamoDB_20120810.Scan") + .contentType(DYNAMODB_CONTENT_TYPE) + .body(""" + { + "TableName": "TestTable", + "Select": "SPECIFIC_ATTRIBUTES" + } + """) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("ValidationException")) + .body("message", equalTo("Must specify the AttributesToGet or " + + "ProjectionExpression when choosing to get SPECIFIC_ATTRIBUTES")); } @Test