mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): refuse unconvertible and out-of-range PartiQL number parameters before parsing the statement (#7179)
* fix(dynamodb): refuse unconvertible and out-of-range PartiQL number parameters before parsing the statement * fix(dynamodb): decode binary PartiQL parameters first, and count types while reading each parameter * fix(dynamodb): take a PartiQL parameter member set to null as absent * fix(dynamodb): drop null parameter members before IAM reads the PartiQL attributes
This commit is contained in:
1 parent
28bde18804
commit
664db0cef3
7 files changed
+228
-23
No files matched your search
+11
@@ -40,6 +40,17 @@ class DynamoDbConditionKeysTest {
|
||||
assertEquals("SPECIFIC_ATTRIBUTES", result.select());
|
||||
}
|
||||
|
||||
@Test
|
||||
void partiqlAttributesTakeAParameterMemberSetToNullAsAbsent() {
|
||||
JsonNode body = mapper.createObjectNode().put("Statement", "SELECT payload FROM FgacTable WHERE PK = ?")
|
||||
.set("Parameters", json("[{\"S\":\"one\",\"N\":null}]"));
|
||||
|
||||
DynamoDbConditionKeys.Result result = DynamoDbConditionKeys.extract("dynamodb:PartiQLSelect", body, table);
|
||||
|
||||
assertEquals(List.of("payload", "PK"), result.attributes());
|
||||
assertTrue(body.at("/Parameters/0").has("N"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', value = {
|
||||
"GetItem | {} | ALL_ATTRIBUTES",
|
||||
|
||||
+110
@@ -9,6 +9,7 @@ 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 org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
@@ -624,6 +625,115 @@ class DynamoDbPartiQLIntegrationTest {
|
||||
.body("Responses[0].Error.Message", equalTo("Requested resource not found"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@Order(30)
|
||||
@CsvSource(delimiter = '|', textBlock = """
|
||||
[{"N":"abc"}] | The parameter cannot be converted to a numeric value: abc
|
||||
[{"N":""}] | The parameter cannot be converted to a numeric value
|
||||
[{"N":"1e2147483648"}] | The parameter cannot be converted to a numeric value: 1e2147483648
|
||||
[{"N":"0.1e2147483648"}] | The parameter cannot be converted to a numeric value: 0.1e2147483648
|
||||
[{"N":"1e-2147483648"}] | The parameter cannot be converted to a numeric value: 1e-2147483648
|
||||
[{"N":"1e2147483645"}] | Number overflow. Attempting to store a number with magnitude larger than supported range
|
||||
[{"N":"1e2147483647"}] | Number underflow. Attempting to store a number with magnitude smaller than supported range
|
||||
[{"N":"0e-131"}] | Number underflow. Attempting to store a number with magnitude smaller than supported range
|
||||
[{"N":"1.23456789012345678901234567890123456789"}] | Attempting to store more than 38 significant digits in a Number
|
||||
[{"NS":["1","1.0"]}] | Input collection contains duplicates
|
||||
[{"N":"abc"},%1$s] | The parameter cannot be converted to a numeric value: abc
|
||||
[%1$s,{"N":"abc"}] | Nesting Levels have exceeded supported limits: Attributes in the item have nested levels beyond supported limit
|
||||
[{"M":{"a":{"N":"abc"},"z":%1$s}}] | The parameter cannot be converted to a numeric value: abc
|
||||
[{"M":{"a":{"N":"abc"},"d":%1$s}}] | Nesting Levels have exceeded supported limits: Attributes in the item have nested levels beyond supported limit
|
||||
[{"L":[{"N":"1e126"},{"N":"abc"}]}] | Number overflow. Attempting to store a number with magnitude larger than supported range
|
||||
[{"NS":["1","1"]},{"N":"abc"}] | Input collection contains duplicates
|
||||
[{},{"N":"abc"}] | Supplied AttributeValue is empty, must contain exactly one of the supported datatypes
|
||||
[{"S":"a","N":"1"},{"N":"abc"}] | Supplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypes
|
||||
[{"S":"a","N":"abc"}] | The parameter cannot be converted to a numeric value: abc
|
||||
[{"N":null},{"N":"abc"}] | Supplied AttributeValue is empty, must contain exactly one of the supported datatypes
|
||||
[{"S":"a","N":null},{"N":"abc"}] | The parameter cannot be converted to a numeric value: abc
|
||||
""")
|
||||
void aParameterIsRefusedAtTheFirstValueThatCannotBeRead(String parameters, String message) {
|
||||
String deep = "{\"M\":{\"n\":".repeat(40) + "{\"S\":\"leaf\"}" + "}}".repeat(40);
|
||||
|
||||
request("DynamoDB_20120810.ExecuteStatement", """
|
||||
{"Statement":"SELECT * FROM \\"%s\\" WHERE pk = 'x' AND x = ? AND y = ?","Parameters":%s}
|
||||
""".formatted(TABLE, parameters.formatted(deep)))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(31)
|
||||
void aParameterIsReadBeforeTheStatementIsParsed() {
|
||||
String unconvertible = "The parameter cannot be converted to a numeric value: abc";
|
||||
|
||||
request("DynamoDB_20120810.ExecuteStatement", """
|
||||
{"Statement":"SELECT * FROM \\"%s\\" WHERE pk = ? #","Parameters":[{"N":"abc"}]}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo(unconvertible));
|
||||
request("DynamoDB_20120810.ExecuteTransaction", """
|
||||
{"TransactStatements":[{"Statement":"UPDATE \\"%1$s\\" SET n = ? WHERE pk = 'x'","Parameters":[{"N":"abc"}]},
|
||||
{"Statement":"UPDATE \\"%1$s\\" SET n = 1 WHERE pk = 'y' #"}]}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(400)
|
||||
.body("message", equalTo(unconvertible));
|
||||
request("DynamoDB_20120810.BatchExecuteStatement", """
|
||||
{"Statements":[{"Statement":"SELECT * FROM \\"%s\\" WHERE pk = ? #","Parameters":[{"N":"abc"}]}]}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(200)
|
||||
.body("Responses[0].Error.Code", equalTo("ValidationError"))
|
||||
.body("Responses[0].Error.Message", equalTo(unconvertible));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(32)
|
||||
void aBinaryParameterIsDecodedBeforeAnythingElse() {
|
||||
String update = "UPDATE \\\"" + TABLE + "\\\" SET n = ? WHERE pk = 'x'";
|
||||
|
||||
request("DynamoDB_20120810.ExecuteStatement", """
|
||||
{"Statement":"","Parameters":[{"N":"abc"},{"B":"AQI"}]}
|
||||
""")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("Base64 encoded length is expected a multiple of 4 bytes but found: 3"));
|
||||
request("DynamoDB_20120810.ExecuteTransaction", """
|
||||
{"TransactStatements":[{"Statement":"%1$s","Parameters":[{"N":"abc"}]},
|
||||
{"Statement":"%1$s","Parameters":[{"B":"AQI"}]}]}
|
||||
""".formatted(update))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"));
|
||||
request("DynamoDB_20120810.BatchExecuteStatement", """
|
||||
{"Statements":[{"Statement":""},{"Statement":"%s","Parameters":[{"B":"AQI"}]}]}
|
||||
""".formatted(update))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(33)
|
||||
void aParameterMemberSetToNullIsAbsent() {
|
||||
request("DynamoDB_20120810.BatchExecuteStatement", """
|
||||
{"Statements":[{"Statement":"SELECT * FROM \\"%s\\" WHERE pk = ?","Parameters":[{"N":null}]}]}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(200)
|
||||
.body("Responses[0].Error.Code", equalTo("ValidationError"))
|
||||
.body("Responses[0].Error.Message",
|
||||
equalTo("Supplied AttributeValue is empty, must contain exactly one of the supported datatypes"));
|
||||
request("DynamoDB_20120810.ExecuteStatement", """
|
||||
{"Statement":"INSERT INTO \\"%s\\" VALUE {'pk': 'null-member', 'v': ?}",
|
||||
"Parameters":[{"M":{"x":{"S":"a"}},"N":null}]}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(200);
|
||||
|
||||
request("DynamoDB_20120810.GetItem", """
|
||||
{"TableName":"%s","Key":{"pk":{"S":"null-member"}}}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(200)
|
||||
.body("Item.v.M.x.S", equalTo("a"))
|
||||
.body("Item.v.containsKey('N')", equalTo(false));
|
||||
}
|
||||
|
||||
private static void putItem(String pk, String attributes) {
|
||||
request("DynamoDB_20120810.PutItem", """
|
||||
{"TableName":"%s","Item":{"pk":{"S":"%s"},%s}}
|
||||
|
||||
Reference in new issue
Block a user