mirror of
https://github.com/floci-io/floci.git
synced 2026-12-03 02:07:58 -05:00
fix(dynamodb): reject unused ExpressionAttributeNames/Values on PutItem, DeleteItem, Scan, Query (#2923)
* fix(dynamodb): reject unused ExpressionAttributeNames/Values on PutItem, DeleteItem, Scan, Query The checkUnusedEan / checkUnusedEav helpers were only wired into handleUpdateItem and (names only) handleQuery, so PutItem, DeleteItem and Scan accepted expression attribute entries not referenced by any expression and performed the operation, where AWS returns ValidationException. Query accepted unused values for the same reason. Wire both helpers into handlePutItem, handleDeleteItem and handleScan, and add the missing checkUnusedEav call to handleQuery, each checking against the tokens actually referenced by that operation's expressions. Closes #2893 * fix(dynamodb): also reject unused EAV on legacy KeyConditions + FilterExpression Query Addresses PR review: the unused ExpressionAttributeNames/Values check in handleQuery was gated on KeyConditionExpression != null, so a Query combining legacy KeyConditions with FilterExpression skipped it. Widen the guard to fire whenever any expression parameter (KCE, FilterExpression, ProjectionExpression) is present, and add an integration case for the mixed path. Also replace an em dash in the new test comment per repo style. * test(dynamodb): reference the aliased name in the reserved-word conformance case The sdk-test-node "reserved word aliased via ExpressionAttributeNames passes" case supplied ExpressionAttributeNames {#st: status} on a PutItem whose ConditionExpression (attribute_not_exists(pk)) never referenced #st. Real AWS — and now Floci, per #2893 — rejects unused ExpressionAttributeNames entries with ValidationException. Point the ConditionExpression at #st so the alias is actually used; the reserved-word aliasing behaviour under test is unchanged. * fix(dynamodb): run Query unused EAN/EAV check unconditionally Addresses PR review: the previous guard (keyConditionExpr || filterExpr || projectionExpression) still let a legacy KeyConditions Query carrying a stray ExpressionAttributeNames/Values map through without validation. Drop the guard so the checks always run; the token sets are still derived only from the expressions that can legitimately reference those maps, so a correct request is unaffected. Add an integration case for legacy KeyConditions with no expression parameter. * test(dynamodb): reference the aliased name in the sdk-test-java reserved-word case Mirror of the sdk-test-node fix: reservedWordWithAliasPasses supplied an unused ExpressionAttributeNames {#st: status} on a PutItem whose ConditionExpression referenced pk, which #2893 now correctly rejects. Point the condition at #st. * fix(dynamodb): AWS "can only be specified when using expressions" wording for PutItem/DeleteItem Addresses PR review: when ExpressionAttributeNames/Values is supplied with no expression parameter at all, this PR's new checkUnusedEan/checkUnusedEav calls reported "Value provided in ExpressionAttributeNames unused in expressions: keys: {...}". Real AWS answers that sub-case with "<param> can only be specified when using expressions: ConditionExpression is null" instead. Add rejectExprAttrsWithoutExpression, parameterised on the null-expression message, and wire it into handlePutItem and handleDeleteItem ahead of the unused-alias checks. Both operations only accept ConditionExpression, so the named param is unambiguous; the wording matches the pre-existing PutItem+EAV guard from #826. EAV is checked before EAN to preserve that guard's order. Scan and Query still return the "unused in expressions" 400 for this sub-case: those ops accept multiple expression parameters and AWS's exact wording there is unverified. The helper is parameterised so it is a one-line change per op once the strings are measured.
This commit is contained in:
1 parent
732e009207
commit
262495df67
4 files changed
+393
-20
No files matched your search
+329
@@ -3540,6 +3540,335 @@ given()
|
||||
deleteTable("NullKeyTable");
|
||||
}
|
||||
|
||||
// Reproduces #2893: unused ExpressionAttributeNames/Values must be rejected on
|
||||
// PutItem, DeleteItem, Scan and Query, matching AWS ValidationException behavior.
|
||||
@Test
|
||||
void unusedExpressionAttributesAreRejected() {
|
||||
String tableName = "UnusedExprAttrTable";
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST"
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
// PutItem: unused ExpressionAttributeNames entry
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"Item": {"pk": {"S": "a"}},
|
||||
"ConditionExpression": "attribute_not_exists(pk)",
|
||||
"ExpressionAttributeNames": {"#st": "status"}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("Value provided in ExpressionAttributeNames "
|
||||
+ "unused in expressions: keys: {#st}"));
|
||||
|
||||
// PutItem: unused ExpressionAttributeValues entry
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"Item": {"pk": {"S": "a"}},
|
||||
"ConditionExpression": "attribute_not_exists(pk)",
|
||||
"ExpressionAttributeValues": {":unused": {"S": "x"}}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("Value provided in ExpressionAttributeValues "
|
||||
+ "unused in expressions: keys: {:unused}"));
|
||||
|
||||
// DeleteItem: unused ExpressionAttributeNames entry
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"Key": {"pk": {"S": "a"}},
|
||||
"ConditionExpression": "attribute_exists(pk)",
|
||||
"ExpressionAttributeNames": {"#st": "status"}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("Value provided in ExpressionAttributeNames "
|
||||
+ "unused in expressions: keys: {#st}"));
|
||||
|
||||
// DeleteItem: unused ExpressionAttributeValues entry
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"Key": {"pk": {"S": "a"}},
|
||||
"ConditionExpression": "attribute_exists(pk)",
|
||||
"ExpressionAttributeValues": {":unused": {"S": "x"}}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("Value provided in ExpressionAttributeValues "
|
||||
+ "unused in expressions: keys: {:unused}"));
|
||||
|
||||
// Scan: unused ExpressionAttributeNames entry
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.Scan")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"FilterExpression": "#d = :d",
|
||||
"ExpressionAttributeNames": {"#d": "data", "#st": "status"},
|
||||
"ExpressionAttributeValues": {":d": {"S": "v"}}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("Value provided in ExpressionAttributeNames "
|
||||
+ "unused in expressions: keys: {#st}"));
|
||||
|
||||
// Scan: unused ExpressionAttributeValues entry
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.Scan")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"FilterExpression": "#d = :d",
|
||||
"ExpressionAttributeNames": {"#d": "data"},
|
||||
"ExpressionAttributeValues": {":d": {"S": "v"}, ":unused": {"S": "x"}}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("Value provided in ExpressionAttributeValues "
|
||||
+ "unused in expressions: keys: {:unused}"));
|
||||
|
||||
// Query: unused ExpressionAttributeValues entry
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.Query")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"KeyConditionExpression": "pk = :pk",
|
||||
"ExpressionAttributeValues": {":pk": {"S": "a"}, ":unused": {"S": "x"}}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("Value provided in ExpressionAttributeValues "
|
||||
+ "unused in expressions: keys: {:unused}"));
|
||||
|
||||
// Query: unused ExpressionAttributeNames entry
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.Query")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"KeyConditionExpression": "pk = :pk",
|
||||
"ExpressionAttributeNames": {"#st": "status"},
|
||||
"ExpressionAttributeValues": {":pk": {"S": "a"}}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("Value provided in ExpressionAttributeNames "
|
||||
+ "unused in expressions: keys: {#st}"));
|
||||
|
||||
// Query: legacy KeyConditions combined with FilterExpression, unused EAV entry.
|
||||
// keyConditionExpr is null here, so the check must not be gated on it.
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.Query")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"KeyConditions": {
|
||||
"pk": {"ComparisonOperator": "EQ", "AttributeValueList": [{"S": "a"}]}
|
||||
},
|
||||
"FilterExpression": "#d = :d",
|
||||
"ExpressionAttributeNames": {"#d": "data"},
|
||||
"ExpressionAttributeValues": {":d": {"S": "v"}, ":unused": {"S": "x"}}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("Value provided in ExpressionAttributeValues "
|
||||
+ "unused in expressions: keys: {:unused}"));
|
||||
|
||||
// Query: legacy KeyConditions with no expression parameter at all, stray EAV.
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.Query")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"KeyConditions": {
|
||||
"pk": {"ComparisonOperator": "EQ", "AttributeValueList": [{"S": "a"}]}
|
||||
},
|
||||
"ExpressionAttributeValues": {":unused": {"S": "x"}}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("Value provided in ExpressionAttributeValues "
|
||||
+ "unused in expressions: keys: {:unused}"));
|
||||
|
||||
// Only the unused entries are reported: #used is referenced, #a and #b are not.
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"Item": {"pk": {"S": "a"}},
|
||||
"ConditionExpression": "attribute_not_exists(#used)",
|
||||
"ExpressionAttributeNames": {"#used": "pk", "#a": "x", "#b": "y"}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("Value provided in ExpressionAttributeNames "
|
||||
+ "unused in expressions: keys: {#a, #b}"));
|
||||
|
||||
// No expression parameter at all: AWS reports the alias map "can only be specified
|
||||
// when using expressions", distinct from the "unused in expressions" wording above.
|
||||
// PutItem and DeleteItem only accept ConditionExpression, so it is the named param.
|
||||
|
||||
// PutItem: ExpressionAttributeNames without ConditionExpression
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"Item": {"pk": {"S": "a"}},
|
||||
"ExpressionAttributeNames": {"#st": "status"}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("ExpressionAttributeNames can only be specified "
|
||||
+ "when using expressions: ConditionExpression is null"));
|
||||
|
||||
// PutItem: ExpressionAttributeValues without ConditionExpression (pre-existing guard)
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"Item": {"pk": {"S": "a"}},
|
||||
"ExpressionAttributeValues": {":unused": {"S": "x"}}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("ExpressionAttributeValues can only be specified "
|
||||
+ "when using expressions: ConditionExpression is null"));
|
||||
|
||||
// DeleteItem: ExpressionAttributeNames without ConditionExpression
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"Key": {"pk": {"S": "a"}},
|
||||
"ExpressionAttributeNames": {"#st": "status"}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("ExpressionAttributeNames can only be specified "
|
||||
+ "when using expressions: ConditionExpression is null"));
|
||||
|
||||
// DeleteItem: ExpressionAttributeValues without ConditionExpression; with both maps
|
||||
// present the values message wins, matching the pre-existing PutItem guard order.
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"Key": {"pk": {"S": "a"}},
|
||||
"ExpressionAttributeNames": {"#st": "status"},
|
||||
"ExpressionAttributeValues": {":unused": {"S": "x"}}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ValidationException"))
|
||||
.body("message", equalTo("ExpressionAttributeValues can only be specified "
|
||||
+ "when using expressions: ConditionExpression is null"));
|
||||
|
||||
// Control: fully-referenced expression attributes are still accepted.
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"Item": {"pk": {"S": "a"}, "data": {"S": "v"}},
|
||||
"ConditionExpression": "attribute_not_exists(#p)",
|
||||
"ExpressionAttributeNames": {"#p": "pk"}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
deleteTable(tableName);
|
||||
}
|
||||
|
||||
private void deleteTable(String tableName) {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
|
||||
Reference in new issue
Block a user