mirror of
https://github.com/floci-io/floci.git
synced 2026-12-02 17:58:05 -05:00
fix(dynamodb): throw ValidationException when list_append operand is not a list type (#1702)
* fix(dynamodb): throw ValidationException when list_append operand is not a list type list_append silently no-oped when either operand resolved to a non-list attribute (e.g. NULL type), returning HTTP 200 with the item unchanged. AWS returns a 400 ValidationException in this case. * test(dynamodb): add integration test for list_append against missing attribute
This commit is contained in:
1 parent
b245632a2e
commit
2a9ab4598f
3 files changed
+188
-9
No files matched your search
+124
@@ -1236,6 +1236,130 @@ class DynamoDbIntegrationTest {
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateItemListAppendAgainstNullAttributeReturnsValidationException() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "NullListAppendTable",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "NullListAppendTable",
|
||||
"Item": {"pk": {"S": "row-1"}, "Tags": {"NULL": true}}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.UpdateItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "NullListAppendTable",
|
||||
"Key": {"pk": {"S": "row-1"}},
|
||||
"UpdateExpression": "SET #t = list_append(#t, :new)",
|
||||
"ExpressionAttributeNames": {"#t": "Tags"},
|
||||
"ExpressionAttributeValues": {":new": {"L": [{"S": "tag-a"}]}}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "NullListAppendTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateItemListAppendAgainstMissingAttributeReturnsValidationException() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "MissingListAppendTable",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "MissingListAppendTable",
|
||||
"Item": {"pk": {"S": "row-1"}}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.UpdateItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "MissingListAppendTable",
|
||||
"Key": {"pk": {"S": "row-1"}},
|
||||
"UpdateExpression": "SET #t = list_append(#t, :new)",
|
||||
"ExpressionAttributeNames": {"#t": "Tags"},
|
||||
"ExpressionAttributeValues": {":new": {"L": [{"S": "tag-a"}]}}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "MissingListAppendTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(29)
|
||||
void deleteElementsFromStringSet() {
|
||||
|
||||
@@ -1076,6 +1076,55 @@ class DynamoDbServiceTest {
|
||||
assertEquals("b", stored.get("items").get("L").get(1).get("S").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listAppendAgainstNullAttributeThrowsValidationException() {
|
||||
String region = "eu-west-1";
|
||||
createUsersTable(region);
|
||||
|
||||
ObjectNode existing = mapper.createObjectNode();
|
||||
existing.set("userId", attributeValue("S", "u-null-list"));
|
||||
ObjectNode nullAttr = mapper.createObjectNode();
|
||||
nullAttr.put("NULL", true);
|
||||
existing.set("tags", nullAttr);
|
||||
service.putItem("Users", existing, region);
|
||||
|
||||
ObjectNode key = item("userId", "u-null-list");
|
||||
ObjectNode exprValues = mapper.createObjectNode();
|
||||
exprValues.set(":new", listAttributeValue("tag-a"));
|
||||
|
||||
ObjectNode exprNames = mapper.createObjectNode();
|
||||
exprNames.put("#t", "tags");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.updateItem("Users", key, null,
|
||||
"SET #t = list_append(#t, :new)",
|
||||
exprNames, exprValues, null, region));
|
||||
assertEquals("ValidationException", ex.getErrorCode());
|
||||
assertTrue(ex.getMessage().contains("An operand in the update expression has an incorrect data type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listAppendAgainstMissingAttributeThrowsValidationException() {
|
||||
String region = "eu-west-1";
|
||||
createUsersTable(region);
|
||||
|
||||
service.putItem("Users", item("userId", "u-no-tags"), region);
|
||||
|
||||
ObjectNode key = item("userId", "u-no-tags");
|
||||
ObjectNode exprValues = mapper.createObjectNode();
|
||||
exprValues.set(":new", listAttributeValue("tag-a"));
|
||||
|
||||
ObjectNode exprNames = mapper.createObjectNode();
|
||||
exprNames.put("#t", "tags");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.updateItem("Users", key, null,
|
||||
"SET #t = list_append(#t, :new)",
|
||||
exprNames, exprValues, null, region));
|
||||
assertEquals("ValidationException", ex.getErrorCode());
|
||||
assertTrue(ex.getMessage().contains("The provided expression refers to an attribute that does not exist in the item"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanContainsOnListWithNumericElements() {
|
||||
String region = "eu-west-1";
|
||||
|
||||
Reference in new issue
Block a user