mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): reject a BETWEEN with reversed bounds at parse time (#3183)
* fix(dynamodb): reject a BETWEEN with reversed bounds at parse time A BETWEEN whose lower bound exceeds its upper bound parsed cleanly and then failed the condition at evaluation, so PutItem answered with a ConditionalCheckFailedException. AWS rejects the expression itself with a ValidationException. The bounds are compared during expression validation, when both resolve to values of the same type. Closes 1 TIER 1 case in the dynamodb-conformance suite. * fix(dynamodb): order BETWEEN string bounds by UTF-8 bytes like DynamoDB * fix(dynamodb): answer a 400 SerializationException for a malformed binary BETWEEN bound * fix(dynamodb): wrap the ConditionExpression BETWEEN error in the AWS validation envelope
This commit is contained in:
1 parent
8142457f9b
commit
df0bf82e12
3 files changed
+185
-1
No files matched your search
+29
@@ -440,6 +440,35 @@ class DynamoDbIntegrationTest {
|
||||
.body("Items[0].total", nullValue());
|
||||
}
|
||||
|
||||
// Checked against real DynamoDB (us-east-1, 2026-09-07). A reversed BETWEEN in a
|
||||
// ConditionExpression is a 400 ValidationException, not a ConditionalCheckFailedException,
|
||||
// and AWS wraps the ConditionExpression form in its validation-error envelope.
|
||||
@Test
|
||||
@Order(10)
|
||||
void putItemWithReversedBetweenBoundsReturnsValidationException() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "TestTable",
|
||||
"Item": {"pk": {"S": "between-1"}, "sk": {"S": "a"}},
|
||||
"ConditionExpression": "#n BETWEEN :hi AND :lo",
|
||||
"ExpressionAttributeNames": {"#n": "n"},
|
||||
"ExpressionAttributeValues": {":hi": {"N": "10"}, ":lo": {"N": "1"}}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo("1 validation error detected: Invalid ConditionExpression: "
|
||||
+ "The BETWEEN operator requires upper bound to be greater than or equal to lower "
|
||||
+ "bound; lower bound operand: AttributeValue: {N:10}, upper bound operand: "
|
||||
+ "AttributeValue: {N:1}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void queryWithSelectSpecificAttributesRequiresProjectionParameters() {
|
||||
|
||||
+92
-1
@@ -2,7 +2,6 @@ package io.github.hectorvent.floci.services.dynamodb;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -596,6 +595,98 @@ class ExpressionEvaluatorTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void reversedBetweenBoundsAreRejectedAtParseTime() {
|
||||
var mapper = new ObjectMapper();
|
||||
var values = mapper.createObjectNode();
|
||||
values.set(":hi", mapper.createObjectNode().put("N", "10"));
|
||||
values.set(":lo", mapper.createObjectNode().put("N", "1"));
|
||||
|
||||
var e = assertThrows(AwsException.class, () ->
|
||||
ExpressionEvaluator.validateExpression("n BETWEEN :hi AND :lo",
|
||||
"ConditionExpression", null, values));
|
||||
assertEquals("ValidationException", e.getErrorCode());
|
||||
assertEquals("1 validation error detected: Invalid ConditionExpression: The BETWEEN operator "
|
||||
+ "requires upper bound to be greater than or equal to lower bound; lower bound operand: "
|
||||
+ "AttributeValue: {N:10}, upper bound operand: AttributeValue: {N:1}", e.getMessage());
|
||||
}
|
||||
|
||||
// Checked against real DynamoDB (us-east-1, 2026-09-07): U+E000 as the lower bound
|
||||
// and U+10000 as the upper bound is accepted, because DynamoDB orders strings by
|
||||
// their UTF-8 bytes. Java's UTF-16 ordering puts them the other way round.
|
||||
@Test
|
||||
void stringBoundsAreOrderedByUtf8Bytes() {
|
||||
var mapper = new ObjectMapper();
|
||||
var values = mapper.createObjectNode();
|
||||
values.set(":lo", mapper.createObjectNode().put("S", "\uE000"));
|
||||
values.set(":hi", mapper.createObjectNode().put("S", "\uD800\uDC00"));
|
||||
|
||||
assertDoesNotThrow(() -> ExpressionEvaluator.validateExpression("n BETWEEN :lo AND :hi",
|
||||
"ConditionExpression", null, values));
|
||||
|
||||
var reversed = mapper.createObjectNode();
|
||||
reversed.set(":lo", mapper.createObjectNode().put("S", "\uD800\uDC00"));
|
||||
reversed.set(":hi", mapper.createObjectNode().put("S", "\uE000"));
|
||||
|
||||
var e = assertThrows(AwsException.class, () ->
|
||||
ExpressionEvaluator.validateExpression("n BETWEEN :lo AND :hi",
|
||||
"ConditionExpression", null, reversed));
|
||||
assertEquals("ValidationException", e.getErrorCode());
|
||||
}
|
||||
|
||||
// Checked against real DynamoDB (us-east-1, 2026-09-07): binary bounds compare by
|
||||
// unsigned bytes, and a bound that is not valid base64 fails the request with a 400
|
||||
// SerializationException before any comparison happens.
|
||||
@Test
|
||||
void binaryBoundsCompareByBytesAndRejectMalformedBase64() {
|
||||
var mapper = new ObjectMapper();
|
||||
var reversed = mapper.createObjectNode();
|
||||
reversed.set(":lo", mapper.createObjectNode().put("B", "/w=="));
|
||||
reversed.set(":hi", mapper.createObjectNode().put("B", "AA=="));
|
||||
|
||||
var e = assertThrows(AwsException.class, () ->
|
||||
ExpressionEvaluator.validateExpression("n BETWEEN :lo AND :hi",
|
||||
"ConditionExpression", null, reversed));
|
||||
assertEquals("ValidationException", e.getErrorCode());
|
||||
|
||||
var malformed = mapper.createObjectNode();
|
||||
malformed.set(":lo", mapper.createObjectNode().put("B", "!!!not-base64!!!"));
|
||||
malformed.set(":hi", mapper.createObjectNode().put("B", "@@@@"));
|
||||
|
||||
var serialization = assertThrows(AwsException.class, () ->
|
||||
ExpressionEvaluator.validateExpression("n BETWEEN :lo AND :hi",
|
||||
"ConditionExpression", null, malformed));
|
||||
assertEquals("SerializationException", serialization.getErrorCode());
|
||||
assertEquals(400, serialization.getHttpStatus());
|
||||
}
|
||||
|
||||
// A FilterExpression carries the same text without the envelope on AWS.
|
||||
@Test
|
||||
void filterExpressionReportsTheReversedBoundsWithoutTheEnvelope() {
|
||||
var mapper = new ObjectMapper();
|
||||
var values = mapper.createObjectNode();
|
||||
values.set(":hi", mapper.createObjectNode().put("N", "10"));
|
||||
values.set(":lo", mapper.createObjectNode().put("N", "1"));
|
||||
|
||||
var e = assertThrows(AwsException.class, () ->
|
||||
ExpressionEvaluator.validateExpression("n BETWEEN :hi AND :lo",
|
||||
"FilterExpression", null, values));
|
||||
assertEquals("Invalid FilterExpression: The BETWEEN operator requires upper bound to be "
|
||||
+ "greater than or equal to lower bound; lower bound operand: AttributeValue: {N:10}, "
|
||||
+ "upper bound operand: AttributeValue: {N:1}", e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void orderedBetweenBoundsAreAccepted() {
|
||||
var mapper = new ObjectMapper();
|
||||
var values = mapper.createObjectNode();
|
||||
values.set(":lo", mapper.createObjectNode().put("N", "1"));
|
||||
values.set(":hi", mapper.createObjectNode().put("N", "10"));
|
||||
|
||||
assertDoesNotThrow(() -> ExpressionEvaluator.validateExpression("n BETWEEN :lo AND :hi",
|
||||
"ConditionExpression", null, values));
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingOperandThrowsSyntaxError() {
|
||||
AwsException e = assertThrows(AwsException.class, () ->
|
||||
|
||||
Reference in new issue
Block a user