mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(appsync): keep GraphQL APIs and custom domain names in their Region (#8745)
This commit is contained in:
1 parent
1942378624
commit
f0c234485b
23 files changed
+526
-138
No files matched your search
@@ -394,6 +394,22 @@ class RegionResolverTest {
|
||||
assertEquals("eu-west-1", resolver.resolveRegionFromAuth(header));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStoredResourcesRegionIsTheOneItsArnNamesOrTheDefault() {
|
||||
assertEquals("eu-west-1", resolver.regionOf("arn:aws:appsync:eu-west-1:000000000000:apis/abc"));
|
||||
// Records stored without an ARN, or with one that names no Region, count as the default Region's.
|
||||
assertEquals("us-east-1", resolver.regionOf(null));
|
||||
assertEquals("us-east-1", resolver.regionOf("arn:aws:iam::000000000000:role/r"));
|
||||
assertEquals("us-east-1", resolver.regionOf("not-an-arn"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void outsideARequestOnlyTheDefaultRegionsResourcesAreInTheRequestsRegion() {
|
||||
assertTrue(resolver.inRequestRegion("arn:aws:appsync:us-east-1:000000000000:apis/abc"));
|
||||
assertTrue(resolver.inRequestRegion(null));
|
||||
assertFalse(resolver.inRequestRegion("arn:aws:appsync:eu-west-1:000000000000:apis/abc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void regionFromAuthWithAShortDateStaysDefault() {
|
||||
String header = "AWS4-HMAC-SHA256 Credential=AKID/2026021/eu-west-1/s3/aws4_request";
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.Base64;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
@@ -130,13 +131,22 @@ class RequestRegionArnIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("graphqlApi.apiId");
|
||||
// A namespace lives in its API's region, even when the request is signed for another one.
|
||||
// A namespace lives in its API's Region, the only Region that reaches the API.
|
||||
given()
|
||||
.header("Authorization", auth(OTHER_REGION, "appsync"))
|
||||
.contentType("application/json")
|
||||
.body("{\"name\": \"region-arn-ns\"}")
|
||||
.when()
|
||||
.post("/v2/apis/" + apiId + "/channelNamespaces")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
given()
|
||||
.header("Authorization", auth("appsync"))
|
||||
.contentType("application/json")
|
||||
.body("{\"name\": \"region-arn-ns\"}")
|
||||
.when()
|
||||
.post("/v2/apis/" + apiId + "/channelNamespaces")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("channelNamespace.channelNamespaceArn", startsWith("arn:aws:appsync:" + REGION + ":"));
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.floci.aws.services.appsync;
|
||||
import io.floci.aws.services.appsync.graphql.AppSyncErrorFormatter;
|
||||
import io.floci.aws.services.appsync.graphql.SchemaCreationWorker;
|
||||
import io.floci.aws.services.appsync.graphql.SchemaRegistry;
|
||||
import io.floci.aws.testing.AppSyncRequests;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.floci.aws.testing.SidecarContainersProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
@@ -12,13 +13,11 @@ import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -47,7 +46,7 @@ class AppSyncExecutionIntegrationTest {
|
||||
apiId = createApi("exec-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
apiKey = createApiKey(apiId);
|
||||
startSchema(apiId, "type Query { hello: String }");
|
||||
awaitSchemaSuccess(apiId);
|
||||
AppSyncRequests.awaitSchemaSuccess(apiId, AUTH);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -246,7 +245,7 @@ class AppSyncExecutionIntegrationTest {
|
||||
String multiApi = createApi("multi-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
String multiKey = createApiKey(multiApi);
|
||||
startSchema(multiApi, "type Query { hello(id: String): String }");
|
||||
awaitSchemaSuccess(multiApi);
|
||||
AppSyncRequests.awaitSchemaSuccess(multiApi, AUTH);
|
||||
|
||||
given()
|
||||
.header("x-api-key", multiKey)
|
||||
@@ -273,7 +272,7 @@ class AppSyncExecutionIntegrationTest {
|
||||
type Query { hello: String }
|
||||
type Subscription { onHello: String }
|
||||
""");
|
||||
awaitSchemaSuccess(subApi);
|
||||
AppSyncRequests.awaitSchemaSuccess(subApi, AUTH);
|
||||
|
||||
given()
|
||||
.header("x-api-key", subKey)
|
||||
@@ -295,7 +294,7 @@ class AppSyncExecutionIntegrationTest {
|
||||
String scalarApi = createApi("scalar-lit-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
String scalarKey = createApiKey(scalarApi);
|
||||
startSchema(scalarApi, "type Query { echo(t: AWSDateTime): AWSDateTime }");
|
||||
awaitSchemaSuccess(scalarApi);
|
||||
AppSyncRequests.awaitSchemaSuccess(scalarApi, AUTH);
|
||||
|
||||
given()
|
||||
.header("x-api-key", scalarKey)
|
||||
@@ -326,7 +325,7 @@ class AppSyncExecutionIntegrationTest {
|
||||
String scalarApi = createApi("scalar-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
String scalarKey = createApiKey(scalarApi);
|
||||
startSchema(scalarApi, "type Query { echo(t: AWSDateTime): AWSDateTime }");
|
||||
awaitSchemaSuccess(scalarApi);
|
||||
AppSyncRequests.awaitSchemaSuccess(scalarApi, AUTH);
|
||||
|
||||
given()
|
||||
.header("x-api-key", scalarKey)
|
||||
@@ -367,7 +366,7 @@ class AppSyncExecutionIntegrationTest {
|
||||
String protectedApi = createApi("protected-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
String protectedKey = createApiKey(protectedApi);
|
||||
startSchema(protectedApi, "type Query { hello: String secret: String @aws_iam }");
|
||||
awaitSchemaSuccess(protectedApi);
|
||||
AppSyncRequests.awaitSchemaSuccess(protectedApi, AUTH);
|
||||
|
||||
given()
|
||||
.header("x-api-key", protectedKey)
|
||||
@@ -397,7 +396,7 @@ class AppSyncExecutionIntegrationTest {
|
||||
String hydrateApi = createApi("hydrate-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
String hydrateKey = createApiKey(hydrateApi);
|
||||
startSchema(hydrateApi, "type Query { hello: String }");
|
||||
awaitSchemaSuccess(hydrateApi);
|
||||
AppSyncRequests.awaitSchemaSuccess(hydrateApi, AUTH);
|
||||
|
||||
schemaRegistry.remove(hydrateApi);
|
||||
assertTrue(schemaRegistry.getSdl(hydrateApi).isEmpty());
|
||||
@@ -470,19 +469,4 @@ class AppSyncExecutionIntegrationTest {
|
||||
.statusCode(200)
|
||||
.body("status", equalTo("PROCESSING"));
|
||||
}
|
||||
|
||||
private static void awaitSchemaSuccess(String apiId) {
|
||||
await().atMost(Duration.ofSeconds(10))
|
||||
.pollInterval(Duration.ofMillis(25))
|
||||
.until(() -> {
|
||||
String status = given()
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.get("/v1/apis/" + apiId + "/schemacreation")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("status");
|
||||
return "SUCCESS".equals(status);
|
||||
});
|
||||
}
|
||||
}
|
||||
+2
-10
@@ -1,6 +1,7 @@
|
||||
package io.floci.aws.services.appsync;
|
||||
|
||||
import com.fasterxml.jackson.core.io.JsonStringEncoder;
|
||||
import io.floci.aws.testing.AppSyncRequests;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.floci.aws.testing.SidecarContainersProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
@@ -10,11 +11,9 @@ import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -484,7 +483,7 @@ class AppSyncJsResolverDockerIntegrationTest {
|
||||
apiId = createApi("js-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
apiKey = createApiKey(apiId);
|
||||
startSchema(apiId, SCHEMA);
|
||||
awaitSchemaSuccess(apiId);
|
||||
AppSyncRequests.awaitSchemaSuccess(apiId, AUTH);
|
||||
createNoneDataSource(apiId, "local");
|
||||
|
||||
String functionId = createFunction(apiId, "Query_getMessages_0", "local", PIPELINE_FUNCTION);
|
||||
@@ -1007,13 +1006,6 @@ class AppSyncJsResolverDockerIntegrationTest {
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static void awaitSchemaSuccess(String apiId) {
|
||||
await().atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(25)).until(() ->
|
||||
"SUCCESS".equals(given().header("Authorization", AUTH)
|
||||
.when().get("/v1/apis/" + apiId + "/schemacreation")
|
||||
.then().statusCode(200).extract().path("status")));
|
||||
}
|
||||
|
||||
private static void createNoneDataSource(String apiId, String name) {
|
||||
given()
|
||||
.header("Authorization", AUTH)
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package io.floci.aws.services.appsync;
|
||||
|
||||
import io.floci.aws.testing.AppSyncRequests;
|
||||
import io.floci.aws.testing.EnforcementFixtures;
|
||||
import io.floci.aws.testing.PartitionCleanup;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.floci.aws.testing.SidecarContainersProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* A GraphQL API's endpoint names no Region, so a query reaches an API of any Region: one authorized by an API key alone
|
||||
* carries no Region, runs as the default Region's request, and is still answered by an API of another Region, in it.
|
||||
* The answer comes from the API's resolver, which is found only in the API's Region, so a query left in the default
|
||||
* Region would answer {@code null}.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(SidecarContainersProfile.class)
|
||||
class AppSyncRegionDataPlaneIntegrationTest {
|
||||
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final String REGION = "eu-west-1";
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
SidecarContainersProfile.requireDockerAndImage("floci.services.appsync.graphql-image");
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void anApiOfAnotherRegionThanTheDefaultAnswersAQueryThroughItsResolver() {
|
||||
String apiId = in().body("{\"name\":\"west-orders\",\"authenticationType\":\"API_KEY\"}").post("/v1/apis")
|
||||
.then().statusCode(200).extract().path("graphqlApi.apiId");
|
||||
cleanup.register(() -> in().delete("/v1/apis/" + apiId));
|
||||
String key = in().body("{}").post("/v1/apis/" + apiId + "/apikeys").then().statusCode(200)
|
||||
.extract().path("apiKey.id");
|
||||
in().body("{\"definition\":\"type Query { hello: String }\"}").post("/v1/apis/" + apiId + "/schemacreation")
|
||||
.then().statusCode(200);
|
||||
AppSyncRequests.awaitSchemaSuccess(apiId, EnforcementFixtures.auth(ACCOUNT, REGION, "appsync"));
|
||||
in().body("{\"name\":\"local\",\"type\":\"NONE\"}").post("/v1/apis/" + apiId + "/datasources")
|
||||
.then().statusCode(200);
|
||||
in().body("{\"fieldName\":\"hello\",\"dataSourceName\":\"local\",\"requestMappingTemplate\":"
|
||||
+ "\"{\\\"version\\\":\\\"2018-05-29\\\",\\\"payload\\\":\\\"west\\\"}\","
|
||||
+ "\"responseMappingTemplate\":\"$util.toJson($ctx.result)\"}")
|
||||
.post("/v1/apis/" + apiId + "/types/Query/resolvers").then().statusCode(200);
|
||||
|
||||
given().header("x-api-key", key).contentType("application/json").body("{\"query\":\"{ hello }\"}")
|
||||
.post("/v1/apis/" + apiId + "/graphql")
|
||||
.then().statusCode(200).body("errors", nullValue()).body("data.hello", equalTo("west"));
|
||||
}
|
||||
|
||||
private static RequestSpecification in() {
|
||||
return AppSyncRequests.signed(ACCOUNT, REGION);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package io.floci.aws.services.appsync;
|
||||
|
||||
import io.floci.aws.testing.AppSyncRequests;
|
||||
import io.floci.aws.testing.PartitionCleanup;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* A GraphQL API and a custom domain name are Regional, as on AWS: each is listed and reached only in the Region it was
|
||||
* created in, and so are an API's data sources and API keys. Another Region's is answered for as one that doesn't
|
||||
* exist: {@code NotFoundException}, and an empty list of its resources. Each test works in an account of its own.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class AppSyncRegionScopingIntegrationTest {
|
||||
|
||||
private static final AtomicLong ACCOUNTS = new AtomicLong(733100000000L);
|
||||
private static final String HOME = "eu-west-1";
|
||||
private static final String OTHER = "eu-central-1";
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
private String account;
|
||||
|
||||
@BeforeEach
|
||||
void accountOfItsOwn() {
|
||||
account = Long.toString(ACCOUNTS.incrementAndGet());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anApiAndItsResourcesAreListedAndReachedOnlyInItsRegion() {
|
||||
String apiId = in(HOME).body("{\"name\":\"orders\",\"authenticationType\":\"API_KEY\"}").post("/v1/apis")
|
||||
.then().statusCode(200).body("graphqlApi.arn", startsWith("arn:aws:appsync:" + HOME + ":"))
|
||||
.extract().path("graphqlApi.apiId");
|
||||
cleanup.register(() -> in(HOME).delete("/v1/apis/" + apiId));
|
||||
String apis = "/v1/apis/" + apiId;
|
||||
in(HOME).body("{\"name\":\"none_ds\",\"type\":\"NONE\"}").post(apis + "/datasources").then().statusCode(200);
|
||||
String keyId = in(HOME).body("{}").post(apis + "/apikeys").then().statusCode(200).extract().path("apiKey.id");
|
||||
|
||||
in(OTHER).get("/v1/apis").then().statusCode(200).body("graphqlApis.apiId", not(hasItem(apiId)));
|
||||
notFound(in(OTHER).get(apis));
|
||||
in(OTHER).get(apis + "/datasources").then().statusCode(200).body("dataSources", empty());
|
||||
notFound(in(OTHER).get(apis + "/datasources/none_ds"));
|
||||
notFound(in(OTHER).body("{\"name\":\"other_ds\",\"type\":\"NONE\"}").post(apis + "/datasources"));
|
||||
in(OTHER).get(apis + "/apikeys").then().statusCode(200).body("apiKeys", empty());
|
||||
notFound(in(OTHER).delete(apis));
|
||||
|
||||
in(HOME).get("/v1/apis").then().statusCode(200).body("graphqlApis.apiId", hasItem(apiId));
|
||||
in(HOME).get(apis + "/datasources/none_ds").then().statusCode(200);
|
||||
in(HOME).get(apis + "/apikeys").then().statusCode(200).body("apiKeys.id", hasItem(keyId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aDomainNameIsListedAndReachedOnlyInItsRegion() {
|
||||
String name = "api-" + UUID.randomUUID().toString().substring(0, 8) + ".example.com";
|
||||
in(HOME).body("{\"domainName\":\"" + name + "\",\"certificateArn\":\"arn:aws:acm:us-east-1:" + account
|
||||
+ ":certificate/abc\"}").post("/v1/domainnames").then().statusCode(200)
|
||||
.body("domainNameConfig.domainNameArn", startsWith("arn:aws:appsync:" + HOME + ":"));
|
||||
cleanup.register(() -> in(HOME).delete("/v1/domainnames/" + name));
|
||||
|
||||
in(OTHER).get("/v1/domainnames").then().statusCode(200)
|
||||
.body("domainNameConfigs.domainName", not(hasItem(name)));
|
||||
notFound(in(OTHER).get("/v1/domainnames/" + name));
|
||||
notFound(in(OTHER).delete("/v1/domainnames/" + name));
|
||||
|
||||
in(HOME).get("/v1/domainnames").then().statusCode(200).body("domainNameConfigs.domainName", hasItem(name));
|
||||
in(HOME).get("/v1/domainnames/" + name).then().statusCode(200).body("domainNameConfig.domainName", equalTo(name));
|
||||
}
|
||||
|
||||
private RequestSpecification in(String region) {
|
||||
return AppSyncRequests.signed(account, region);
|
||||
}
|
||||
|
||||
private static void notFound(Response response) {
|
||||
response.then().statusCode(404).body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,12 @@ public final class AppSyncServiceFixture {
|
||||
}
|
||||
|
||||
public static AppSyncService create(Clock clock) {
|
||||
return create(clock, "http://localhost:4566", "us-east-1", null,
|
||||
return create(clock, "us-east-1");
|
||||
}
|
||||
|
||||
/** As above, answering for {@code region}, as a request there does: an API of another Region isn't found. */
|
||||
public static AppSyncService create(Clock clock, String region) {
|
||||
return create(clock, "http://localhost:4566", region, null,
|
||||
AccountAwareStorageBackend.inMemory("000000000000"), null,
|
||||
mock(SchemaRegistry.class), new LambdaAuthorizerCache());
|
||||
}
|
||||
|
||||
@@ -527,6 +527,9 @@ class AppSyncServiceTest {
|
||||
"cn-north-1, aws-cn",
|
||||
"us-isob-east-1, aws-iso-b"})
|
||||
void tagResourceAcceptsAnApiArnFromAnyPartition(String region, String partition) {
|
||||
// The service answers for the Region of the API, as a request tagging it there does.
|
||||
this.region = region;
|
||||
service = newService(Clock.fixed(NOW, ZoneOffset.UTC));
|
||||
GraphqlApi api = service.createGraphqlApi(
|
||||
Map.of("name", "p-" + region, "authenticationType", "API_KEY"), region);
|
||||
String apiArn = "arn:" + partition + ":appsync:" + region + ":000000000000:apis/" + api.getApiId();
|
||||
|
||||
@@ -3,6 +3,8 @@ package io.floci.aws.services.cloudcontrol;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.aws.testing.AppSyncRequests;
|
||||
import io.floci.aws.testing.EnforcementFixtures;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.parsing.Parser;
|
||||
@@ -276,6 +278,36 @@ class CloudControlIntegrationTest {
|
||||
assertThat(body, containsString(identifier));
|
||||
}
|
||||
|
||||
/**
|
||||
* A resource is created and deleted in the Region the request is signed for, where its service then finds it: an
|
||||
* AppSync API outside the default Region gets the environment variables its create sets with a second call, and
|
||||
* the delete removes it.
|
||||
*/
|
||||
@Test
|
||||
void aResourceIsCreatedAndDeletedInTheRequestsRegion() throws InterruptedException {
|
||||
String ct = "application/x-amz-json-1.0";
|
||||
String account = "333333333333";
|
||||
String region = "eu-west-1";
|
||||
String auth = EnforcementFixtures.auth(account, region, "cloudcontrol");
|
||||
String token = given().config(config().encoderConfig(encoderConfig().encodeContentTypeAs(ct, TEXT)))
|
||||
.contentType(ct).header("Authorization", auth)
|
||||
.header("X-Amz-Target", "CloudApiService.CreateResource")
|
||||
.body("{\"TypeName\":\"AWS::AppSync::GraphQLApi\",\"DesiredState\":\"{\\\"Name\\\":\\\"regional\\\","
|
||||
+ "\\\"AuthenticationType\\\":\\\"API_KEY\\\","
|
||||
+ "\\\"EnvironmentVariables\\\":{\\\"STAGE\\\":\\\"eu\\\"}}\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().path("ProgressEvent.RequestToken");
|
||||
|
||||
String apiId = awaitIdentifier(token, ct, auth);
|
||||
assertNotNull(apiId, "the create succeeds");
|
||||
|
||||
AppSyncRequests.signed(account, region).get("/v1/apis/" + apiId + "/environmentVariables")
|
||||
.then().statusCode(200).body("environmentVariables.STAGE", equalTo("eu"));
|
||||
|
||||
deleteThroughCloudControl(ct, auth, "AWS::AppSync::GraphQLApi", apiId, "SUCCESS");
|
||||
AppSyncRequests.signed(account, region).get("/v1/apis/" + apiId).then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteResourceReportsFailureWhenItWouldSilentlyNoOp() {
|
||||
String ct = "application/x-amz-json-1.0";
|
||||
@@ -301,10 +333,14 @@ class CloudControlIntegrationTest {
|
||||
}
|
||||
|
||||
private void deleteThroughCloudControl(String ct, String auth, String identifier, String status) {
|
||||
deleteThroughCloudControl(ct, auth, "AWS::EC2::VPC", identifier, status);
|
||||
}
|
||||
|
||||
private void deleteThroughCloudControl(String ct, String auth, String typeName, String identifier, String status) {
|
||||
given().config(config().encoderConfig(encoderConfig().encodeContentTypeAs(ct, TEXT)))
|
||||
.contentType(ct).header("Authorization", auth)
|
||||
.header("X-Amz-Target", "CloudApiService.DeleteResource")
|
||||
.body("{\"TypeName\":\"AWS::EC2::VPC\",\"Identifier\":\"" + identifier + "\"}")
|
||||
.body("{\"TypeName\":\"" + typeName + "\",\"Identifier\":\"" + identifier + "\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("ProgressEvent.OperationStatus", equalTo(status));
|
||||
}
|
||||
|
||||
+4
-2
@@ -1240,7 +1240,8 @@ class AppSyncCfnProvisionerTest {
|
||||
void aRollbackThatTheServiceRefusesLeavesTheApiKeyAsTheUpdateLeftItAndKeepsTheSnapshot() throws Exception {
|
||||
Instant start = Instant.parse("2026-01-01T00:00:00Z");
|
||||
AppSyncServiceFixture.MutableClock clock = new AppSyncServiceFixture.MutableClock(start);
|
||||
AppSyncService real = AppSyncServiceFixture.create(clock);
|
||||
// CloudFormation provisions in its stack's Region, eu-west-1 here, and the service answers for it.
|
||||
AppSyncService real = AppSyncServiceFixture.create(clock, "eu-west-1");
|
||||
AppSyncCfnProvisioner onRealService = new AppSyncCfnProvisioner(real);
|
||||
GraphqlApi created = real.createGraphqlApi(Map.of("name", "keys", "authenticationType", "API_KEY"), "eu-west-1");
|
||||
long soonExpiry = start.getEpochSecond() + Duration.ofHours(25).getSeconds();
|
||||
@@ -1267,7 +1268,8 @@ class AppSyncCfnProvisionerTest {
|
||||
|
||||
@Test
|
||||
void aSnapshotThatIsNotJsonFailsTheRollbackNamingTheResourceAndChangesNothing() {
|
||||
AppSyncService real = AppSyncServiceFixture.create(Clock.fixed(Instant.parse("2026-01-01T00:00:00Z"), ZoneOffset.UTC));
|
||||
AppSyncService real = AppSyncServiceFixture.create(
|
||||
Clock.fixed(Instant.parse("2026-01-01T00:00:00Z"), ZoneOffset.UTC), "eu-west-1");
|
||||
AppSyncCfnProvisioner onRealService = new AppSyncCfnProvisioner(real);
|
||||
GraphqlApi created = real.createGraphqlApi(Map.of("name", "corrupt", "authenticationType", "API_KEY"), "eu-west-1");
|
||||
real.createDataSource(created.getApiId(), Map.of("name", "ds", "type", "NONE", "description", "kept"), "eu-west-1");
|
||||
|
||||
@@ -44,10 +44,10 @@ class ElastiCacheQueryHandlerTest {
|
||||
void setUp() {
|
||||
SigV4Validator sigV4Validator = mock(SigV4Validator.class);
|
||||
service = mock(ElastiCacheService.class);
|
||||
// Every record these tests describe belongs to the request's Region.
|
||||
when(service.inRequestRegion(any())).thenReturn(true);
|
||||
memcachedService = mock(ElastiCacheMemcachedService.class);
|
||||
RegionResolver regionResolver = mock(RegionResolver.class);
|
||||
// Every record these tests describe belongs to the request's Region.
|
||||
when(regionResolver.inRequestRegion(any())).thenReturn(true);
|
||||
when(regionResolver.getRegion()).thenReturn("us-east-1");
|
||||
when(regionResolver.getDefaultRegion()).thenReturn("us-east-1");
|
||||
when(regionResolver.getAccountId()).thenReturn("000000000000");
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.floci.aws.testing;
|
||||
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
|
||||
/** AppSync control-plane requests signed for an account and a Region, over the test's RestAssured port. */
|
||||
public final class AppSyncRequests {
|
||||
|
||||
private AppSyncRequests() {}
|
||||
|
||||
/** A JSON request signed for {@code account} in {@code region}. */
|
||||
public static RequestSpecification signed(String account, String region) {
|
||||
return given()
|
||||
.header("Authorization", EnforcementFixtures.auth(account, region, "appsync"))
|
||||
.contentType("application/json");
|
||||
}
|
||||
|
||||
/** Waits until the schema creation of {@code apiId} has succeeded, its status read with {@code authorization}. */
|
||||
public static void awaitSchemaSuccess(String apiId, String authorization) {
|
||||
await().atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(25)).until(() ->
|
||||
"SUCCESS".equals(given().header("Authorization", authorization)
|
||||
.when().get("/v1/apis/" + apiId + "/schemacreation")
|
||||
.then().statusCode(200).extract().path("status")));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user