mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(dynamodb): reject QueryFilter with KeyConditionExpression (#2935)
* fix(dynamodb): reject QueryFilter with key expression * test(dynamodb): keep QueryFilter test legacy
This commit is contained in:
1 parent
de6bf8f599
commit
7d693de663
4 files changed
+59
-4
No files matched your search
+4
-2
@@ -547,8 +547,10 @@ class DynamoDbConformanceChangesTest {
|
||||
void queryWithQueryFilter() {
|
||||
QueryResponse resp = ddb.query(QueryRequest.builder()
|
||||
.tableName(TABLE)
|
||||
.keyConditionExpression("pk = :pk")
|
||||
.expressionAttributeValues(Map.of(":pk", av("p1")))
|
||||
.keyConditions(Map.of("pk", Condition.builder()
|
||||
.comparisonOperator(ComparisonOperator.EQ)
|
||||
.attributeValueList(av("p1"))
|
||||
.build()))
|
||||
.queryFilter(Map.of("name", Condition.builder()
|
||||
.comparisonOperator(ComparisonOperator.EQ)
|
||||
.attributeValueList(av("Item-0"))
|
||||
|
||||
@@ -707,8 +707,9 @@ describe('DynamoDB — Phase 10: Legacy API', () => {
|
||||
it('QueryFilter (legacy) filters query results', async () => {
|
||||
const resp = await ddb.send(new QueryCommand({
|
||||
TableName: table,
|
||||
KeyConditionExpression: 'pk = :pk',
|
||||
ExpressionAttributeValues: { ':pk': s('p1') },
|
||||
KeyConditions: {
|
||||
pk: { ComparisonOperator: 'EQ', AttributeValueList: [s('p1')] },
|
||||
},
|
||||
QueryFilter: {
|
||||
name: { ComparisonOperator: 'EQ', AttributeValueList: [s('Item-0')] },
|
||||
},
|
||||
@@ -717,6 +718,23 @@ describe('DynamoDB — Phase 10: Legacy API', () => {
|
||||
expect(resp.Items![0].name.S).toBe('Item-0');
|
||||
});
|
||||
|
||||
it('QueryFilter and KeyConditionExpression are mutually exclusive', async () => {
|
||||
const err = await ddb.send(new QueryCommand({
|
||||
TableName: table,
|
||||
KeyConditionExpression: 'pk = :pk',
|
||||
ExpressionAttributeValues: { ':pk': s('p1') },
|
||||
QueryFilter: {
|
||||
name: { ComparisonOperator: 'EQ', AttributeValueList: [s('Item-0')] },
|
||||
},
|
||||
})).catch(e => e);
|
||||
|
||||
expect(err.name).toBe('ValidationException');
|
||||
expect(err.message).toBe(
|
||||
'Can not use both expression and non-expression parameters in the same request: '
|
||||
+ 'Non-expression parameters: {QueryFilter} Expression parameters: {KeyConditionExpression}',
|
||||
);
|
||||
});
|
||||
|
||||
it('ScanFilter (legacy) filters scan results', async () => {
|
||||
const resp = await ddb.send(new ScanCommand({
|
||||
TableName: table,
|
||||
|
||||
@@ -826,6 +826,11 @@ public class DynamoDbJsonHandler {
|
||||
"Can not use both expression and non-expression parameters in the same request: "
|
||||
+ "Non-expression parameters: {KeyConditions} Expression parameters: {KeyConditionExpression}", 400);
|
||||
}
|
||||
if (keyConditionExpr != null && queryFilter != null) {
|
||||
throw new AwsException("ValidationException",
|
||||
"Can not use both expression and non-expression parameters in the same request: "
|
||||
+ "Non-expression parameters: {QueryFilter} Expression parameters: {KeyConditionExpression}", 400);
|
||||
}
|
||||
if (filterExpr != null && queryFilter != null) {
|
||||
throw new AwsException("ValidationException",
|
||||
"Can not use both expression and non-expression parameters in the same request: "
|
||||
|
||||
+30
@@ -491,6 +491,36 @@ class DynamoDbIntegrationTest {
|
||||
+ "Non-expression parameters: {AttributesToGet} Expression parameters: {ProjectionExpression}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void queryWithQueryFilterAndKeyConditionExpressionFails() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.Query")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "TestTable",
|
||||
"KeyConditionExpression": "pk = :pk",
|
||||
"ExpressionAttributeValues": {
|
||||
":pk": {"S": "user-1"}
|
||||
},
|
||||
"QueryFilter": {
|
||||
"name": {
|
||||
"ComparisonOperator": "EQ",
|
||||
"AttributeValueList": [{"S": "Alice"}]
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.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: {QueryFilter} Expression parameters: {KeyConditionExpression}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void queryWithBeginsWith() {
|
||||
|
||||
Reference in new issue
Block a user