mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): report the token and the text near a condition syntax error (#7360)
* fix(dynamodb): report the token and the text near a condition syntax error * fix(dynamodb): add braces to the digit token loop
This commit is contained in:
1 parent
d74a084a61
commit
b0721f9795
5 files changed
+153
-63
No files matched your search
+2
-2
@@ -198,13 +198,13 @@ class DynamoDbAccessPathValidatorTest {
|
||||
void rejectsMalformedKeyAndFilterExpressions() {
|
||||
AwsException keyError = assertThrows(AwsException.class,
|
||||
() -> validateExpression(tablePath, "pk ="));
|
||||
assertEquals("Invalid KeyConditionExpression: Syntax error", keyError.getMessage());
|
||||
assertEquals("Invalid KeyConditionExpression: Syntax error; token: \"<EOF>\", near: \"=\"", keyError.getMessage());
|
||||
|
||||
AwsException filterError = assertThrows(AwsException.class,
|
||||
() -> DynamoDbAccessPathValidator.validateQuery(
|
||||
table, tablePath, null, "pk = :pk", "status =", null, null,
|
||||
expressionValues(":pk")));
|
||||
assertEquals("Invalid FilterExpression: Syntax error", filterError.getMessage());
|
||||
assertEquals("Invalid FilterExpression: Syntax error; token: \"<EOF>\", near: \"=\"", filterError.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+36
@@ -11,6 +11,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.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
@@ -5807,6 +5809,40 @@ given()
|
||||
deleteTable(tableName);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', quoteCharacter = '`', textBlock = """
|
||||
Query | {"TableName": "SyntaxTable", "KeyConditionExpression": " ", "ExpressionAttributeValues": {":v": {"S": "x"}}} | Invalid KeyConditionExpression: Syntax error; token: "<EOF>", near: " "
|
||||
Scan | {"TableName": "SyntaxTable", "FilterExpression": "a = = b", "ExpressionAttributeValues": {":v": {"S": "x"}}} | Invalid FilterExpression: Syntax error; token: "=", near: "= = b"
|
||||
TransactWriteItems | {"TransactItems": [{"ConditionCheck": {"TableName": "SyntaxTable", "Key": {"pk": {"S": "a"}}, "ConditionExpression": "attribute_not_exists(", "ExpressionAttributeValues": {":v": {"S": "x"}}}}]} | Invalid ConditionExpression: Syntax error; token: "<EOF>", near: "("
|
||||
""")
|
||||
void conditionSyntaxErrorsNameTheTokenAndTheTextAroundIt(String operation, String body, String message) {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "SyntaxTable",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST"
|
||||
}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810." + operation)
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body(body)
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo(message));
|
||||
|
||||
deleteTable("SyntaxTable");
|
||||
}
|
||||
|
||||
private void deleteTable(String tableName) {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
|
||||
+45
@@ -6,6 +6,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -792,5 +795,47 @@ class ExpressionEvaluatorTest {
|
||||
assertEquals("ValidationException", e.getErrorCode());
|
||||
assertTrue(e.getMessage().contains("Invalid ConditionExpression: Syntax error"), e.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', quoteCharacter = '`', textBlock = """
|
||||
attribute_not_exists( | <EOF> | (
|
||||
a = = b | = | = = b
|
||||
` ) a` | ) | ` ) a`
|
||||
a = :v b | b | :v b
|
||||
a IN :v | :v | IN :v
|
||||
a BETWEEN :v OR :v | OR | :v OR :v
|
||||
a | <EOF> | a
|
||||
` ` | <EOF> | ` `
|
||||
`attribute_not_exists( ` | <EOF> | `( `
|
||||
a.b. = :v | = | . = :v
|
||||
a[x] = :v | x | [x]
|
||||
a[1 = :v | = | 1 = :v
|
||||
a = 1.5 | 1 | = 1.
|
||||
_a = :v | _ | _a
|
||||
a\u00e9 = :v | \u00e9 | a\u00e9 =
|
||||
a = : | : | = :
|
||||
a = :v \uD83D\uDE00 | \uD83D\uDE00 | :v \uD83D\uDE00
|
||||
`a\u3000= :v` | `\u3000` | `a\u3000=`
|
||||
a = :v AND $ = = b | $ | AND $ =
|
||||
""")
|
||||
void syntaxErrorsNameTheTokenAndTheTextAroundIt(String expression, String token, String near) {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> ExpressionEvaluator.validateSyntax(expression, "ConditionExpression"));
|
||||
assertEquals("Invalid ConditionExpression: Syntax error; token: \"" + token + "\", near: \"" + near + "\"",
|
||||
e.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"a[ 1 ] = :v", "a [1] = :v", "a_b = :v"})
|
||||
void spacesInAListIndexAndUnderscoresInsideANameAreAccepted(String expression) {
|
||||
assertDoesNotThrow(() -> ExpressionEvaluator.validateSyntax(expression, "ConditionExpression"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void redundantParenthesesAreReportedBeforeAnUnknownCharacter() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> ExpressionEvaluator.validateSyntax("((a = :v)) $", "ConditionExpression"));
|
||||
assertEquals("Invalid ConditionExpression: The expression has redundant parentheses;", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
@@ -2427,6 +2427,8 @@ class NativeDynamoDbJsonHandlerTest {
|
||||
[{"Put":{"TableName":"Missing","Item":{},"ConditionExpression":""}}] | Invalid ConditionExpression: The expression can not be empty;
|
||||
[{"Update":{"TableName":"Missing","Key":{},"UpdateExpression":"","ConditionExpression":""}}] | Invalid ConditionExpression: The expression can not be empty;
|
||||
[{"Update":{"TableName":"Missing","Key":{},"UpdateExpression":""}}] | Invalid UpdateExpression: The expression can not be empty;
|
||||
[{"Put":{"TableName":"Missing","Item":{},"ConditionExpression":" "}}] | Invalid ConditionExpression: Syntax error; token: "<EOF>", near: " "
|
||||
[{"Put":{"TableName":"Missing","Item":{}}},{"ConditionCheck":{"TableName":"Missing","Key":{},"ConditionExpression":"attribute_not_exists("}}] | Invalid ConditionExpression: Syntax error; token: "<EOF>", near: "("
|
||||
[{"Update":{"TableName":"Missing","Key":{},"UpdateExpression":"SET a = :zz","ConditionExpression":"a = :yy"}}] | Invalid ConditionExpression: An expression attribute value used in expression is not defined; attribute value: :yy
|
||||
[{"Update":{"TableName":"Missing","Key":{},"UpdateExpression":"SET a = :zz","ConditionExpression":"contains(a, a)"}}] | Invalid ConditionExpression: The first operand must be distinct from the remaining operands for this operator or function; operator: contains, first operand: [a]
|
||||
[{"Put":{"TableName":"Missing","Item":{},"ConditionExpression":"attribute_not_exists(a)","ExpressionAttributeNames":{"#n":"n"},"ExpressionAttributeValues":{":v":{"S":"x"}}}}] | Value provided in ExpressionAttributeNames unused in expressions: keys: {#n}
|
||||
|
||||
Reference in new issue
Block a user