mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): refuse unknown functions and unused SearchVectors names (#9305)
SearchVectors now refuses unused ExpressionAttributeNames and ExpressionAttributeValues, and runs every check that needs no table, the 4 KB expression size limits included, before it looks up the table, in DynamoDB's order. Every condition expression now refuses an unknown function name with DynamoDB's message, the name as written, so ATTRIBUTE_EXISTS(a) is refused like nope(a). Function names are not keywords, so size = :v reads size as an attribute name. The Step Functions putItem, updateItem, deleteItem and scan tasks, which skip the handler, get the same check.
This commit is contained in:
1 parent
c650bc098b
commit
99fa7b404e
13 files changed
+382
-84
No files matched your search
@@ -5974,6 +5974,47 @@ given()
|
||||
deleteTable("SyntaxTable");
|
||||
}
|
||||
|
||||
@Test
|
||||
void functionNamesWithoutParenthesesAreAttributeNames() {
|
||||
createOnDemandTableForGsiUpdates("FunctionNameAttributesTable");
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "FunctionNameAttributesTable",
|
||||
"Item": {"pk": {"S": "a"}, "size": {"N": "2"}, "attribute_exists": {"S": "a"}}}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
List<String> filters = List.of(
|
||||
"\"FilterExpression\": \"size = :v\", \"ExpressionAttributeValues\": {\":v\": {\"N\": \"2\"}}",
|
||||
"\"FilterExpression\": \"attribute_exists = :s\", \"ExpressionAttributeValues\": {\":s\": {\"S\": \"a\"}}",
|
||||
"\"FilterExpression\": \"attribute_exists(size)\"");
|
||||
for (String filter : filters) {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.Scan")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("{\"TableName\": \"FunctionNameAttributesTable\", " + filter + "}")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Count", equalTo(1));
|
||||
}
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "FunctionNameAttributesTable", "Item": {"pk": {"S": "a"}},
|
||||
"ConditionExpression": "size = :v", "ExpressionAttributeValues": {":v": {"N": "2"}}}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
deleteTable("FunctionNameAttributesTable");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', quoteCharacter = '`', textBlock = """
|
||||
Query | {"TableName": "ConditionOrderTable", "KeyConditionExpression": "begins_with(sk, :n) AND pk = :missing", "ExpressionAttributeValues": {":n": {"N": "1"}}} | Invalid KeyConditionExpression: Incorrect operand type for operator or function; operator or function: begins_with, operand type: N
|
||||
@@ -5985,6 +6026,16 @@ given()
|
||||
Scan | {"TableName": "ConditionOrderTable", "FilterExpression": "attribute_exists(:v)", "ExpressionAttributeValues": {":v": {"N": "3"}}} | Invalid FilterExpression: Operator or function requires a document path; operator or function: attribute_exists
|
||||
PutItem | {"TableName": "ConditionOrderTable", "Item": {"pk": {"S": "a"}}, "ConditionExpression": "attribute_exists(x, :v)", "ExpressionAttributeValues": {":v": {"N": "3"}}} | 1 validation error detected: Invalid ConditionExpression: Incorrect number of operands for operator or function; operator or function: attribute_exists, number of operands: 2
|
||||
PutItem | {"TableName": "ConditionOrderTable", "Item": {"pk": {"S": "a"}}, "ConditionExpression": "attribute_exists(:v)", "ExpressionAttributeValues": {":v": {"N": "3"}}} | 1 validation error detected: Invalid ConditionExpression: Operator or function requires a document path; operator or function: attribute_exists
|
||||
Scan | {"TableName": "ConditionOrderTable", "FilterExpression": "nope(x)"} | Invalid FilterExpression: Invalid function name; function: nope
|
||||
Scan | {"TableName": "ConditionOrderTable", "FilterExpression": "ATTRIBUTE_EXISTS(x)"} | Invalid FilterExpression: Invalid function name; function: ATTRIBUTE_EXISTS
|
||||
Scan | {"TableName": "ConditionOrderTable", "FilterExpression": "Begins_With(x, :v)", "ExpressionAttributeValues": {":v": {"S": "a"}}} | Invalid FilterExpression: Invalid function name; function: Begins_With
|
||||
Scan | {"TableName": "ConditionOrderTable", "FilterExpression": "nope()"} | Invalid FilterExpression: Syntax error; token: ")", near: "()"
|
||||
Scan | {"TableName": "ConditionOrderTable", "FilterExpression": "nope(x) AND y < :missing"} | Invalid FilterExpression: Invalid function name; function: nope
|
||||
Scan | {"TableName": "ConditionOrderTable", "FilterExpression": "y < :missing AND nope(x)"} | Invalid FilterExpression: An expression attribute value used in expression is not defined; attribute value: :missing
|
||||
Scan | {"TableName": "ConditionOrderTable", "FilterExpression": "x = nope(y)"} | Invalid FilterExpression: Invalid function name; function: nope
|
||||
PutItem | {"TableName": "ConditionOrderTable", "Item": {"pk": {"S": "a"}}, "ConditionExpression": "nope(x)"} | 1 validation error detected: Invalid ConditionExpression: Invalid function name; function: nope
|
||||
PutItem | {"TableName": "ConditionOrderTable", "Item": {"pk": {"S": "a"}}, "ConditionExpression": "ATTRIBUTE_EXISTS(x)"} | 1 validation error detected: Invalid ConditionExpression: Invalid function name; function: ATTRIBUTE_EXISTS
|
||||
Query | {"TableName": "ConditionOrderTable", "KeyConditionExpression": "pk = :k AND BEGINS_WITH(sk, :c)", "ExpressionAttributeValues": {":k": {"S": "a"}, ":c": {"S": "b"}}} | Invalid KeyConditionExpression: Invalid function name; function: BEGINS_WITH
|
||||
""")
|
||||
void expressionErrorsComeFromTheFirstFailingConditionInWrittenOrder(String operation, String body, String message) {
|
||||
createOnDemandTableForGsiUpdates("ConditionOrderTable");
|
||||
|
||||
@@ -492,6 +492,19 @@ class DynamoDbServiceTest {
|
||||
assertThrows(AwsException.class, () -> service.describeTable("NonExistent", "eu-west-1"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', textBlock = """
|
||||
nope(userId) | nope
|
||||
ATTRIBUTE_EXISTS(userId) | ATTRIBUTE_EXISTS
|
||||
""")
|
||||
void putItemRefusesAnUnknownConditionFunctionWithoutTheHandler(String condition, String function) {
|
||||
createUsersTable("us-east-1");
|
||||
AwsException exception = assertThrows(AwsException.class, () -> service.putItem("Users",
|
||||
item("userId", "u1"), condition, null, null, "us-east-1", "NONE"));
|
||||
assertEquals("Invalid ConditionExpression: Invalid function name; function: " + function,
|
||||
exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyReplicaUpdatesRejectsBlankRegion() {
|
||||
createUsersTable("us-east-1");
|
||||
@@ -1164,8 +1177,8 @@ class DynamoDbServiceTest {
|
||||
|
||||
@Test
|
||||
void scanOfEmptyTableDoesNotReadFilterExpression() {
|
||||
// Callers that skip the handler's validation (the Step Functions scan integration)
|
||||
// only see a malformed FilterExpression once an item is evaluated.
|
||||
// The handler and the typed backend check the FilterExpression before the scan,
|
||||
// so the scan reads it only once an item is evaluated.
|
||||
String region = "eu-west-1";
|
||||
createUsersTable(region);
|
||||
|
||||
|
||||
+140
@@ -1138,6 +1138,13 @@ class DynamoDbVectorSearchIntegrationTest {
|
||||
+ "function; operator or function: " + function + ", number of operands: 2";
|
||||
}
|
||||
|
||||
private static String invalidFunction(String name) {
|
||||
return "Invalid SearchConditionExpression: Invalid function name; function: " + name;
|
||||
}
|
||||
|
||||
private static final String RESERVED_NAME = "Invalid SearchConditionExpression: Attribute name is a "
|
||||
+ "reserved keyword; reserved keyword: name";
|
||||
|
||||
private static String operandType(String op, String type) {
|
||||
return "Invalid SearchConditionExpression: Incorrect operand type for operator or function; "
|
||||
+ "operator or function: " + op + ", operand type: " + type;
|
||||
@@ -1270,6 +1277,26 @@ class DynamoDbVectorSearchIntegrationTest {
|
||||
operandType("<", "BOOL")),
|
||||
Arguments.of("full", "tenant = :t AND attribute_exists(:p)", EXISTS_NEEDS_PATH),
|
||||
Arguments.of("full", "tenant = :t AND attribute_exists(size(price))", EXISTS_NEEDS_PATH),
|
||||
Arguments.of("full", "tenant = :t AND nope(category)", invalidFunction("nope")),
|
||||
Arguments.of("full", "tenant = :t AND ATTRIBUTE_EXISTS(price)", invalidFunction("ATTRIBUTE_EXISTS")),
|
||||
Arguments.of("full", "tenant = :t AND SIZE(category) = :p", invalidFunction("SIZE")),
|
||||
Arguments.of("full", "tenant = :t AND name(category)", invalidFunction("name")),
|
||||
Arguments.of("full", "tenant = :t AND nope(:c)", invalidFunction("nope")),
|
||||
Arguments.of("full", "tenant = :t AND category = nope(price)", invalidFunction("nope")),
|
||||
Arguments.of("full", "tenant = :t AND nope(category) IN (:c)", invalidFunction("nope")),
|
||||
Arguments.of("full", "tenant = :t AND nope(price) BETWEEN :n2 AND :n4", invalidFunction("nope")),
|
||||
Arguments.of("full", "tenant = :t AND attribute_exists(nope(category))", invalidFunction("nope")),
|
||||
Arguments.of("full", "tenant = :t AND nope(category) = :missing", invalidFunction("nope")),
|
||||
Arguments.of("full", "tenant = :t AND size(nope(:missing)) = :p",
|
||||
"Invalid SearchConditionExpression: An expression attribute value used in "
|
||||
+ "expression is not defined; attribute value: :missing"),
|
||||
Arguments.of("full", "tenant = :t AND nope(name)", RESERVED_NAME),
|
||||
Arguments.of("full", "tenant = :t AND begins_with(category, :a) AND nope(category)",
|
||||
invalidFunction("nope")),
|
||||
Arguments.of("full", "tenant = :t AND category < :bool AND nope(category)", operandType("<", "BOOL")),
|
||||
Arguments.of("full", "tenant = :t AND nope(category) AND category < :bool", invalidFunction("nope")),
|
||||
Arguments.of("full", "tenant = :t AND nope()",
|
||||
"Invalid SearchConditionExpression: Syntax error; token: \")\", near: \"()\""),
|
||||
Arguments.of("full", "tenant = :t AND tenant = :u AND zz = :z", HASH_ONCE),
|
||||
Arguments.of("full", "zz = :z AND tenant = :t AND tenant = :u", HASH_ONCE),
|
||||
Arguments.of("full", "tenant = :t AND tenant = :p", HASH_ONCE),
|
||||
@@ -1324,4 +1351,117 @@ class DynamoDbVectorSearchIntegrationTest {
|
||||
""".formatted(expression, valuesFor(expression))), message);
|
||||
}
|
||||
|
||||
private static final String UNUSED_VALUE_X = "Value provided in ExpressionAttributeValues unused in "
|
||||
+ "expressions: keys: {:x}";
|
||||
private static final String UNUSED_NAME_X = "Value provided in ExpressionAttributeNames unused in "
|
||||
+ "expressions: keys: {#x}";
|
||||
private static final String EMPTY_NAMES = "ExpressionAttributeNames must not be empty";
|
||||
private static final String EMPTY_VALUES = "ExpressionAttributeValues must not be empty";
|
||||
private static final String VALUES_NEED_EXPRESSION = "ExpressionAttributeValues can only be "
|
||||
+ "specified when using expressions";
|
||||
private static final String NAMES_NEED_EXPRESSION = "ExpressionAttributeNames can only be "
|
||||
+ "specified when using expressions";
|
||||
private static final String UNDEFINED_ZZ = "Invalid ProjectionExpression: An expression attribute "
|
||||
+ "name used in the document path is not defined; attribute name: #zz";
|
||||
private static final String MISSING_TABLE = "VectorNoSuchFilterTable";
|
||||
private static final String TENANT_EQUALS = "\"tenant = :t\"";
|
||||
private static final String T_VALUES = "{\":t\": {\"S\": \"t1\"}}";
|
||||
private static final String TX_VALUES = "{\":t\": {\"S\": \"t1\"}, \":x\": {\"S\": \"x\"}}";
|
||||
private static final String X_VALUES = "{\":x\": {\"S\": \"x\"}}";
|
||||
private static final String X_NAMES = "{\"#x\": \"x\"}";
|
||||
private static final String CX_NAMES = "{\"#c\": \"category\", \"#x\": \"x\"}";
|
||||
private static final String C_NAMES = "{\"#c\": \"category\"}";
|
||||
private static final String LONG_CONDITION = "\"tenant = :t" + " ".repeat(4086) + "\"";
|
||||
private static final String DEEP_CONDITION = "\"" + "NOT ".repeat(25000) + "tenant = :t\"";
|
||||
private static final String LONG_PROJECTION = "\"category" + " ".repeat(4089) + "\"";
|
||||
private static final String CONDITION_TOO_LONG = "Invalid SearchConditionExpression: Expression size "
|
||||
+ "has exceeded the maximum allowed size;";
|
||||
private static final String PROJECTION_TOO_LONG = "Invalid ProjectionExpression: Expression size has "
|
||||
+ "exceeded the maximum allowed size;";
|
||||
|
||||
private static String members(String condition, String values, String names, String projection) {
|
||||
StringBuilder members = new StringBuilder();
|
||||
if (condition != null) {
|
||||
members.append(",\n\"SearchConditionExpression\": ").append(condition);
|
||||
}
|
||||
if (values != null) {
|
||||
members.append(",\n\"ExpressionAttributeValues\": ").append(values);
|
||||
}
|
||||
if (names != null) {
|
||||
members.append(",\n\"ExpressionAttributeNames\": ").append(names);
|
||||
}
|
||||
if (projection != null) {
|
||||
members.append(",\n\"ProjectionExpression\": ").append(projection);
|
||||
}
|
||||
return members.toString();
|
||||
}
|
||||
|
||||
static Stream<Arguments> searchChecksBeforeTheTableLookup() {
|
||||
return Stream.of(
|
||||
Arguments.of(FILTERS, members(TENANT_EQUALS, TX_VALUES, null, null), UNUSED_VALUE_X),
|
||||
Arguments.of(FILTERS, members(TENANT_EQUALS, T_VALUES, X_NAMES, null), UNUSED_NAME_X),
|
||||
Arguments.of(FILTERS, members(TENANT_EQUALS, TX_VALUES, X_NAMES, null), UNUSED_NAME_X),
|
||||
Arguments.of(FILTERS, members("\"tenant = :t AND attribute_exists(category.x)\"", TX_VALUES,
|
||||
null, null), NESTED),
|
||||
Arguments.of(FILTERS, members("\"attribute_exists(price)\"", X_VALUES, null, null),
|
||||
UNUSED_VALUE_X),
|
||||
Arguments.of(FILTERS, members(TENANT_EQUALS, T_VALUES, CX_NAMES, "\"#c\""), UNUSED_NAME_X),
|
||||
Arguments.of(FILTERS, members(TENANT_EQUALS, null, "{}", null), EMPTY_NAMES),
|
||||
Arguments.of(FILTERS, members("\"tenant = :t AND\"", "{}", null, null), EMPTY_VALUES),
|
||||
Arguments.of(FILTERS, members("\"attribute_exists(price)\"", "{}", "{}", null), EMPTY_NAMES),
|
||||
Arguments.of(FILTERS, members("\"attribute_exists(price)\"", "{}", null, "\"#zz\""),
|
||||
EMPTY_VALUES),
|
||||
Arguments.of(FILTERS, members("\"tenant = :t AND attribute_exists(category.x)\"", T_VALUES,
|
||||
null, "\"#zz\""), UNDEFINED_ZZ),
|
||||
Arguments.of(FILTERS, members("\"tenant = :t AND\"", null, null, "\"a,,b\""),
|
||||
"Invalid ProjectionExpression: Syntax error; token: \",\", near: \",,b\""),
|
||||
Arguments.of(FILTERS, members(null, T_VALUES, null, null), VALUES_NEED_EXPRESSION),
|
||||
Arguments.of(FILTERS, members(null, null, X_NAMES, null), NAMES_NEED_EXPRESSION),
|
||||
Arguments.of(FILTERS, members(null, T_VALUES, X_NAMES, null), NAMES_NEED_EXPRESSION),
|
||||
Arguments.of(FILTERS, members(null, T_VALUES, C_NAMES, "\"#c\""), VALUES_NEED_EXPRESSION),
|
||||
Arguments.of(FILTERS, members(null, T_VALUES, null, "\"#zz\""), VALUES_NEED_EXPRESSION),
|
||||
Arguments.of(FILTERS, members(null, null, CX_NAMES, "\"#c\""), UNUSED_NAME_X),
|
||||
Arguments.of(FILTERS, members(null, null, C_NAMES, "\"#c\""), "SearchConditionExpression "
|
||||
+ "must be provided when SearchSchema has a HASH key"),
|
||||
Arguments.of(MISSING_TABLE, members("\"tenant = :t AND nope(category)\"", T_VALUES, null, null),
|
||||
invalidFunction("nope")),
|
||||
Arguments.of(MISSING_TABLE, members(TENANT_EQUALS, TX_VALUES, null, null), UNUSED_VALUE_X),
|
||||
Arguments.of(MISSING_TABLE, members(TENANT_EQUALS, T_VALUES, null, "\"#zz\""), UNDEFINED_ZZ),
|
||||
Arguments.of(MISSING_TABLE, members("\"attribute_exists(price)\"", "{}", null, null),
|
||||
EMPTY_VALUES),
|
||||
Arguments.of(MISSING_TABLE, members(null, T_VALUES, null, null), VALUES_NEED_EXPRESSION),
|
||||
Arguments.of(MISSING_TABLE, members(LONG_CONDITION, T_VALUES, null, null), CONDITION_TOO_LONG),
|
||||
Arguments.of(MISSING_TABLE, members(DEEP_CONDITION, T_VALUES, null, null), CONDITION_TOO_LONG),
|
||||
Arguments.of(MISSING_TABLE, members(TENANT_EQUALS, T_VALUES, null, LONG_PROJECTION),
|
||||
PROJECTION_TOO_LONG),
|
||||
Arguments.of(MISSING_TABLE, members(LONG_CONDITION, T_VALUES, null, LONG_PROJECTION),
|
||||
PROJECTION_TOO_LONG),
|
||||
Arguments.of(FILTERS, members(LONG_CONDITION, T_VALUES, null, "\"#zz\""), UNDEFINED_ZZ),
|
||||
Arguments.of(FILTERS, members(LONG_CONDITION, "{}", null, null), EMPTY_VALUES));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0}: {2}")
|
||||
@Order(50)
|
||||
@MethodSource("searchChecksBeforeTheTableLookup")
|
||||
void searchVectorsChecksTheExpressionsBeforeItLooksUpTheTable(String table, String extraMembers,
|
||||
String message) {
|
||||
expectValidation("SearchVectors", search(table, "full", 10, extraMembers), message);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(51)
|
||||
void searchVectorsAcceptsAProjectionThatUsesANameAlias() throws Exception {
|
||||
JsonNode response = json("SearchVectors", search(FILTERS, "full", 10,
|
||||
members(TENANT_EQUALS, T_VALUES, C_NAMES, "\"#c\"")));
|
||||
assertFalse(response.path("SearchResults").isEmpty());
|
||||
boolean projected = false;
|
||||
for (JsonNode result : response.path("SearchResults")) {
|
||||
List<String> attributes = new ArrayList<>();
|
||||
result.path("Item").fieldNames().forEachRemaining(attributes::add);
|
||||
assertTrue(List.of("category").containsAll(attributes));
|
||||
projected |= !attributes.isEmpty();
|
||||
}
|
||||
assertTrue(projected);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -81,10 +81,11 @@ class ExpressionEvaluatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void functionTokens() {
|
||||
void functionNamesAreIdentifiers() {
|
||||
List<ExpressionEvaluator.Token> tokens = ExpressionEvaluator.tokenize("attribute_exists(a) AND begins_with(b, :v) AND contains(c, :w) AND size(d) > :x AND attribute_not_exists(e)");
|
||||
List<String> functions = tokens.stream()
|
||||
.filter(t -> t.type() == ExpressionEvaluator.TokenType.FUNCTION)
|
||||
.filter(t -> t.type() == ExpressionEvaluator.TokenType.IDENTIFIER)
|
||||
.filter(t -> ExpressionEvaluator.CONDITION_FUNCTIONS.contains(t.value()))
|
||||
.map(ExpressionEvaluator.Token::value)
|
||||
.toList();
|
||||
assertEquals(List.of("attribute_exists", "begins_with", "contains", "size", "attribute_not_exists"), functions);
|
||||
@@ -123,6 +124,20 @@ class ExpressionEvaluatorTest {
|
||||
assertInstanceOf(ExpressionEvaluator.CompareExpr.class, expr);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownFunctionNameParsesAsACallNamedAsWritten() {
|
||||
ExpressionEvaluator.FunctionCallExpr call = assertInstanceOf(
|
||||
ExpressionEvaluator.FunctionCallExpr.class, ExpressionEvaluator.parse("nope(a)"));
|
||||
assertEquals("nope", call.functionName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void functionNamesAreCaseSensitive() {
|
||||
ExpressionEvaluator.FunctionCallExpr call = assertInstanceOf(
|
||||
ExpressionEvaluator.FunctionCallExpr.class, ExpressionEvaluator.parse("ATTRIBUTE_EXISTS(a)"));
|
||||
assertEquals("ATTRIBUTE_EXISTS", call.functionName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void andExpression() {
|
||||
ExpressionEvaluator.Expr expr = ExpressionEvaluator.parse("a = :a AND b = :b");
|
||||
@@ -270,6 +285,20 @@ class ExpressionEvaluatorTest {
|
||||
return mapper.readTree(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
void sizeCanSitLeftOfBetween() throws Exception {
|
||||
JsonNode i = item("{\"a\": {\"S\": \"abc\"}}");
|
||||
JsonNode v = values("{\":lo\": {\"N\": \"2\"}, \":hi\": {\"N\": \"4\"}}");
|
||||
assertTrue(ExpressionEvaluator.matches("size(a) BETWEEN :lo AND :hi", i, null, v));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sizeCanSitLeftOfIn() throws Exception {
|
||||
JsonNode i = item("{\"a\": {\"S\": \"abc\"}}");
|
||||
JsonNode v = values("{\":n\": {\"N\": \"3\"}}");
|
||||
assertTrue(ExpressionEvaluator.matches("size(a) IN (:n)", i, null, v));
|
||||
}
|
||||
|
||||
// DynamoDB's size() of a Binary is its length in bytes; "AQID" encodes the three bytes 1, 2, 3.
|
||||
@Test
|
||||
void sizeOfABinaryCountsItsBytes() throws Exception {
|
||||
|
||||
@@ -29,6 +29,8 @@ import io.floci.aws.services.kinesis.KinesisService;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -160,6 +162,23 @@ class DynamoDbNativeBackendTest {
|
||||
assertTrue(backend.findTable(SCOPE, TABLE).isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', textBlock = """
|
||||
attribute_not_exist(id) | attribute_not_exist
|
||||
NOT attribute_exist(id) | attribute_exist
|
||||
ATTRIBUTE_EXISTS(id) | ATTRIBUTE_EXISTS
|
||||
""")
|
||||
void typedScanRefusesAnUnknownFilterFunction(String filter, String function) throws Exception {
|
||||
createTable("");
|
||||
backend.putItem(SCOPE, TABLE, json("{\"id\":{\"S\":\"k\"}}"), null, null, null);
|
||||
|
||||
AwsException refused = assertThrows(AwsException.class,
|
||||
() -> backend.scan(SCOPE, TABLE, filter, null, null, null, null, null));
|
||||
|
||||
assertEquals("ValidationException", refused.getErrorCode());
|
||||
assertEquals("Invalid FilterExpression: Invalid function name; function: " + function, refused.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void typedUpdateItemReturnsOnlyTheRequestedImage() throws Exception {
|
||||
backend.createTable(SCOPE, TABLE, List.of(new KeySchemaElement("id", "HASH")),
|
||||
|
||||
Reference in new issue
Block a user