mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(appsync): validate type updates before mutation (#8129)
Reject an invalid type format before changing the stored definition. Keep validation inside the existing synchronized update operation. Cover the refused request through service and AWS SDK tests, including unchanged get/list responses and a subsequent successful valid update. Signed-off-by: Andre Kurait <akurait@amazon.com> Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> Co-authored-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
1 parent
5da8045bb2
commit
5d1d626cbe
4 files changed
+85
-3
No files matched your search
@@ -542,6 +542,12 @@
|
||||
<version>${aws.sdk.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>appsync</artifactId>
|
||||
<version>${aws.sdk.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>ssm</artifactId>
|
||||
|
||||
@@ -616,9 +616,16 @@ public class AppSyncService {
|
||||
public synchronized AppSyncType updateType(String apiId, String typeName, Map<String, Object> request) {
|
||||
assertSchemaNotBusy(apiId);
|
||||
AppSyncType existing = getType(apiId, typeName);
|
||||
if (request.containsKey("definition")) existing.setDefinition((String) request.get("definition"));
|
||||
if (request.containsKey("description")) existing.setDescription((String) request.get("description"));
|
||||
if (request.containsKey("format")) existing.setFormat(parseEnum(TypeFormat.class, request.get("format")));
|
||||
TypeFormat format = request.containsKey("format") ? parseEnum(TypeFormat.class, request.get("format")) : null;
|
||||
if (request.containsKey("definition")) {
|
||||
existing.setDefinition((String) request.get("definition"));
|
||||
}
|
||||
if (request.containsKey("description")) {
|
||||
existing.setDescription((String) request.get("description"));
|
||||
}
|
||||
if (request.containsKey("format")) {
|
||||
existing.setFormat(format);
|
||||
}
|
||||
typeStore.put(apiKey(apiId, typeName), existing);
|
||||
return existing;
|
||||
}
|
||||
|
||||
@@ -705,4 +705,18 @@ class AppSyncServiceTest {
|
||||
assertEquals(SchemaCreationStatusType.PROCESSING,
|
||||
svc.getSchemaCreationStatus(api.getApiId()).getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidTypeFormatLeavesTheStoredDefinitionUnchanged() {
|
||||
GraphqlApi api = service.createGraphqlApi(
|
||||
Map.of("name", "types", "authenticationType", "API_KEY"), "us-east-1");
|
||||
service.createType(api.getApiId(), Map.of("name", "Item", "definition", "type Item { id: ID }", "format", "SDL"));
|
||||
|
||||
AwsException refused = assertThrows(AwsException.class, () -> service.updateType(api.getApiId(), "Item",
|
||||
Map.of("definition", "type Item { changed: ID }", "format", "BOGUS")));
|
||||
|
||||
assertEquals("BadRequestException", refused.getErrorCode());
|
||||
assertEquals("type Item { id: ID }", service.getType(api.getApiId(), "Item").getDefinition());
|
||||
assertEquals("SDL", service.getType(api.getApiId(), "Item").getFormat().name());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package io.floci.aws.services.appsync;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.appsync.AppSyncClient;
|
||||
import software.amazon.awssdk.services.appsync.model.AuthenticationType;
|
||||
import software.amazon.awssdk.services.appsync.model.BadRequestException;
|
||||
import software.amazon.awssdk.services.appsync.model.Type;
|
||||
import software.amazon.awssdk.services.appsync.model.TypeDefinitionFormat;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@QuarkusTest
|
||||
class AppSyncUpdateTypeIntegrationTest {
|
||||
|
||||
@Test
|
||||
void rejectedFormatPreservesTheTypeAndValidUpdateStillSucceeds() {
|
||||
try (AppSyncClient client = AwsTestClients.create(
|
||||
AppSyncClient.builder(), "741648700015", Region.US_EAST_1)) {
|
||||
String apiId = client.createGraphqlApi(request -> request.name("type-update-" + UUID.randomUUID())
|
||||
.authenticationType(AuthenticationType.API_KEY)).graphqlApi().apiId();
|
||||
try {
|
||||
String original = "type Item { id: ID }";
|
||||
String replacement = "type Item { changed: ID }";
|
||||
client.createType(request -> request.apiId(apiId).definition(original).format(TypeDefinitionFormat.SDL));
|
||||
Type stored = client.getType(request -> request.apiId(apiId).typeName("Item")
|
||||
.format(TypeDefinitionFormat.SDL)).type();
|
||||
|
||||
BadRequestException refused = assertThrows(BadRequestException.class,
|
||||
() -> client.updateType(request -> request.apiId(apiId).typeName("Item")
|
||||
.definition(replacement).format("BOGUS")));
|
||||
|
||||
assertEquals(400, refused.statusCode());
|
||||
assertEquals(stored, client.getType(request -> request.apiId(apiId).typeName("Item")
|
||||
.format(TypeDefinitionFormat.SDL)).type());
|
||||
assertEquals(original, client.listTypes(request -> request.apiId(apiId).format(TypeDefinitionFormat.SDL))
|
||||
.types().getFirst().definition());
|
||||
|
||||
Type updated = client.updateType(request -> request.apiId(apiId).typeName("Item")
|
||||
.definition(replacement).format(TypeDefinitionFormat.SDL)).type();
|
||||
assertEquals(replacement, updated.definition());
|
||||
assertEquals(TypeDefinitionFormat.SDL, updated.format());
|
||||
assertEquals(updated, client.getType(request -> request.apiId(apiId).typeName("Item")
|
||||
.format(TypeDefinitionFormat.SDL)).type());
|
||||
} finally {
|
||||
client.deleteGraphqlApi(request -> request.apiId(apiId));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user