mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): drop the table name from the PartiQL missing table error, and treat a CREATING table as missing (#7158)
This commit is contained in:
1 parent
e77823feed
commit
89ecb594e1
5 files changed
+77
-13
No files matched your search
+25
@@ -8,6 +8,8 @@ import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
@@ -599,6 +601,29 @@ class DynamoDbPartiQLIntegrationTest {
|
||||
.body("Responses[0].Error.Message", equalTo(notWellFormed));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@Order(29)
|
||||
@ValueSource(strings = {
|
||||
"SELECT * FROM \"%s\" WHERE pk = 'x'",
|
||||
"SELECT * FROM \"%s\".\"gsi\" WHERE pk = 'x'",
|
||||
"INSERT INTO \"%s\" VALUE {'pk': 'x'}",
|
||||
"UPDATE \"%s\" SET a = 1 WHERE pk = 'x'",
|
||||
"DELETE FROM \"%s\" WHERE pk = 'x'",
|
||||
"FROM \"%s\" WHERE pk = 'x' SET c = 1"})
|
||||
void aStatementOnAMissingTableIsRefusedWithoutTheTableName(String statement) {
|
||||
String partiql = statement.formatted(TABLE + "-never-created");
|
||||
|
||||
statement(partiql)
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"))
|
||||
.body("message", equalTo("Requested resource not found"));
|
||||
request("DynamoDB_20120810.BatchExecuteStatement",
|
||||
"{\"Statements\":[{\"Statement\":\"" + partiql.replace("\"", "\\\"") + "\"}]}")
|
||||
.statusCode(200)
|
||||
.body("Responses[0].Error.Code", equalTo("ResourceNotFound"))
|
||||
.body("Responses[0].Error.Message", equalTo("Requested resource not found"));
|
||||
}
|
||||
|
||||
private static void putItem(String pk, String attributes) {
|
||||
request("DynamoDB_20120810.PutItem", """
|
||||
{"TableName":"%s","Item":{"pk":{"S":"%s"},%s}}
|
||||
|
||||
+35
@@ -16,6 +16,8 @@ import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
@@ -2533,6 +2535,39 @@ class NativeDynamoDbJsonHandlerTest {
|
||||
assertEquals("Requested resource not found", ex.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"SELECT * FROM \"Users\".\"TitleIndex\" WHERE userId = 'u1'",
|
||||
"INSERT INTO \"Users\" VALUE {'userId': 1}",
|
||||
"UPDATE \"Users\" SET a = 1 WHERE userId = 1",
|
||||
"DELETE FROM \"Users\" WHERE nope = 'u1'"})
|
||||
void executeStatementAnswersResourceNotFoundForACreatingTableBeforeTheKeyCheck(String statement) {
|
||||
createUsersTable("eu-west-1").setTableStatus("CREATING");
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("Statement", statement);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> handler.handle("ExecuteStatement", request, "eu-west-1"));
|
||||
assertEquals("ResourceNotFoundException", ex.getErrorCode());
|
||||
assertEquals("Requested resource not found", ex.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"SELECT * FROM \"Users\" WHERE userId = 'u1'",
|
||||
"UPDATE \"Users\" SET a = 1 WHERE userId = 'u1'"})
|
||||
void executeTransactionCancelsOnACreatingTable(String statement) throws Exception {
|
||||
createUsersTable("eu-west-1").setTableStatus("CREATING");
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.putArray("TransactStatements").addObject().put("Statement", statement);
|
||||
|
||||
Response response = handler.handle("ExecuteTransaction", request, "eu-west-1");
|
||||
assertEquals(400, response.getStatus());
|
||||
JsonNode reason = mapper.convertValue(response.getEntity(), JsonNode.class).get("CancellationReasons").get(0);
|
||||
assertEquals("ResourceNotFound", reason.get("Code").asText());
|
||||
assertEquals("Requested resource not found", reason.get("Message").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void transactWriteItemsFailsTheRequestOnAnEmptyKeyAheadOfAKeyMismatch() {
|
||||
createUsersTable("eu-west-1");
|
||||
|
||||
Reference in new issue
Block a user