mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -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
+3
-2
@@ -817,11 +817,12 @@ class DynamoDbConformanceChangesTest {
|
||||
|
||||
@Test @Order(101)
|
||||
void reservedWordWithAliasPasses() {
|
||||
// Using #status alias should work fine
|
||||
// Using the #st alias should work fine. The alias must be referenced by the
|
||||
// expression: AWS rejects ExpressionAttributeNames entries left unused.
|
||||
assertThatCode(() -> ddb.putItem(r -> r
|
||||
.tableName(TABLE)
|
||||
.item(Map.of("pk", av("rw-alias"), "sk", av("s"), "status", av("ok")))
|
||||
.conditionExpression("attribute_not_exists(pk)")
|
||||
.conditionExpression("attribute_not_exists(#st)")
|
||||
.expressionAttributeNames(Map.of("#st", "status"))))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user