mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): reject every mix of expression and non-expression parameters in Query and Scan (#5619)
This commit is contained in:
1 parent
988991033f
commit
804335d071
3 files changed
+76
-35
No files matched your search
+4
-4
@@ -947,9 +947,8 @@ class DynamoDbIntegrationTest {
|
||||
.body("""
|
||||
{
|
||||
"TableName": "TestTable",
|
||||
"KeyConditionExpression": "pk = :pk",
|
||||
"ExpressionAttributeValues": {
|
||||
":pk": {"S": "user-1"}
|
||||
"KeyConditions": {
|
||||
"pk": {"ComparisonOperator": "EQ", "AttributeValueList": [{"S": "user-1"}]}
|
||||
},
|
||||
"Select": "SPECIFIC_ATTRIBUTES",
|
||||
"AttributesToGet": ["pk", "sk"]
|
||||
@@ -1106,7 +1105,8 @@ class DynamoDbIntegrationTest {
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo("Can not use both expression and non-expression parameters in the same request: "
|
||||
+ "Non-expression parameters: {AttributesToGet} Expression parameters: {ProjectionExpression}"));
|
||||
+ "Non-expression parameters: {AttributesToGet} "
|
||||
+ "Expression parameters: {ProjectionExpression, KeyConditionExpression}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+50
@@ -1183,6 +1183,56 @@ class NativeDynamoDbJsonHandlerTest {
|
||||
+ "when choosing to get ALL_PROJECTED_ATTRIBUTES", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryListsEveryMixedParameter() {
|
||||
AwsException ex = expectValidationException("Query", json("""
|
||||
{"TableName": "Users", "KeyConditionExpression": "userId = :u",
|
||||
"ExpressionAttributeValues": {":u": {"S": "a"}},
|
||||
"KeyConditions": {"userId": {"ComparisonOperator": "EQ", "AttributeValueList": [{"S": "a"}]}},
|
||||
"FilterExpression": "attribute_exists(x)", "ProjectionExpression": "userId",
|
||||
"AttributesToGet": ["userId"], "ConditionalOperator": "AND",
|
||||
"QueryFilter": {"x": {"ComparisonOperator": "NOT_NULL"}}}
|
||||
"""));
|
||||
assertEquals("Can not use both expression and non-expression parameters in the same request: "
|
||||
+ "Non-expression parameters: {AttributesToGet, QueryFilter, ConditionalOperator, KeyConditions} "
|
||||
+ "Expression parameters: {ProjectionExpression, FilterExpression, KeyConditionExpression}",
|
||||
ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryAllowsAFilterExpressionWithKeyConditions() throws Exception {
|
||||
createUsersTable("eu-west-1");
|
||||
|
||||
Response response = handler.handle("Query", json("""
|
||||
{"TableName": "Users",
|
||||
"KeyConditions": {"userId": {"ComparisonOperator": "EQ", "AttributeValueList": [{"S": "a"}]}},
|
||||
"FilterExpression": "attribute_exists(x)"}
|
||||
"""), "eu-west-1");
|
||||
assertEquals(200, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanListsEveryMixedParameter() {
|
||||
AwsException ex = expectValidationException("Scan", json("""
|
||||
{"TableName": "Users", "FilterExpression": "attribute_exists(x)",
|
||||
"ProjectionExpression": "userId", "AttributesToGet": ["userId"],
|
||||
"ConditionalOperator": "AND", "ScanFilter": {"x": {"ComparisonOperator": "NOT_NULL"}}}
|
||||
"""));
|
||||
assertEquals("Can not use both expression and non-expression parameters in the same request: "
|
||||
+ "Non-expression parameters: {AttributesToGet, ScanFilter, ConditionalOperator} "
|
||||
+ "Expression parameters: {ProjectionExpression, FilterExpression}", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanReportsTheLimitBeforeMixedParameters() {
|
||||
AwsException ex = expectValidationException("Scan", json("""
|
||||
{"TableName": "Users", "Limit": 0, "FilterExpression": "attribute_exists(x)",
|
||||
"ScanFilter": {"x": {"ComparisonOperator": "NOT_NULL"}}}
|
||||
"""));
|
||||
assertEquals("1 validation error detected: Value at 'Limit' failed to satisfy constraint: "
|
||||
+ "Member must have value greater than or equal to 1", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanAcceptsSegmentsAtTheBounds() throws Exception {
|
||||
createUsersTable("eu-west-1");
|
||||
|
||||
Reference in new issue
Block a user