mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): validate cursor key types (#2470)
* fix(dynamodb): validate cursor key types Closes #2468 * fix(dynamodb): reject malformed cursors
This commit is contained in:
1 parent
564dbf204f
commit
e3df59ae1f
3 files changed
+170
-15
No files matched your search
+102
@@ -247,6 +247,108 @@ class DynamoDbAccessPathIntegrationTest {
|
||||
.body("message", equalTo("Consistent reads are not supported on global secondary indexes"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void queryAndScanRejectWrongExclusiveStartKeyTypes() {
|
||||
request("DynamoDB_20120810.Query", """
|
||||
{
|
||||
"TableName":"%s",
|
||||
"KeyConditionExpression":"pk = :pk",
|
||||
"ExpressionAttributeValues":{":pk":{"S":"p1"}},
|
||||
"ExclusiveStartKey":{"pk":{"N":"1"},"sk":{"S":"s1"}}
|
||||
}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo("The provided starting key is invalid"));
|
||||
|
||||
request("DynamoDB_20120810.Scan", """
|
||||
{
|
||||
"TableName":"%s",
|
||||
"ExclusiveStartKey":{"pk":{"S":"p1"},"sk":{"BOOL":true}}
|
||||
}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo("The provided starting key is invalid: "
|
||||
+ "The provided key element does not match the schema"));
|
||||
|
||||
request("DynamoDB_20120810.Query", """
|
||||
{
|
||||
"TableName":"%s",
|
||||
"KeyConditionExpression":"pk = :pk",
|
||||
"ExpressionAttributeValues":{":pk":{"S":"p1"}},
|
||||
"ExclusiveStartKey":{"pk":{"S":null},"sk":{"S":"s1"}}
|
||||
}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo("The provided starting key is invalid"));
|
||||
|
||||
request("DynamoDB_20120810.Scan", """
|
||||
{
|
||||
"TableName":"%s",
|
||||
"ExclusiveStartKey":{"pk":{"S":123},"sk":{"S":"s1"}}
|
||||
}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void queryRejectsMalformedNumericExclusiveStartKey() {
|
||||
String numericTable = TABLE + "-numeric";
|
||||
request("DynamoDB_20120810.CreateTable", """
|
||||
{
|
||||
"TableName":"%s",
|
||||
"AttributeDefinitions":[{"AttributeName":"pk","AttributeType":"N"}],
|
||||
"KeySchema":[{"AttributeName":"pk","KeyType":"HASH"}],
|
||||
"BillingMode":"PAY_PER_REQUEST"
|
||||
}
|
||||
""".formatted(numericTable))
|
||||
.statusCode(200);
|
||||
|
||||
request("DynamoDB_20120810.Query", """
|
||||
{
|
||||
"TableName":"%s",
|
||||
"KeyConditionExpression":"pk = :pk",
|
||||
"ExpressionAttributeValues":{":pk":{"N":"1"}},
|
||||
"ExclusiveStartKey":{"pk":{"N":"not-a-number"}}
|
||||
}
|
||||
""".formatted(numericTable))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
request("DynamoDB_20120810.DeleteTable", """
|
||||
{"TableName":"%s"}
|
||||
""".formatted(numericTable))
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void queryRejectsWrongIndexExclusiveStartKeyType() {
|
||||
request("DynamoDB_20120810.Query", """
|
||||
{
|
||||
"TableName":"%s",
|
||||
"IndexName":"status-index",
|
||||
"KeyConditionExpression":"#status = :status",
|
||||
"ExpressionAttributeNames":{"#status":"status"},
|
||||
"ExpressionAttributeValues":{":status":{"S":"open"}},
|
||||
"ExclusiveStartKey":{
|
||||
"pk":{"S":"p1"},
|
||||
"sk":{"S":"s1"},
|
||||
"status":{"S":"open"},
|
||||
"createdAt":{"N":"1"}
|
||||
}
|
||||
}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo("The provided starting key is invalid"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void deleteTable() {
|
||||
|
||||
Reference in new issue
Block a user