fix(cloudformation): return stack IDs before provisioning completes (#7491)

This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-11-04 18:36:23 -04:00
1 parent cfbf86b8a1
commit af0461af91
103 files changed
+917 -51

No files matched your search

@@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Future;
/**
* Handles CloudFormation Query-protocol API calls (form-encoded POST, XML response).
@@ -119,20 +118,23 @@ public class CloudFormationQueryHandler {
List<String> capabilities = extractList(params, "Capabilities.member.");
Map<String, String> tags = extractTags(params);
cfnService.createChangeSet(stackName, "initial-create", "CREATE",
templateBody, templateUrl, parameters, capabilities, tags, region);
awaitExecution(cfnService.executeChangeSet(stackName, "initial-create", region));
if (Boolean.parseBoolean(params.getFirst("EnableTerminationProtection"))) {
// CreateStackInput carries the same member; honor it so the stack is created protected.
cfnService.updateTerminationProtection(stackName, true, region);
boolean terminationProtection = Boolean.parseBoolean(params.getFirst("EnableTerminationProtection"));
ChangeSet initial = cfnService.createChangeSetForCreateStack(stackName, "initial-create",
templateBody, templateUrl, parameters, capabilities, tags, region,
terminationProtection);
try {
cfnService.executeChangeSet(initial.getStackId(), initial.getChangeSetId(), region);
} catch (AwsException e) {
if (terminationProtection) {
cfnService.clearProtectionAfterRejectedCreate(stackName, initial, region);
}
throw e;
}
Stack stack = cfnService.describeStacks(stackName, region).get(0);
String xml = new XmlBuilder()
.start("CreateStackResponse", CF_NS)
.start("CreateStackResult")
.elem("StackId", stack.getStackId())
.elem("StackId", initial.getStackId())
.end("CreateStackResult")
.raw(AwsQueryResponse.responseMetadata())
.end("CreateStackResponse")
@@ -165,13 +167,12 @@ public class CloudFormationQueryHandler {
cfnService.deleteChangeSet(stackName, cs.getChangeSetName(), region);
return xmlError("ValidationError", "No updates are to be performed.", 400);
}
awaitExecution(cfnService.executeChangeSet(stackName, cs.getChangeSetName(), region));
cfnService.executeChangeSet(cs.getStackId(), cs.getChangeSetId(), region);
Stack stack = cfnService.describeStacks(stackName, region).get(0);
String xml = new XmlBuilder()
.start("UpdateStackResponse", CF_NS)
.start("UpdateStackResult")
.elem("StackId", stack.getStackId())
.elem("StackId", cs.getStackId())
.end("UpdateStackResult")
.raw(AwsQueryResponse.responseMetadata())
.end("UpdateStackResponse")
@@ -1134,14 +1135,6 @@ public class CloudFormationQueryHandler {
xml.end("Parameters");
}
private void awaitExecution(Future<?> future) {
try {
future.get();
} catch (Exception e) {
LOG.warnv("Stack execution failed: {0}", e.getMessage());
}
}
private Response xmlError(String code, String message, int status) {
String xml = new XmlBuilder()
.start("ErrorResponse", CF_NS)
@@ -234,6 +234,25 @@ public class CloudFormationService implements ResourceProvider {
return stack;
}
public void clearProtectionAfterRejectedCreate(String stackName, ChangeSet initial, String region) {
String accountId = currentAccount();
stacks.computeIfPresent(stackKey(accountId, stackName, region), (key, stack) -> {
ChangeSet current = stack.getChangeSets().get(initial.getChangeSetName());
if (stack.getStackId().equals(initial.getStackId())
&& "REVIEW_IN_PROGRESS".equals(stack.getStatus())
&& (current == null && stack.getChangeSets().isEmpty()
|| current != null && current.getChangeSetId().equals(initial.getChangeSetId())
&& ("AVAILABLE".equals(current.getExecutionStatus())
|| "UNAVAILABLE".equals(current.getExecutionStatus())))
&& !runningExecutions.containsKey(stack.getStackId())) {
stack.setEnableTerminationProtection(false);
// Keep this rare rejection cleanup ordered before a concurrent delete unpersists it.
persistStack(stack);
}
return stack;
});
}
// ── DescribeStacks ────────────────────────────────────────────────────────
public List<Stack> describeStacks(String stackName, String region) {
@@ -347,7 +366,7 @@ public class CloudFormationService implements ResourceProvider {
}
String previousTemplate = previousTemplateOf(stack);
created = createChangeSet(stackName, changeSetName, "UPDATE", previousTemplate, null,
parameters, capabilities, tags, region, currentAccount(), false, true);
parameters, capabilities, tags, region, currentAccount(), false, true, false);
}
return created;
}
@@ -365,7 +384,17 @@ public class CloudFormationService implements ResourceProvider {
Map<String, String> parameters, List<String> capabilities,
Map<String, String> tags, String region) {
return createChangeSet(stackName, changeSetName, changeSetType, templateBody, templateUrl,
parameters, capabilities, tags, region, regionResolver.getAccountId(), false, false);
parameters, capabilities, tags, region, regionResolver.getAccountId(), false, false, false);
}
public ChangeSet createChangeSetForCreateStack(String stackName, String changeSetName,
String templateBody, String templateUrl,
Map<String, String> parameters, List<String> capabilities,
Map<String, String> tags, String region,
boolean enableTerminationProtection) {
return createChangeSet(stackName, changeSetName, "CREATE", templateBody, templateUrl,
parameters, capabilities, tags, region, regionResolver.getAccountId(), false, false,
enableTerminationProtection);
}
/**
@@ -389,7 +418,7 @@ public class CloudFormationService implements ResourceProvider {
Map<String, String> parameters, List<String> capabilities,
Map<String, String> tags, String region) {
return createChangeSet(stackName, changeSetName, changeSetType, templateBody, templateUrl,
parameters, capabilities, tags, region, regionResolver.getAccountId(), true, false);
parameters, capabilities, tags, region, regionResolver.getAccountId(), true, false, false);
}
/**
@@ -407,14 +436,15 @@ public class CloudFormationService implements ResourceProvider {
Map<String, String> parameters, List<String> capabilities,
Map<String, String> tags, String region, String accountId) {
return createChangeSet(stackName, changeSetName, changeSetType, templateBody, templateUrl,
parameters, capabilities, tags, region, accountId, false, false);
parameters, capabilities, tags, region, accountId, false, false, false);
}
private ChangeSet createChangeSet(String stackName, String changeSetName, String changeSetType,
String templateBody, String templateUrl,
Map<String, String> parameters, List<String> capabilities,
Map<String, String> tags, String region, String accountId,
boolean attachToReviewInProgressStack, boolean fromPreviousTemplate) {
boolean attachToReviewInProgressStack, boolean fromPreviousTemplate,
boolean enableTerminationProtection) {
String resolvedTemplate = resolveTemplate(templateBody, templateUrl);
requireValidTemplate(resolvedTemplate);
boolean isCreateType = "CREATE".equalsIgnoreCase(changeSetType);
@@ -511,6 +541,7 @@ public class CloudFormationService implements ResourceProvider {
target = newStack(stackName,
createdStackId != null ? createdStackId : newStackId(stackName, region, accountId),
region, accountId);
target.setEnableTerminationProtection(enableTerminationProtection);
if (tags != null) target.getTags().putAll(tags);
// A CREATE change set puts a brand-new stack into REVIEW_IN_PROGRESS. Record the
// matching stack-level event (as AWS and LocalStack do) so DescribeStackEvents is
@@ -1289,6 +1320,9 @@ public class CloudFormationService implements ResourceProvider {
cs.setExecutionStatus(status != null && (status.contains("ROLLBACK") || status.endsWith("_FAILED"))
? "EXECUTE_FAILED" : "EXECUTE_COMPLETE");
persistStack(stack);
} catch (RuntimeException | Error e) {
LOG.errorv(e, "Stack {0} execution aborted unexpectedly", stack.getStackName());
throw e;
} finally {
endExecution(stack, claimed.done(), region, accountId);
}
@@ -1322,6 +1356,7 @@ public class CloudFormationService implements ResourceProvider {
}
done.complete(null);
} catch (RuntimeException e) {
LOG.errorv(e, "Stack {0} execution cleanup failed", stack.getStackName());
done.completeExceptionally(e);
}
}
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.core.common;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.github.hectorvent.floci.testing.PartitionMatrix;
import io.github.hectorvent.floci.testing.PartitionMatrix.PartitionCase;
@@ -67,6 +68,8 @@ class PartitionArnMintingIntegrationTest {
.formParam("StackName", stackName)
.when().post("/"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE",
PartitionMatrix.sigV4Auth(region, "cloudformation"));
given()
.header("Authorization", PartitionMatrix.sigV4Auth(region, "cloudformation"))
.contentType("application/x-www-form-urlencoded")
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.autoscaling;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.EnforcementFixtures;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -164,6 +165,7 @@ class AutoScalingLaunchConfigurationMetadataIntegrationTest {
""".formatted(name);
request("cloudformation", "CreateStack").formParam("StackName", name)
.formParam("TemplateBody", template).post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE", EnforcementFixtures.auth(ACCOUNT, "cloudformation"));
} else {
request("autoscaling", "CreateLaunchConfiguration")
.formParam("LaunchConfigurationName", name).formParam("ImageId", "ami-amazonlinux2023")
@@ -205,6 +207,7 @@ class AutoScalingLaunchConfigurationMetadataIntegrationTest {
.formParam("Parameters.member.1.ParameterKey", "Strict")
.formParam("Parameters.member.1.ParameterValue", strict ? "yes" : "no")
.post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE", EnforcementFixtures.auth(ACCOUNT, "cloudformation"));
ValidatableResponse described = describeLaunchConfiguration(name);
if (strict) {
described.body(LAUNCH_CONFIGURATION + ".MetadataOptions.HttpTokens", equalTo("required"))
@@ -206,6 +206,8 @@ class AcmCfnIntegrationTest {
}
private static String describeStacks(String stack, String expectedStatus) {
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stack, CFN_AUTH);
assertEquals(expectedStatus, state.status(), state.reason());
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -60,6 +60,7 @@ class ApiGatewayCfnMockCorsIntegrationTest {
.formParam("TemplateBody", TEMPLATE)
.when().post("/").then().statusCode(200);
try {
CfnStackWaits.awaitStatus(STACK, "CREATE_COMPLETE");
String xml = given().contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
.formParam("StackName", STACK)
@@ -278,6 +278,7 @@ class ApiGatewayDomainCfnIntegrationTest {
}
private static String describeStacks(String stack, String expectedStatus) {
CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -146,6 +146,7 @@ class ApiGatewayGatewayResponseCfnIntegrationTest {
}
private static String describeStacks(String expectedStatus) {
CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -191,6 +191,7 @@ class ApiGatewayUsagePlanCfnIntegrationTest {
}
private static String describeStacks(String expectedStatus) {
CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -505,6 +505,7 @@ class AppSyncCfnIntegrationTest {
}
private static String describeStacks(String stackName, String expectedStatus) {
CfnStackWaits.awaitStatus(stackName, expectedStatus, CFN_AUTH);
return cfn("DescribeStacks", stackName).header("Authorization", CFN_AUTH)
.when().post("/").then().statusCode(200)
.body(containsString("<StackStatus>" + expectedStatus + "</StackStatus>"))
@@ -166,6 +166,8 @@ class AutoScalingScalingPolicyCfnIntegrationTest {
}
private static String describeStacks(String expectedStatus) {
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(STACK, CFN_AUTH);
assertEquals(expectedStatus, state.status(), state.reason());
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
@@ -113,6 +114,7 @@ class AwsIncludeIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -166,6 +168,7 @@ class AwsIncludeIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_FAILED");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -272,6 +275,7 @@ class AwsIncludeIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -377,6 +381,7 @@ class AwsIncludeIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -645,6 +650,7 @@ class AwsIncludeIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -117,6 +117,7 @@ class BackupVaultCfnIntegrationTest {
}
private static String describeStacks(String expectedStatus) {
CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -95,7 +95,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DeleteStack").formParam("StackName", stackName)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStackDeleted(stackName);
CfnStackWaits.awaitStackDeleted(stackName, CFN_AUTH);
}
/**
@@ -114,6 +114,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("TemplateBody", stackWith(body, "probe-q-a-" + suffix))
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200)
@@ -127,6 +128,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("TemplateBody", stackWith(body, "probe-q-b-" + suffix))
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200)
@@ -150,6 +152,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("TemplateBody", stackWith(createBody.replace("SUFFIX", suffix), "probe-q-a-" + suffix))
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String before = namedPhysicalId(stackName);
assertNotNull(before, "no PhysicalResourceId for Named after create");
@@ -158,6 +161,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("TemplateBody", stackWith(updateBody.replace("SUFFIX", suffix), "probe-q-b-" + suffix))
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200)
@@ -333,6 +337,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("Action", "CreateStack").formParam("StackName", stackName)
.formParam("TemplateBody", initialTemplate)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200).body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
@@ -349,6 +354,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("Action", "UpdateStack").formParam("StackName", stackName)
.formParam("TemplateBody", updatedTemplate)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200).body(containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"));
@@ -379,6 +385,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("Action", "CreateStack").formParam("StackName", stackName)
.formParam("TemplateBody", initialTemplate)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200).body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
@@ -447,6 +454,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("Action", "CreateStack").formParam("StackName", stackName)
.formParam("TemplateBody", initialTemplate)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200).body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
@@ -467,6 +475,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("Action", "UpdateStack").formParam("StackName", stackName)
.formParam("TemplateBody", updatedTemplate)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200).body(containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"));
@@ -599,6 +608,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("TemplateBody", initialTemplate)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200)
@@ -609,6 +619,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("TemplateBody", updatedTemplate)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200)
@@ -813,6 +824,7 @@ class CfnUnchangedResourceUpdateIntegrationTest {
.formParam("TemplateBody", initialTemplate)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200)
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -166,6 +167,7 @@ class CloudFormationAccountOwnershipIntegrationTest {
.formParam("StackName", name)
.formParam("TemplateBody", template)
.when().post("/").then().statusCode(200).extract().body().asString();
CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE", auth(account, region));
return body.replaceFirst("(?s).*<StackId>([^<]+)</StackId>.*", "$1");
}
@@ -178,6 +180,7 @@ class CloudFormationAccountOwnershipIntegrationTest {
.formParam("StackName", name)
.formParam("TemplateBody", template)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE", auth(account, region));
}
private static ValidatableResponse describeStack(
@@ -110,6 +110,7 @@ class CloudFormationAsgLaunchTemplateIntegrationTest {
}
private void assertStackCreated(String stackName) {
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
String body = describeStacks(stackName);
assertThat(body, containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
assertThat(body, not(containsString("The specified launch template does not exist.")));
@@ -328,6 +329,7 @@ class CloudFormationAsgLaunchTemplateIntegrationTest {
}
""".formatted(suffix, ltName));
CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE");
assertThat(describeStacks(stackName), containsString("<StackStatus>ROLLBACK_COMPLETE</StackStatus>"));
assertThat(CfnStackWaits.failedResourceReason(stackName, CFN_AUTH),
containsString("Value of property OnDemandBaseCapacity must be an integer."));
@@ -446,6 +448,7 @@ class CloudFormationAsgLaunchTemplateIntegrationTest {
assertEquals("False", asgChange.get("Replacement"));
updateStack(stackName, template2);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
String describe = describeStacks(stackName);
assertThat(describe, containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"));
// ASG must have updated to version 2 because Fn::GetAtt on LatestVersionNumber changed
@@ -569,6 +572,7 @@ class CloudFormationAsgLaunchTemplateIntegrationTest {
assertThat(describeAutoScalingGroup(asgName), containsString("<Version>1</Version>"));
updateStack(stackName, template2);
CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE");
String describe = describeStacks(stackName);
assertThat(describe, containsString("<StackStatus>UPDATE_ROLLBACK_COMPLETE</StackStatus>"));
// ASG must have rolled back to Version 1
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -83,6 +84,7 @@ class CloudFormationAutoScalingIntegrationTest {
.statusCode(200);
// Stack completes and Fn::GetAtt(Asg, Arn) resolves to the real ASG ARN.
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -159,6 +161,7 @@ class CloudFormationAutoScalingIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// Redeploy with a changed DesiredCapacity: LaunchConfiguration is unchanged (immutable, so
// must reconcile to a no-op) and the ASG's capacity must reconcile in place.
given()
@@ -172,6 +175,7 @@ class CloudFormationAutoScalingIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -89,6 +89,7 @@ class CloudFormationBatchIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -171,6 +172,7 @@ class CloudFormationBatchIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -245,6 +247,7 @@ class CloudFormationBatchIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// The update changes only updatable properties, so the entities must be mutated, not
// replaced: the physical ids the outputs carry have to survive it.
given()
@@ -257,6 +260,7 @@ class CloudFormationBatchIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -392,6 +396,7 @@ class CloudFormationBatchIntegrationTest {
}
private static void assertStackStatus(String stackName, String status) {
CfnStackWaits.awaitStatus(stackName, status);
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -130,6 +131,7 @@ class CloudFormationCdkDeployLoopIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -203,6 +205,7 @@ class CloudFormationCdkDeployLoopIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -251,6 +254,7 @@ class CloudFormationCdkDeployLoopIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.AfterEach;
@@ -81,6 +82,7 @@ class CloudFormationChangeSetDiffIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// Same template, only the parameter value changes.
given()
.contentType("application/x-www-form-urlencoded")
@@ -142,6 +144,7 @@ class CloudFormationChangeSetDiffIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// Same template, and the parameter says UsePreviousValue instead of resubmitting its value.
given()
.contentType("application/x-www-form-urlencoded")
@@ -202,6 +205,7 @@ class CloudFormationChangeSetDiffIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// Same template, but the update omits Suffix entirely - real CloudFormation falls back to
// the template Default ("fallback"), which differs from the deployed value ("override").
given()
@@ -262,6 +266,7 @@ class CloudFormationChangeSetDiffIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// Same template, but the update omits Suffix entirely and the template has no Default. An
// update does not carry the deployed value over, so CloudFormation refuses the change set
// rather than preview, or apply, the parameter without a value.
@@ -330,6 +335,7 @@ class CloudFormationChangeSetDiffIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// The update points QueueSuffix at an SSM parameter that was never put. ExecuteChangeSet
// would fail resolving it, but DescribeChangeSet is only a preview - it must not 400 just
// because the current value can't be resolved.
@@ -388,6 +394,7 @@ class CloudFormationChangeSetDiffIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// Byte-identical re-submission of the same SAM source: the deployed template is the
// *expanded* form, so diffing the raw SAM source against it must not report the
// SAM-generated IAM role as removed or the function as modified.
@@ -454,6 +461,7 @@ class CloudFormationChangeSetDiffIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateChangeSet")
@@ -528,6 +536,7 @@ class CloudFormationChangeSetDiffIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// The SSM parameter's value changes in Parameter Store; the referencing template parameter
// (the SSM parameter *name*) is resubmitted unchanged. Real CloudFormation re-resolves the
// SSM value at CreateChangeSet time, so ExecuteChangeSet would apply "two" to the queue —
@@ -610,6 +619,7 @@ class CloudFormationChangeSetDiffIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// Q's definition text is unchanged, but Env flips IsProd from false to true - Q was never
// created, and ExecuteChangeSet would create it now.
given()
@@ -674,6 +684,7 @@ class CloudFormationChangeSetDiffIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// Q's definition text is unchanged, but Env flips IsProd from true to false - Q was created,
// and ExecuteChangeSet would delete it now.
given()
@@ -820,6 +831,7 @@ class CloudFormationChangeSetDiffIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateChangeSet")
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.services.cloudfront.model.KeyGroup;
import io.github.hectorvent.floci.services.cloudfront.model.OriginAccessControl;
import io.github.hectorvent.floci.services.cloudfront.model.PublicKey;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
@@ -112,6 +113,7 @@ class CloudFormationCloudFrontDistributionIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// Stack completes and Fn::GetAtt(Dist, DomainName) resolves to a real *.cloudfront.net domain
// (not the unresolved "Dist.DomainName" token).
given()
@@ -172,6 +174,7 @@ class CloudFormationCloudFrontDistributionIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
Distribution original = distributionsWithAlias(alias).getFirst();
given()
@@ -185,6 +188,7 @@ class CloudFormationCloudFrontDistributionIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
List<Distribution> matching = distributionsWithAlias(alias);
assertEquals(1, matching.size(), "UpdateStack must not leak a second distribution");
Distribution updated = matching.getFirst();
@@ -257,6 +261,7 @@ class CloudFormationCloudFrontDistributionIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus("cfn-cloudfront-private-" + suffix, "CREATE_COMPLETE");
Distribution distribution = distributionsWithAlias(alias).getFirst();
assertEquals(List.of(defaultKeyGroup.getId()),
distribution.getConfig().getDefaultCacheBehavior().getTrustedKeyGroups());
@@ -305,6 +310,7 @@ class CloudFormationCloudFrontDistributionIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE");
// On AWS the stack fails because CloudFront rejects the out-of-range value; the
// service-level check makes the CloudFormation path share that one copy.
given()
@@ -238,10 +238,12 @@ class CloudFormationCloudFrontPoliciesIntegrationTest {
private static void createStack(String stackName, String template) {
stackCall("CreateStack", stackName, template);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
}
private static void updateStack(String stackName, String template) {
stackCall("UpdateStack", stackName, template);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
}
private static void stackCall(String action, String stackName, String template) {
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -60,6 +61,7 @@ class CloudFormationCloudWatchAlarmIntegrationTest {
.statusCode(200);
// Stack completes and Fn::GetAtt(Alarm, Arn) resolves to the real alarm ARN.
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -380,6 +380,7 @@ class CloudFormationCloudWatchDashboardIntegrationTest {
}
private static String describeStacks(String stack, String expectedStatus) {
CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -14,6 +14,7 @@ import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* A stack update that changes a Cognito user pool and its client in place and then fails on a later
@@ -116,6 +117,8 @@ class CloudFormationCognitoUpdateRollbackIntegrationTest {
}
private static String describeStacks(String stack, String expectedStatus) {
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stack, CFN_AUTH);
assertEquals(expectedStatus, state.status(), state.reason());
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -104,6 +104,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest {
.then()
.statusCode(200);
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status());
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -143,6 +144,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest {
.then()
.statusCode(200);
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status());
cognito("GetGroup", "{\"UserPoolId\": \"" + poolId + "\", \"GroupName\": \"admin\"}")
.statusCode(400)
.body("__type", equalTo("ResourceNotFoundException"));
@@ -159,6 +161,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest {
String poolId = createStack(stackName, poolAndGroupsTemplate("admin", 0));
updateStack(stackName, poolAndGroupsTemplate("operators", 0));
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status());
String describeXml = describeStack(stackName);
assertThat(describeXml, containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"));
@@ -182,6 +185,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest {
String original = output(describeXml, "GroupName");
updateStack(stackName, twoPoolsAndUnnamedGroupTemplate("SecondPool"));
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status());
describeXml = describeStack(stackName);
assertThat(describeXml, containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"));
@@ -332,6 +336,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest {
.then()
.statusCode(200);
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status());
String describeXml = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -0,0 +1,100 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.services.cloudformation.model.ChangeSet;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.arc.ClientProxy;
import io.quarkus.test.junit.QuarkusMock;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import org.mockito.AdditionalAnswers;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import static io.github.hectorvent.floci.testing.CfnRequests.cfn;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.Mockito.withSettings;
@QuarkusTest
class CloudFormationCreateStackIdentityIntegrationTest {
private static final String TEMPLATE = """
{"Resources":{"Q":{"Type":"AWS::SQS::Queue","Properties":{}}}}
""";
@Inject
CloudFormationService service;
@Test
void createStackDoesNotExecuteAReplacementWithTheSameName() throws Exception {
String stackName = "cfn-create-identity-" + UUID.randomUUID().toString().substring(0, 8);
CloudFormationService original = ClientProxy.unwrap(service);
Answer<Object> realService = AdditionalAnswers.delegatesTo(original);
AtomicReference<ChangeSet> replacement = new AtomicReference<>();
CloudFormationService replacingService = Mockito.mock(CloudFormationService.class,
withSettings().defaultAnswer(invocation -> {
if (!"createChangeSetForCreateStack".equals(invocation.getMethod().getName())) {
return realService.answer(invocation);
}
ChangeSet initial = (ChangeSet) realService.answer(invocation);
Future<?> deleted = original.deleteStack(initial.getStackId(), List.of(), "us-east-1",
"000000000000");
deleted.get(5, TimeUnit.SECONDS);
replacement.set(original.createChangeSetForCreateStack(stackName, "initial-create",
TEMPLATE, null, null, List.of(), null, "us-east-1", false));
assertNotEquals(initial.getStackId(), replacement.get().getStackId());
return initial;
}));
QuarkusMock.installMockForType(replacingService, CloudFormationService.class);
try {
cfn("CreateStack", stackName).formParam("TemplateBody", TEMPLATE)
.when().post("/").then().statusCode(400);
assertThat(cfn("DescribeStacks", stackName).when().post("/").asString(),
containsString("<StackId>" + replacement.get().getStackId() + "</StackId>"));
assertThat(cfn("DescribeStacks", stackName).when().post("/").asString(),
containsString("<StackStatus>REVIEW_IN_PROGRESS</StackStatus>"));
} finally {
CfnStackWaits.deleteStack(stackName);
}
}
@Test
void protectedCreateClearsProtectionWhenItsChangeSetIsDeletedBeforeExecution() {
String stackName = "cfn-create-deleted-cs-" + UUID.randomUUID().toString().substring(0, 8);
CloudFormationService original = ClientProxy.unwrap(service);
Answer<Object> realService = AdditionalAnswers.delegatesTo(original);
CloudFormationService deletingService = Mockito.mock(CloudFormationService.class,
withSettings().defaultAnswer(invocation -> {
if (!"createChangeSetForCreateStack".equals(invocation.getMethod().getName())) {
return realService.answer(invocation);
}
ChangeSet initial = (ChangeSet) realService.answer(invocation);
original.deleteChangeSet(initial.getStackId(), initial.getChangeSetId(), "us-east-1");
return initial;
}));
QuarkusMock.installMockForType(deletingService, CloudFormationService.class);
try {
cfn("CreateStack", stackName).formParam("TemplateBody", TEMPLATE)
.formParam("EnableTerminationProtection", "true")
.when().post("/").then().statusCode(400)
.body(containsString("ChangeSetNotFoundException"));
String stackXml = cfn("DescribeStacks", stackName).when().post("/")
.then().statusCode(200).extract().asString();
assertThat(stackXml, containsString("<StackStatus>REVIEW_IN_PROGRESS</StackStatus>"));
assertThat(stackXml, containsString("<EnableTerminationProtection>false</EnableTerminationProtection>"));
} finally {
original.updateTerminationProtection(stackName, false, "us-east-1");
CfnStackWaits.deleteStack(stackName);
}
}
}
@@ -65,8 +65,7 @@ class CloudFormationDeleteIdempotencyIntegrationTest {
.formParam("TemplateBody", template)
.when().post("/").then().statusCode(200);
// CloudFormationQueryHandler awaits executeChangeSet before CreateStack returns, so this
// one-shot assertion verifies the handler's synchronous completion contract.
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
assertStackStatus(stackName, "CREATE_COMPLETE");
// Remove the table out-of-band — mimics a rollback having already deleted it.
@@ -47,6 +47,7 @@ class CloudFormationDescribeStackResourcesFilterIntegrationTest {
.post("/")
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
return stackName;
}
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.hamcrest.Matchers;
@@ -77,6 +78,7 @@ class CloudFormationDynamicReferenceIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus("cfn-dynref-ssm-stack", "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -143,6 +145,7 @@ class CloudFormationDynamicReferenceIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus("cfn-dynref-sm-stack", "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -203,6 +206,7 @@ class CloudFormationDynamicReferenceIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus("cfn-dynref-sns-stack", "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -250,6 +254,7 @@ class CloudFormationDynamicReferenceIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus("cfn-dynref-ssm-secure-non-rds-stack", "ROLLBACK_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -296,6 +301,7 @@ class CloudFormationDynamicReferenceIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus("cfn-dynref-literal-stack", "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -124,6 +124,7 @@ class CloudFormationDynamoDbGlobalTableIntegrationTest {
}
private void assertStackStatus(String stackName, String status) {
CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -56,6 +56,7 @@ class CloudFormationDynamoDbReplicaIntegrationTest {
}
private void assertStackStatus(String stackName, String status) {
CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ec2.model.Tag;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
@@ -64,6 +65,7 @@ class CloudFormationEc2InstanceIntegrationTest {
.formParam("TemplateBody", template.formatted(original, original))
.when().post("/").then().statusCode(200);
try {
awaitStackStatus(stackName, "CREATE_COMPLETE");
String stack = given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200)
@@ -81,6 +83,7 @@ class CloudFormationEc2InstanceIntegrationTest {
.formParam("Action", "UpdateStack").formParam("StackName", stackName)
.formParam("TemplateBody", template.formatted(desired, desired))
.when().post("/").then().statusCode(200);
awaitStackStatus(stackName, "UPDATE_COMPLETE");
String updated = given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stackName)
.when().post("/").then().statusCode(200)
@@ -137,6 +140,7 @@ class CloudFormationEc2InstanceIntegrationTest {
.then()
.statusCode(200);
awaitStackStatus(stackName, "CREATE_COMPLETE");
String describeStacks = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -458,6 +462,7 @@ class CloudFormationEc2InstanceIntegrationTest {
}
private static String describeStacks(String stackName, String expectedStatus) {
awaitStackStatus(stackName, expectedStatus);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -468,6 +473,11 @@ class CloudFormationEc2InstanceIntegrationTest {
.extract().asString();
}
private static void awaitStackStatus(String stackName, String expectedStatus) {
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stackName, CFN_AUTH);
assertEquals(expectedStatus, state.status(), state.reason());
}
private static String instanceIdFrom(String stackXml) {
Matcher m = Pattern.compile("<OutputValue>(i-[0-9a-fA-F]+)</OutputValue>").matcher(stackXml);
assertTrue(m.find(), "expected an instance id in the stack outputs: " + stackXml);
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -81,6 +82,7 @@ class CloudFormationEc2IntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
// The exported subnet ids must be real subnet-xxxx ids (not the old stub shape).
String describeStacks = given()
.contentType("application/x-www-form-urlencoded")
@@ -174,6 +176,7 @@ class CloudFormationEc2IntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String describeStacks = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -242,6 +245,7 @@ class CloudFormationEc2IntegrationTest {
.formParam("TemplateBody", template)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String describe = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.EnforcementFixtures;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.xml.XmlPath;
@@ -529,6 +530,8 @@ class CloudFormationEc2MetadataOptionsIntegrationTest {
}
private static XmlPath describeStack(String stackName, String expectedStatus) {
CfnStackWaits.awaitStatus(stackName, expectedStatus,
EnforcementFixtures.auth(ACCOUNT, REGION, "cloudformation"));
return cfnRequest("DescribeStacks").formParam("StackName", stackName)
.post("/").then().statusCode(200)
.body(containsString("<StackStatus>" + expectedStatus + "</StackStatus>"))
@@ -822,6 +822,7 @@ class CloudFormationEc2NetworkingIntegrationTest {
}
private static String describeStacks(String stack, String expectedStatus) {
CfnStackWaits.awaitStatus(stack, expectedStatus);
return cfn("DescribeStacks", stack)
.header("Authorization", CFN_AUTH)
.when().post("/").then().statusCode(200)
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -77,6 +78,7 @@ class CloudFormationEcsCapacityIntegrationTest {
createStack(stackName, template(clusterName, providerName));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -91,6 +93,7 @@ class CloudFormationEcsCapacityIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -190,6 +193,7 @@ class CloudFormationEcsCapacityIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"))
.extract().asString();
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
return xml.substring(xml.indexOf("<StackId>") + "<StackId>".length(), xml.indexOf("</StackId>"));
}
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
@@ -161,6 +162,7 @@ class CloudFormationEcsServiceStableIntegrationTest {
String name = "cfn-stable-" + Long.toString(System.nanoTime(), 36);
stackCall("CreateStack", name, TEMPLATE.formatted(name, "app:v1", 1));
CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE");
assertThat(stackStatus(name), equalTo("CREATE_COMPLETE"));
Response service = describeService(name);
@@ -176,8 +178,10 @@ class CloudFormationEcsServiceStableIntegrationTest {
void updateStack_ecsService_runsOnlyTheNewRevisionWhenTheUpdateCompletes() {
String name = "cfn-stable-upd-" + Long.toString(System.nanoTime(), 36);
stackCall("CreateStack", name, TEMPLATE.formatted(name, "app:v1", 1));
CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE");
stackCall("UpdateStack", name, TEMPLATE.formatted(name, "app:v2", 2));
CfnStackWaits.awaitStatus(name, "UPDATE_COMPLETE");
assertThat(stackStatus(name), equalTo("UPDATE_COMPLETE"));
Response service = describeService(name);
@@ -195,9 +199,11 @@ class CloudFormationEcsServiceStableIntegrationTest {
String name = "cfn-stable-rb-" + Long.toString(System.nanoTime(), 36);
String subnet = Ec2Service.defaultSubnetId("us-east-1", "a");
stackCall("CreateStack", name, AWSVPC_TEMPLATE.formatted(name, 1, subnet));
CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE");
assertThat(stackStatus(name), equalTo("CREATE_COMPLETE"));
stackCall("UpdateStack", name, AWSVPC_TEMPLATE.formatted(name, 2, "subnet-does-not-exist"));
CfnStackWaits.awaitStatus(name, "UPDATE_ROLLBACK_COMPLETE");
assertThat(stackStatus(name), equalTo("UPDATE_ROLLBACK_COMPLETE"));
Response service = describeService(name);
@@ -226,6 +232,7 @@ class CloudFormationEcsServiceStableIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE");
assertThat(stackStatus(name), equalTo("CREATE_COMPLETE"));
Response service = describeService(name);
assertThat(service.path("services[0].networkConfiguration.awsvpcConfiguration.subnets"),
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -63,6 +64,7 @@ class CloudFormationEksIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -49,6 +49,7 @@ class CloudFormationElbV2ReplacementIntegrationTest {
String oldTg = output(describeBefore, "TgRef");
updateStack(stackName, template(suffix, "AlbB", "tg-b-" + suffix, ""));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
String describeAfter = describeStack(stackName);
assertStatus(describeAfter, "UPDATE_COMPLETE");
String newListener = output(describeAfter, "ListenerRef");
@@ -92,6 +93,7 @@ class CloudFormationElbV2ReplacementIntegrationTest {
}""".formatted(suffix);
updateStack(stackName, template(suffix, "AlbB", "tg-" + suffix, failingSecret));
CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE");
String describe = describeStack(stackName);
assertStatus(describe, "UPDATE_ROLLBACK_COMPLETE");
assertEquals(oldListener, output(describe, "ListenerRef"));
@@ -122,12 +124,14 @@ class CloudFormationElbV2ReplacementIntegrationTest {
createStack(stackName, fixedResponseTemplate(suffix));
updateStack(stackName, template(suffix, "AlbA", "tg-a-" + suffix, ""));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
String describeBefore = describeStack(stackName);
assertStatus(describeBefore, "UPDATE_COMPLETE");
String oldListener = output(describeBefore, "ListenerRef");
String oldTg = output(describeBefore, "TgRef");
updateStack(stackName, template(suffix, "AlbB", "tg-b-" + suffix, ""));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
String describeAfter = describeStack(stackName);
assertStatus(describeAfter, "UPDATE_COMPLETE");
assertNotEquals(oldListener, output(describeAfter, "ListenerRef"));
@@ -259,6 +263,7 @@ class CloudFormationElbV2ReplacementIntegrationTest {
given().formParam("Action", "CreateStack").formParam("Version", "2010-05-15")
.formParam("StackName", stackName).formParam("TemplateBody", body)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
assertStatus(describeStack(stackName), "CREATE_COMPLETE");
}
@@ -53,6 +53,7 @@ class CloudFormationEventBusIntegrationTest {
}
private void assertStackStatus(String stackName, String status) {
CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -97,6 +97,7 @@ class CloudFormationFirehoseIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
// Stack completes and Fn::GetAtt(Stream, Arn) resolves to the real delivery stream ARN.
given()
.contentType("application/x-www-form-urlencoded")
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -97,6 +98,7 @@ class CloudFormationGeneratedNameUniquenessIntegrationTest {
createStack(stackName, template);
try {
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
String xml = describeStacks(stackName);
assertTrue(xml.contains("<StackStatus>CREATE_COMPLETE</StackStatus>"),
"stack should be CREATE_COMPLETE");
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -138,6 +139,7 @@ class CloudFormationIamInlinePolicyIntegrationTest {
}
private static void assertStackStatus(String stackName, String status) {
CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -310,6 +312,7 @@ class CloudFormationIamInlinePolicyIntegrationTest {
createStack(stackName, template);
// Managed policy has an ARN (unlike inline), surfaced through Ref.
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -559,6 +562,7 @@ class CloudFormationIamInlinePolicyIntegrationTest {
createStack(stackName, template);
CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH);
String stack = describeStack(stackName, "DescribeStacks");
assertTrue(stack.contains("<StackStatus>ROLLBACK_COMPLETE</StackStatus>"),
"stack should roll back after the inline attachment failure: " + stack);
@@ -767,6 +771,7 @@ class CloudFormationIamInlinePolicyIntegrationTest {
private static void assertFailedResource(String stackName, String logicalId,
String expectedSubject, String expectedReason) {
CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH);
String stack = describeStack(stackName, "DescribeStacks");
assertTrue(
stack.contains("<StackStatus>ROLLBACK_COMPLETE</StackStatus>"),
@@ -128,6 +128,7 @@ class CloudFormationIamRoleInlinePoliciesIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -72,6 +73,7 @@ class CloudFormationIamRoleTrustPolicyUpdateIntegrationTest {
}
private static void assertStackStatus(String stackName, String status) {
CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.config.EncoderConfig;
@@ -58,6 +59,7 @@ class CloudFormationKinesisIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
// Stack completes and Fn::GetAtt(Stream, Arn) resolves to the real stream ARN.
given()
.contentType("application/x-www-form-urlencoded")
@@ -108,6 +110,7 @@ class CloudFormationKinesisIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -119,6 +122,7 @@ class CloudFormationKinesisIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -88,6 +88,7 @@ class CloudFormationLambdaAddressingIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -201,6 +202,7 @@ class CloudFormationLambdaAddressingIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -213,6 +215,7 @@ class CloudFormationLambdaAddressingIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
// "Ver" must still be version 1: the update must not republish an unchanged version.
given()
.contentType("application/x-www-form-urlencoded")
@@ -270,6 +270,7 @@ class CloudFormationLambdaEventInvokeConfigIntegrationTest {
}
private static String describeStacks(String stack, String expectedStatus) {
assertEquals(expectedStatus, CfnStackWaits.awaitTerminal(stack, CFN_AUTH).status());
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -33,6 +33,7 @@ class CloudFormationLambdaHotReloadIntegrationTest {
createStack(stackName, template(fnName, hostPath));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
describeStacks(stackName)
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
@@ -62,6 +63,8 @@ class CloudFormationLambdaHotReloadIntegrationTest {
createStack(stackName, template(fnName, "relative/dist"));
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stackName, CFN_AUTH);
assertThat(state.status(), not("CREATE_COMPLETE"));
describeStacks(stackName)
.body(not(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>")));
assertThat(CfnStackWaits.failedResourceReason(stackName, CFN_AUTH),
@@ -84,6 +84,7 @@ class CloudFormationLambdaMicrovmsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -263,6 +264,7 @@ class CloudFormationLambdaMicrovmsIntegrationTest {
}
private static String describeStacks(String stackName, String expectedStatus) {
CfnStackWaits.awaitStatus(stackName, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1,9 +1,11 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
@@ -53,6 +55,8 @@ class CloudFormationLambdaMissingS3CodeIntegrationTest {
}
private static void assertStackFailed(String stackName) {
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stackName, CFN_AUTH);
assertThat(state.status(), not("CREATE_COMPLETE"));
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -95,6 +99,7 @@ class CloudFormationLambdaMissingS3CodeIntegrationTest {
// handler is correct and present in the real package that was never fetched.
createStack(stackName, template(fnName, "src/api.handler"));
assertStackFailed(stackName);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.CloudFormationSettingsProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
@@ -36,6 +37,7 @@ class CloudFormationLambdaStubCodeAllowedIntegrationTest {
createStack(stackName, template(fnName, "index.handler"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.services.lambdaweb.LambdaWebCodeBuckets;
import io.github.hectorvent.floci.services.lambdaweb.LambdaWebRoles;
import io.github.hectorvent.floci.services.lambdaweb.LambdaWebZips;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -306,6 +307,7 @@ class CloudFormationLambdaWebIntegrationTest {
}
private static String describeStacks(String stackName, String expectedStatus) {
assertEquals(expectedStatus, CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status());
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -80,6 +80,7 @@ class CloudFormationLaunchTemplateIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -146,6 +147,7 @@ class CloudFormationLaunchTemplateIntegrationTest {
.statusCode(200);
// Stack completes, Ref resolves to a launch template id, GetAtt resolves the version.
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -65,6 +66,7 @@ class CloudFormationListIntrinsicsIntegrationTest {
.when().post("/")
.then().statusCode(200);
CfnStackWaits.awaitStatus(name, tagged ? "CREATE_COMPLETE" : "UPDATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -46,6 +47,8 @@ class CloudFormationListStacksIntegrationTest {
}
""".formatted(suffix));
CfnStackWaits.awaitStatus(completeStack, "CREATE_COMPLETE");
CfnStackWaits.awaitStatus(rolledBackStack, "ROLLBACK_COMPLETE");
String response = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "ListStacks")
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.config.EncoderConfig;
@@ -59,6 +60,7 @@ class CloudFormationLogsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
// Stack completes and Fn::GetAtt(LogGroup, Arn) resolves to the log group ARN.
given()
.contentType("application/x-www-form-urlencoded")
@@ -107,6 +109,7 @@ class CloudFormationLogsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -118,6 +121,7 @@ class CloudFormationLogsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -191,6 +195,7 @@ class CloudFormationLogsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String beforeXml = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -215,6 +220,7 @@ class CloudFormationLogsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
String afterXml = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -252,6 +258,7 @@ class CloudFormationLogsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -263,6 +270,7 @@ class CloudFormationLogsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -322,6 +330,7 @@ class CloudFormationLogsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -333,6 +342,7 @@ class CloudFormationLogsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -391,6 +401,7 @@ class CloudFormationLogsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -402,6 +413,7 @@ class CloudFormationLogsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.services.cloudformation.model.Stack;
import io.github.hectorvent.floci.services.iam.IamService;
import io.github.hectorvent.floci.services.iam.model.IamRole;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.arc.ClientProxy;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -150,6 +151,7 @@ class CloudFormationManagedPolicyUpdateIntegrationTest {
}
private static void assertStackStatus(String stackName, String status) {
CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -70,6 +71,7 @@ class CloudFormationNetworkAclIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String describe = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -15,11 +15,13 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Map;
import java.util.Optional;
import static io.github.hectorvent.floci.testing.PersistentStorageProfile.STORAGE_DIR;
import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -84,6 +86,7 @@ class CloudFormationPersistenceIntegrationTest {
given().when().head("/cfn-persist-it-bucket").then().statusCode(404);
});
CfnStackWaits.awaitStatus("persist-it-stack", "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -97,7 +100,11 @@ class CloudFormationPersistenceIntegrationTest {
// Read the on-disk file the way a fresh Floci process would on the next boot.
PersistentStorage<String, Stack> store = new PersistentStorage<>(
STACKS_FILE, new TypeReference<Map<String, Stack>>() {});
store.load();
await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> {
store.load();
assertEquals("CREATE_COMPLETE", store.get("000000000000/us-east-1:persist-it-stack")
.map(Stack::getStatus).orElse(null));
});
// Account-prefixed key: <defaultAccount>/<region>:<stackName>
Optional<Stack> loaded = store.get("000000000000/us-east-1:persist-it-stack");
@@ -54,6 +54,7 @@ class CloudFormationPipesCleanupIntegrationTest {
updateStack(stackName, template(newName, suffix));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -105,6 +106,7 @@ class CloudFormationPipesCleanupIntegrationTest {
updateStack(stackName, template(newName, suffix));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -162,6 +164,7 @@ class CloudFormationPipesCleanupIntegrationTest {
updateStack(stackName, template(newName, suffix));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE_CLEANUP_IN_PROGRESS");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -175,6 +178,7 @@ class CloudFormationPipesCleanupIntegrationTest {
assertPipe(oldName);
assertPipe(newName);
verify(pipesService, Mockito.timeout(5_000)).deletePipe(eq(oldName), anyString());
Mockito.doCallRealMethod().when(pipesService).deletePipe(eq(oldName), anyString());
given()
@@ -232,6 +236,8 @@ class CloudFormationPipesCleanupIntegrationTest {
updateStack(stackName, template(newName, suffix));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE_CLEANUP_IN_PROGRESS");
verify(pipesService, Mockito.timeout(5_000)).deletePipe(eq(oldName), anyString());
Mockito.doCallRealMethod().when(pipesService).deletePipe(eq(oldName), anyString());
given()
@@ -286,6 +292,7 @@ class CloudFormationPipesCleanupIntegrationTest {
}
}""".formatted(suffix)));
CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -369,6 +376,7 @@ class CloudFormationPipesCleanupIntegrationTest {
}
}""".formatted(suffix)));
CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_FAILED");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -407,6 +415,7 @@ class CloudFormationPipesCleanupIntegrationTest {
// "No updates are to be performed.": a new output makes it an update.
updateStack(stackName, CfnUpdates.forceUpdate(renameRollbackTemplate(priorName, "")));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
given()
.contentType("application/json")
.when()
@@ -447,6 +456,7 @@ class CloudFormationPipesCleanupIntegrationTest {
updateStack(stackName, tagReconcileTemplate(pipeName, "after", "team", "after"));
CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -492,6 +502,7 @@ class CloudFormationPipesCleanupIntegrationTest {
updateStack(stackName, tagReconcileTemplate(pipeName, "after", "team", "after"));
CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_FAILED");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -579,6 +590,7 @@ class CloudFormationPipesCleanupIntegrationTest {
.post("/")
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
}
private static void updateStack(String stackName, String templateBody) {
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import org.junit.jupiter.api.Test;
@@ -161,6 +162,7 @@ class CloudFormationPolicyDocumentIntrinsicsIntegrationTest {
String policyName = "sub-shorthand-policy-" + suffix;
createStack(stackName, stackWithSubShorthandPolicy(roleName, bucketName, policyName));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
cfnQuery("DescribeStacks", stackName).then().statusCode(200)
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
@@ -137,6 +137,7 @@ class CloudFormationRdsDynamicReferenceIntegrationTest {
createStack(stackName, mapper.writeValueAsString(document));
stackCreated = true;
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String describeXml = describeStack(stackName);
assertTrue(describeXml.contains("<StackStatus>CREATE_COMPLETE</StackStatus>"),
"an ssm-secure master password is legal on RDS and must provision: " + describeXml);
@@ -167,6 +168,7 @@ class CloudFormationRdsDynamicReferenceIntegrationTest {
"{{resolve:ssm:" + parameterName + "}}"));
stackCreated = true;
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String describeXml = describeStack(stackName);
assertTrue(describeXml.contains("<StackStatus>CREATE_COMPLETE</StackStatus>"),
"a plain ssm master password must still resolve: " + describeXml);
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -61,6 +62,7 @@ class CloudFormationRdsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
// Stack reaches CREATE_COMPLETE and Ref(DbSubnets) exports the subnet group name.
given()
.contentType("application/x-www-form-urlencoded")
@@ -108,6 +110,7 @@ class CloudFormationRdsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String beforeXml = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -134,6 +137,7 @@ class CloudFormationRdsIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
String afterXml = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -210,6 +214,7 @@ class CloudFormationRdsIntegrationTest {
.statusCode(200);
try {
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String xml = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1535,6 +1535,7 @@ class CloudFormationResourceConditionIntegrationTest {
.then()
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
}
private static void updateStack(String stackName, String template) {
@@ -1548,6 +1549,7 @@ class CloudFormationResourceConditionIntegrationTest {
.then()
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
}
private static void deleteStack(String stackName) {
@@ -366,6 +366,7 @@ class CloudFormationRollbackCompleteUpdateIntegrationTest {
}
private static void assertStackStatus(String stackName, String status) {
CfnStackWaits.awaitStatus(stackName, status);
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -1098,6 +1098,7 @@ class CloudFormationRoute53RecordSetIntegrationTest {
}
private void assertStackStatus(String stackName, String status) {
CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -76,6 +76,7 @@ class CloudFormationSecretTargetAttachmentIntegrationTest {
createStack(stackName, template);
stackCreated = true;
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String describeXml = describeStack(stackName);
assertTrue(describeXml.contains("<StackStatus>CREATE_COMPLETE</StackStatus>"),
"stack should be CREATE_COMPLETE: " + describeXml);
@@ -156,6 +157,7 @@ class CloudFormationSecretTargetAttachmentIntegrationTest {
createStack(stackName, template);
stackCreated = true;
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String describeXml = describeStack(stackName);
assertTrue(describeXml.contains("<StackStatus>CREATE_COMPLETE</StackStatus>"),
"stack should be CREATE_COMPLETE: " + describeXml);
@@ -226,6 +228,7 @@ class CloudFormationSecretTargetAttachmentIntegrationTest {
createStack(stackName, template);
stackCreated = true;
CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH);
String describeXml = describeStack(stackName);
assertTrue(describeXml.contains("<StackStatus>ROLLBACK_COMPLETE</StackStatus>"),
"stack should be ROLLBACK_COMPLETE: " + describeXml);
@@ -293,6 +296,7 @@ class CloudFormationSecretTargetAttachmentIntegrationTest {
createStack(stackName, template);
stackCreated = true;
CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH);
String describeXml = describeStack(stackName);
assertTrue(describeXml.contains("<StackStatus>ROLLBACK_COMPLETE</StackStatus>"),
"stack should be ROLLBACK_COMPLETE: " + describeXml);
@@ -90,6 +90,7 @@ class CloudFormationSecurityGroupRulesIntegrationTest {
.extract().asString();
String stackId = between(created, "<StackId>", "</StackId>");
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String describe = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -383,6 +384,7 @@ class CloudFormationSecurityGroupRulesIntegrationTest {
.formParam("StackName", stackName)
.formParam("TemplateBody", template)
.when().post("/").then().statusCode(200).extract().asString();
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -402,6 +404,7 @@ class CloudFormationSecurityGroupRulesIntegrationTest {
.formParam("StackName", stackName)
.formParam("TemplateBody", template)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH);
}
private static String output(String stackName, String key) {
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResour
import io.quarkus.arc.ClientProxy;
import io.quarkus.test.junit.QuarkusMock;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -22,12 +23,15 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static io.github.hectorvent.floci.testing.CfnRequests.cfn;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.withSettings;
@@ -127,6 +131,49 @@ class CloudFormationServiceRestoreIntegrationTest {
assertEquals("DELETE_COMPLETE", stack.getStatus());
}
@Test
void rejectedProtectedCreateLeavesDeletablePlaceholder() throws Exception {
String targetStack = uniqueStackName("protected");
List<Future<?>> runningOperations = fillExecutor();
try {
Response rejected = cfn("CreateStack", targetStack)
.formParam("TemplateBody", TEMPLATE)
.formParam("EnableTerminationProtection", "true")
.when().post("/");
assertEquals(400, rejected.statusCode(), rejected.asString());
assertTrue(rejected.asString().contains("LimitExceededException"), rejected.asString());
Stack placeholder = service.describeStacks(targetStack, REGION).getFirst();
assertEquals("REVIEW_IN_PROGRESS", placeholder.getStatus());
assertFalse(placeholder.isEnableTerminationProtection());
} finally {
release(runningOperations);
}
service.deleteStack(targetStack, REGION, regionResolver.getAccountId())
.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
@Test
void rejectedCreateCleanupDoesNotUnprotectAnExecutingStack() throws Exception {
String targetStack = uniqueStackName("executing");
ChangeSet initial = service.createChangeSetForCreateStack(targetStack, "initial-create",
TEMPLATE, null, Map.of(), List.of(), Map.of(), REGION, true);
Future<?> execution = service.executeChangeSet(targetStack, "initial-create", REGION);
try {
service.clearProtectionAfterRejectedCreate(targetStack, initial, REGION);
Stack stack = service.describeStacks(targetStack, REGION).getFirst();
assertEquals("CREATE_IN_PROGRESS", stack.getStatus());
assertTrue(stack.isEnableTerminationProtection());
} finally {
releaseOperations.countDown();
execution.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
service.updateTerminationProtection(targetStack, false, REGION);
service.deleteStack(targetStack, REGION, regionResolver.getAccountId())
.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
}
/** Starts change set executions that block in provisioning until every thread and queue slot is taken. */
private List<Future<?>> fillExecutor() throws InterruptedException {
List<String> fillerStacks = new ArrayList<>();
@@ -189,6 +236,6 @@ class CloudFormationServiceRestoreIntegrationTest {
}
private static String uniqueStackName(String kind) {
return STACK_PREFIX + kind + "-" + System.nanoTime();
return STACK_PREFIX + kind + "-" + UUID.randomUUID();
}
}
@@ -0,0 +1,176 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.arc.ClientProxy;
import io.quarkus.test.junit.QuarkusMock;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.AdditionalAnswers;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import static io.github.hectorvent.floci.testing.CfnRequests.cfn;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.withSettings;
@QuarkusTest
class CloudFormationSlowStackResponseIntegrationTest {
private static final String PREFIX = "slow-stack-response-";
private static final String SLOW_RESOURCE = "AWS::Test::Resource";
private static final String SLOW_TEMPLATE = """
{"Resources":{"Slow":{"Type":"AWS::Test::Resource","Properties":{}}}}
""";
@Inject
CfnResourceDispatcher provisioner;
private final CountDownLatch provisioningStarted = new CountDownLatch(1);
private final CountDownLatch releaseProvisioning = new CountDownLatch(1);
@BeforeEach
void blockSlowResource() {
Answer<Object> realProvisioner = AdditionalAnswers.delegatesTo(ClientProxy.unwrap(provisioner));
CfnResourceDispatcher blockingProvisioner = Mockito.mock(CfnResourceDispatcher.class,
withSettings().defaultAnswer(invocation -> {
if (!"provision".equals(invocation.getMethod().getName())
|| !SLOW_RESOURCE.equals(invocation.getArgument(1))
|| Arrays.stream(invocation.getArguments()).noneMatch(
argument -> argument instanceof String name && name.startsWith(PREFIX))) {
return realProvisioner.answer(invocation);
}
provisioningStarted.countDown();
assertTrue(releaseProvisioning.await(15, TimeUnit.SECONDS),
"blocked provisioning was not released");
StackResource resource = new StackResource();
resource.setLogicalId(invocation.getArgument(0));
resource.setResourceType(SLOW_RESOURCE);
resource.setPhysicalId("slow-resource");
resource.setStatus("CREATE_COMPLETE");
return resource;
}));
QuarkusMock.installMockForType(blockingProvisioner, CfnResourceDispatcher.class);
}
@Test
void createStackReturnsStackIdWhileResourceIsStillProvisioning() throws Exception {
String stackName = uniqueStackName();
try {
assertRespondsBeforeProvisioningCompletes("CreateStack", stackName, SLOW_TEMPLATE,
"CREATE_IN_PROGRESS");
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
} finally {
releaseProvisioning.countDown();
deleteStack(stackName);
}
}
@Test
void updateStackReturnsStackIdWhileResourceIsStillProvisioning() throws Exception {
String stackName = uniqueStackName();
String baseTemplate = """
{"Resources":{"Base":{"Type":"AWS::SQS::Queue","Properties":{"QueueName":"%s"}}}}
""".formatted(stackName);
String updatedTemplate = """
{"Resources":{"Base":{"Type":"AWS::SQS::Queue","Properties":{"QueueName":"%s"}},
"Slow":{"Type":"AWS::Test::Resource","Properties":{}}}}
""".formatted(stackName);
try {
String createdStackId = cfn("CreateStack", stackName).formParam("TemplateBody", baseTemplate)
.when().post("/").then().statusCode(200).extract().xmlPath()
.getString("**.find { it.name() == 'StackId' }");
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
assertEquals(createdStackId, assertRespondsBeforeProvisioningCompletes("UpdateStack", stackName,
updatedTemplate, "UPDATE_IN_PROGRESS"));
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
} finally {
releaseProvisioning.countDown();
deleteStack(stackName);
}
}
@Test
void protectedCreateStackRejectsDeleteWhileResourceIsStillProvisioning() throws Exception {
String stackName = uniqueStackName();
try {
assertRespondsBeforeProvisioningCompletes("CreateStack", stackName, SLOW_TEMPLATE,
"CREATE_IN_PROGRESS", true);
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
} finally {
releaseProvisioning.countDown();
cfn("UpdateTerminationProtection", stackName)
.formParam("EnableTerminationProtection", "false")
.when().post("/").then().statusCode(200);
deleteStack(stackName);
}
}
private String assertRespondsBeforeProvisioningCompletes(String action, String stackName,
String template, String inProgressStatus) throws Exception {
return assertRespondsBeforeProvisioningCompletes(action, stackName, template, inProgressStatus, false);
}
private String assertRespondsBeforeProvisioningCompletes(String action, String stackName,
String template, String inProgressStatus,
boolean terminationProtection) throws Exception {
try (ExecutorService requests = Executors.newSingleThreadExecutor()) {
Future<Response> request = requests.submit(() -> {
RequestSpecification form = cfn(action, stackName).formParam("TemplateBody", template);
if (terminationProtection) {
form.formParam("EnableTerminationProtection", "true");
}
return form.when().post("/");
});
try {
assertTrue(provisioningStarted.await(10, TimeUnit.SECONDS),
"stack never reached resource provisioning");
Response response = request.get(5, TimeUnit.SECONDS);
assertEquals(200, response.statusCode(), response.asString());
assertThat(response.asString(), containsString("<StackId>"));
String responseStackId = response.xmlPath().getString("**.find { it.name() == 'StackId' }");
Response described = cfn("DescribeStacks", stackName).when().post("/");
assertEquals(200, described.statusCode(), described.asString());
assertEquals(responseStackId,
described.xmlPath().getString("**.find { it.name() == 'StackId' }"));
assertThat(described.asString(),
containsString("<StackStatus>" + inProgressStatus + "</StackStatus>"));
if (terminationProtection) {
assertThat(described.asString(),
containsString("<EnableTerminationProtection>true</EnableTerminationProtection>"));
cfn("DeleteStack", stackName).when().post("/").then().statusCode(400)
.body(containsString("cannot be deleted while TerminationProtection is enabled"));
}
return responseStackId;
} finally {
releaseProvisioning.countDown();
}
}
}
private static void deleteStack(String stackName) {
cfn("DeleteStack", stackName).when().post("/").then().statusCode(200);
CfnStackWaits.awaitStackDeleted(stackName);
}
private static String uniqueStackName() {
return PREFIX + UUID.randomUUID().toString().substring(0, 8);
}
}
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -254,6 +255,7 @@ class CloudFormationSmallMetadataIntegrationTest {
.post("/")
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
}
private static String describeFlowLogs() {
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -241,6 +242,7 @@ class CloudFormationSqsQueuePropertiesIntegrationTest {
}
private static String describeStacks(String stack, String expectedStatus) {
CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -76,6 +76,7 @@ class CloudFormationSsmParameterIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus("ssm-param-stack", "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -130,6 +131,7 @@ class CloudFormationSsmParameterIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus("ssm-missing-param-stack", "CREATE_FAILED");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -182,6 +184,7 @@ class CloudFormationSsmParameterIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus("ssm-secret-ref-param-stack", "CREATE_FAILED");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -130,16 +131,19 @@ class CloudFormationStackSetsIntegrationTest {
@Test
void singleStackProvisioningLandsInCallerAccount() {
String queue = "single-" + UUID.randomUUID().toString().substring(0, 8);
String stackName = "stack-" + queue;
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateStack")
.formParam("StackName", "stack-" + queue)
.formParam("StackName", stackName)
.formParam("TemplateBody", queueTemplate(queue))
.header("Authorization", auth(ACCOUNT_B, "cloudformation"))
.when().post("/")
.then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", auth(ACCOUNT_B, "cloudformation"));
// Resource lands in the caller's account, not the default account.
assertQueueVisible(ACCOUNT_B, queue);
assertQueueAbsent("000000000000", queue);
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.stepfunctions.StepFunctionsService;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -288,6 +289,7 @@ class CloudFormationStepFunctionsCleanupIntegrationTest {
.post("/")
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
}
private static void updateStack(String stackName, String templateBody) {
@@ -300,6 +302,7 @@ class CloudFormationStepFunctionsCleanupIntegrationTest {
.post("/")
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
}
private static void deleteStack(String stackName) {
@@ -44,6 +44,7 @@ class CloudFormationUnsupportedResourceTypeStrictIntegrationTest {
}
""");
CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -74,6 +75,7 @@ class CloudFormationUpdateRollbackParametersTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus("ssm-rollback-stack", "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -99,6 +101,7 @@ class CloudFormationUpdateRollbackParametersTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus("ssm-rollback-stack", "UPDATE_ROLLBACK_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -176,6 +179,7 @@ class CloudFormationUpdateRollbackParametersTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
// This fixture deliberately uses the still-unsupported metric-alarm rollback to exercise
// parameter restoration when another resource prevents rollback from completing.
given()
@@ -190,6 +194,7 @@ class CloudFormationUpdateRollbackParametersTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_FAILED");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import org.junit.jupiter.api.Test;
@@ -31,6 +32,7 @@ class CloudFormationUsePreviousTemplateIntegrationTest {
.formParam("TemplateBody", TEMPLATE.formatted(queueName))
.when().post("/")
.then().statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
}
private String visibilityTimeout(String queueName) {
@@ -60,6 +62,7 @@ class CloudFormationUsePreviousTemplateIntegrationTest {
.when().post("/")
.then().statusCode(200);
CfnStackWaits.awaitStatus("use-prev-update", "UPDATE_COMPLETE");
assertEquals("60", visibilityTimeout("use-prev-update-q"));
given().contentType(FORM)
@@ -88,6 +91,7 @@ class CloudFormationUsePreviousTemplateIntegrationTest {
.when().post("/")
.then().statusCode(200);
CfnStackWaits.awaitStatus("use-prev-sam", "CREATE_COMPLETE");
given().contentType(FORM)
.formParam("Action", "UpdateStack")
.formParam("StackName", "use-prev-sam")
@@ -97,6 +101,7 @@ class CloudFormationUsePreviousTemplateIntegrationTest {
.when().post("/")
.then().statusCode(200);
CfnStackWaits.awaitStatus("use-prev-sam", "UPDATE_COMPLETE");
given().contentType(FORM)
.formParam("Action", "GetTemplate")
.formParam("StackName", "use-prev-sam")
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -48,6 +49,7 @@ class CloudFormationVpcDefaultSgAttrIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -160,6 +160,7 @@ class CloudFormationVpcEndpointIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String stackDescription = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -239,6 +240,7 @@ class CloudFormationVpcEndpointIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String stackDescription = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.xml.XmlPath;
import io.restassured.response.ValidatableResponse;
@@ -128,6 +129,7 @@ class CloudFormationVpcPropertiesIntegrationTest {
}
private static String describeStacks(String stackName, String expectedStatus) {
CfnStackWaits.awaitStatus(stackName, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -187,6 +187,7 @@ class CloudFormationVpcReplacementIntegrationTest {
}
private static String describeStacks(String stack, String expectedStatus) {
CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -73,6 +74,7 @@ class CloudFormationWafV2ConfigGetAttIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
String describeBody = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -140,6 +142,7 @@ class CloudFormationWafV2ConfigGetAttIntegrationTest {
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -186,6 +189,7 @@ class CloudFormationWafV2ConfigGetAttIntegrationTest {
createStack(stackName, template);
CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH);
describeStackEvents(stackName)
.body(containsString("<ResourceStatus>CREATE_FAILED</ResourceStatus>"))
.body(containsString(
@@ -211,6 +215,7 @@ class CloudFormationWafV2ConfigGetAttIntegrationTest {
createStack(stackName, template);
CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH);
describeStackEvents(stackName)
.body(containsString("<ResourceStatus>CREATE_FAILED</ResourceStatus>"))
.body(containsString(
@@ -239,6 +244,7 @@ class CloudFormationWafV2ConfigGetAttIntegrationTest {
createStack(stackName, template);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH);
given()
.contentType(CONFIG_JSON)
.header("X-Amz-Target", CONFIG_TARGET_PREFIX + "DescribeConfigRules")
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnRequests;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.xml.XmlPath;
@@ -44,6 +45,7 @@ class CloudFormationWafV2IpSetIntegrationTest {
String nameB = "cfn-ipset-b-" + suffix;
cfn("CreateStack", stackName, template(nameA, "\"192.0.2.1/32\""));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
String created = describeStack(stackName)
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"))
.extract().asString();
@@ -58,6 +60,7 @@ class CloudFormationWafV2IpSetIntegrationTest {
.body("IPSet.Addresses", contains("192.0.2.1/32"));
cfn("UpdateStack", stackName, template(nameA, "\"198.51.100.0/24\""));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
String addressesUpdated = describeStack(stackName)
.body(containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"))
.extract().asString();
@@ -67,6 +70,7 @@ class CloudFormationWafV2IpSetIntegrationTest {
ipSet(nameA, id).body("IPSet.Addresses", contains("198.51.100.0/24"));
cfn("UpdateStack", stackName, template(nameB, "\"198.51.100.0/24\""));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
String replaced = describeStack(stackName)
.body(containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"))
.body(not(containsString("ROLLBACK")))
@@ -107,6 +111,7 @@ class CloudFormationWafV2IpSetIntegrationTest {
cfn("CreateStack", stackName, template);
CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE");
describeStackEvents(stackName)
.body(containsString("<ResourceStatus>CREATE_FAILED</ResourceStatus>"))
.body(containsString(
@@ -138,6 +143,7 @@ class CloudFormationWafV2IpSetIntegrationTest {
""";
cfn("CreateStack", stackName, template);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
String created = describeStack(stackName)
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"))
.extract().asString();
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnRequests;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.xml.XmlPath;
@@ -41,6 +42,7 @@ class CloudFormationWafV2WebAclAssociationIntegrationTest {
String stackName = "cfn-wafv2-assoc-" + suffix;
cfn("CreateStack", stackName, template(suffix, "AclA"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
String created = describeStack(stackName)
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"))
.extract().asString();
@@ -52,6 +54,7 @@ class CloudFormationWafV2WebAclAssociationIntegrationTest {
webAclForResource(poolArn).body("WebACL.ARN", equalTo(aclAArn));
cfn("UpdateStack", stackName, template(suffix, "AclB"));
CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE");
String updated = describeStack(stackName)
.body(containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"))
.body(not(containsString("ROLLBACK")))
@@ -81,6 +81,7 @@ class CodePipelineCfnIntegrationTest {
.formParam("TemplateBody", TEMPLATE)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(STACK, "CREATE_COMPLETE");
String stacks = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -712,6 +712,7 @@ class CognitoCfnIntegrationTest {
}
private static String describeStacks(String stack, String expectedStatus) {
CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -130,6 +130,7 @@ class ElastiCacheServerlessCfnIntegrationTest {
}
private static String describeStacks(String stack, String expectedStatus) {
CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -146,6 +146,7 @@ class GuardDutyMalwareProtectionPlanCfnIntegrationTest {
given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "CreateStack").formParam("StackName", stack).formParam("TemplateBody", template)
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stack, "CREATE_COMPLETE", CFN_AUTH);
String xml = given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH)
.formParam("Action", "DescribeStacks").formParam("StackName", stack)
.when().post("/").then().statusCode(200)
@@ -299,6 +300,7 @@ class GuardDutyMalwareProtectionPlanCfnIntegrationTest {
}
private static String describe(String stack, String expectedStatus) {
CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -328,6 +330,7 @@ class GuardDutyMalwareProtectionPlanCfnIntegrationTest {
}
private static String describeStacks(String expectedStatus) {
CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -250,6 +250,7 @@ class IotCfnIntegrationTest {
}
private static String describeStacks(String expectedStatus) {
CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -126,6 +126,7 @@ class IotDomainConfigurationCfnIntegrationTest {
}
private static String describeStacks(String expectedStatus) {
CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -214,6 +214,8 @@ class RedshiftServerlessCfnIntegrationTest {
}
private static String describeStacks(String expectedStatus) {
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(STACK, CFN_AUTH);
assertEquals(expectedStatus, state.status(), state.reason());
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.AfterEach;
@@ -885,6 +886,7 @@ class SamTransformIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -939,6 +941,7 @@ class SamTransformIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -1004,6 +1007,7 @@ class SamTransformIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -1633,6 +1637,7 @@ class SamTransformIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -1685,6 +1690,7 @@ class SamTransformIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -1742,6 +1748,7 @@ class SamTransformIntegrationTest {
.statusCode(200)
.body(containsString("<StackId>"));
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
@@ -123,6 +123,7 @@ class SnsFifoThroughputScopeCfnIntegrationTest {
}
private static String describeStacks(String expectedStatus) {
CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH);
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -120,6 +120,8 @@ class SnsTopicPolicyCfnIntegrationTest {
}
private static String describeStacks(String expectedStatus) {
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(STACK, CFN_AUTH);
assertEquals(expectedStatus, state.status(), state.reason());
return given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", CFN_AUTH)
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbStreamReader
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbStreamReader.RecordsPage;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbStreamReader.Shard;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbStreamReader.Stream;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.github.hectorvent.floci.testing.TestAccounts;
import io.quarkus.test.junit.QuarkusTest;
@@ -282,6 +283,7 @@ class DynamoDbLocalBackendIntegrationTest {
cloudFormation(A_EAST, "CreateStack", stack, template);
// The stack stays in Floci; its table is removed from Local with the others.
created.add(new CreatedTable(A_EAST, table));
CfnStackWaits.awaitStatus(stack, "CREATE_COMPLETE", A_EAST.authorization("cloudformation"));
cloudFormation(A_EAST, "DescribeStacks", stack, null)
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.autoscaling.AutoScalingReconciler;
import io.github.hectorvent.floci.services.autoscaling.AutoScalingService;
import io.github.hectorvent.floci.services.ec2.model.Instance;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
import io.restassured.specification.RequestSpecification;
@@ -55,6 +56,7 @@ class AutoScalingConfigurationUserDataIntegrationTest {
createConfiguration(source, name, encoded);
try {
if (!source.equals("query")) {
CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE");
String status = request("cloudformation", "DescribeStacks").formParam("StackName", name)
.post("/").then().statusCode(200).extract().xmlPath()
.getString("DescribeStacksResponse.DescribeStacksResult.Stacks.member.StackStatus");
@@ -126,6 +128,7 @@ class AutoScalingConfigurationUserDataIntegrationTest {
} else {
createConfiguration(source, name, data);
try {
CfnStackWaits.awaitStatus(name, "ROLLBACK_COMPLETE");
String status = request("cloudformation", "DescribeStacks").formParam("StackName", name)
.post("/").then().statusCode(200).extract().xmlPath()
.getString("DescribeStacksResponse.DescribeStacksResult.Stacks.member.StackStatus");
Loaded 100 of 103 files, more files were not shown because too many files have changed in this diff. Show more