mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): report a missing PartiQL term, path or table name as DynamoDB does (#6957)
* fix(dynamodb): report a missing PartiQL term, path or table name as DynamoDB does * fix(dynamodb): stop a star string or a long run of signs from crashing the PartiQL parser
This commit is contained in:
1 parent
17a8d76cee
commit
aecabcb783
3 files changed
+187
-11
No files matched your search
+26
@@ -422,6 +422,32 @@ class DynamoDbPartiQLIntegrationTest {
|
||||
+ (unsupported.indexOf("n IS") + 1) + ":1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void aStatementThatBreaksOffNamesWhatItFoundWhereATermShouldStart() {
|
||||
String notWellFormed = "Statement wasn't well formed, can't be processed: ";
|
||||
|
||||
statement("SELECT * FROM \"" + TABLE + "-never-created\" WHERE")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo(notWellFormed + "Unexpected term"));
|
||||
statement("DELETE FROM WHERE pk = 'x'")
|
||||
.statusCode(400)
|
||||
.body("message", equalTo(notWellFormed + "Expected identifier for simple path"));
|
||||
request("DynamoDB_20120810.ExecuteTransaction", """
|
||||
{"TransactStatements":[{"Statement":"SELECT * FROM \\"%s\\" WHERE pk = 'x' AND"}]}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Validation failed in TransactStatements[0]: " + notWellFormed
|
||||
+ "Missing right-hand side expression of infix operator"));
|
||||
request("DynamoDB_20120810.BatchExecuteStatement", """
|
||||
{"Statements":[{"Statement":"SELECT * FROM \\"%s\\" WHERE IS NULL"}]}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(200)
|
||||
.body("Responses[0].Error.Code", equalTo("ValidationError"))
|
||||
.body("Responses[0].Error.Message", equalTo(notWellFormed + "Unexpected operator"));
|
||||
}
|
||||
|
||||
private static void putItem(String pk, String attributes) {
|
||||
request("DynamoDB_20120810.PutItem", """
|
||||
{"TableName":"%s","Item":{"pk":{"S":"%s"},%s}}
|
||||
|
||||
+54
@@ -334,6 +334,60 @@ class DynamoDbPartiQLParserTest {
|
||||
+ "[MISSING, NULL, BOOLEAN, BLOB, STRING, NUMERIC, STRUCT, TUPLE, LIST] at 2:3:5", e.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', quoteCharacter = '`', textBlock = """
|
||||
SELECT pk FROM "t" WHERE | Unexpected term
|
||||
SELECT pk FROM "t" WHERE ; | Unexpected term
|
||||
SELECT pk FROM "t" WHERE NOT | Unexpected term
|
||||
SELECT pk FROM "t" WHERE ( | Unexpected term
|
||||
SELECT pk FROM "t" WHERE * | Unexpected term
|
||||
SELECT pk FROM "t" WHERE begins_with( | Unexpected term
|
||||
SELECT pk FROM "t" WHERE pk IN ['a', | Unexpected term
|
||||
SELECT pk FROM "t" WHERE pk = 'a' OR ; | Unexpected term
|
||||
SELECT * FROM | Unexpected term
|
||||
; | Unexpected term
|
||||
UPDATE "t" SET a = | Unexpected term
|
||||
INSERT INTO "t" | Unexpected term
|
||||
INSERT INTO "t" VALUE {'pk': | Unexpected term
|
||||
SELECT pk FROM "t" WHERE ORDER BY pk | Unexpected keyword
|
||||
SELECT pk FROM "t" WHERE pk = - ORDER | Unexpected keyword
|
||||
SELECT pk FROM "t" WHERE IS NULL | Unexpected operator
|
||||
SELECT pk FROM "t" WHERE pk = LIKE | Unexpected operator
|
||||
SELECT pk FROM "t" WHERE pk = 'a' AND | Missing right-hand side expression of infix operator
|
||||
SELECT pk FROM "t" WHERE pk < | Missing right-hand side expression of infix operator
|
||||
SELECT pk FROM "t" WHERE pk IN | Missing right-hand side expression of infix operator
|
||||
UPDATE "t" SET a = a + | Missing right-hand side expression of infix operator
|
||||
SELECT pk FROM "t" WHERE pk BETWEEN 'a' AND | Expected expression after AND
|
||||
DELETE FROM | Expected identifier for simple path
|
||||
DELETE FROM WHERE pk = 'a' | Expected identifier for simple path
|
||||
UPDATE "t" SET a = 1, | Expected identifier for simple path
|
||||
INSERT INTO like VALUE {'pk': 'a'} | Expected identifier for simple path
|
||||
SELECT FROM "t" | Expected identifier or an expression but found unexpected keyword 'from' in a select list.
|
||||
SELECT pk, * FROM "t" WHERE | Other expressions may not be present in the select list when '*' is used without dot notation.
|
||||
SELECT *, pk FROM "t" | Other expressions may not be present in the select list when '*' is used without dot notation.
|
||||
""")
|
||||
void namesWhatItFoundWhereATermShouldStart(String statement, String message) {
|
||||
AwsException e = assertThrows(AwsException.class, () -> DynamoDbPartiQLParser.parse(statement, List.of()));
|
||||
|
||||
assertEquals("Statement wasn't well formed, can't be processed: " + message, e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void namesWhatFollowsALongRunOfSigns() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> DynamoDbPartiQLParser.parse(SELECT + "= " + "+ ".repeat(300_000), List.of()));
|
||||
|
||||
assertEquals("Statement wasn't well formed, can't be processed: Unexpected term", e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void refusesAStarStringInTheSelectListAsAValidationError() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> DynamoDbPartiQLParser.parse("SELECT '*' FROM \"t\"", List.of()));
|
||||
|
||||
assertEquals("ValidationException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void parsesNotAheadOfThePredicateItNegates() {
|
||||
Stmt stmt = DynamoDbPartiQLParser.parse(
|
||||
|
||||
Reference in new issue
Block a user