mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(sqs): refuse a FifoQueue attribute on a standard queue (#8898)
CreateQueue now refuses a FifoQueue attribute, even false, on a queue whose name does not end in .fifo, with InvalidAttributeName "Unknown Attribute FifoQueue." as AWS does, before any queue is stored. An AWS::SQS::Queue declaring FifoQueue: false now fails and rolls back with the same message, while a FifoQueue dropped through AWS::NoValue still leaves a standard queue. Closes #8788
This commit is contained in:
1 parent
1d8499e837
commit
9d39f2941a
4 files changed
+95
No files matched your search
+55
@@ -5,10 +5,13 @@ import io.floci.aws.testing.CfnStackWaits;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@@ -27,6 +30,8 @@ class CloudFormationSqsQueuePropertiesIntegrationTest {
|
||||
private static final String NO_VALUE_STACK = "cfn-sqs-queue-no-value";
|
||||
private static final String SSE_STACK = "cfn-sqs-queue-sse";
|
||||
private static final String FIFO_STACK = "cfn-sqs-queue-fifo";
|
||||
private static final String FIFO_FALSE_STACK = "cfn-sqs-queue-fifo-false";
|
||||
private static final String FIFO_NO_VALUE_STACK = "cfn-sqs-queue-fifo-no-value";
|
||||
|
||||
@Test
|
||||
void declaredPropertiesReachTheQueueAndDroppedOnesReturnToTheirDefaults() {
|
||||
@@ -222,6 +227,56 @@ class CloudFormationSqsQueuePropertiesIntegrationTest {
|
||||
cloudFormation(FIFO_STACK, "DeleteStack", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStandardQueueDeclaringFifoQueueFalseFailsTheStackAsAwsDoes() {
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"Queue": {"Type": "AWS::SQS::Queue", "Properties": {"FifoQueue": false}}
|
||||
}
|
||||
}
|
||||
""";
|
||||
cloudFormation(FIFO_FALSE_STACK, "CreateStack", template);
|
||||
|
||||
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(FIFO_FALSE_STACK, CFN_AUTH);
|
||||
assertEquals("ROLLBACK_COMPLETE", state.status(), state.reason());
|
||||
String events = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DescribeStackEvents")
|
||||
.formParam("StackName", FIFO_FALSE_STACK)
|
||||
.when().post("/").then().statusCode(200).extract().asString();
|
||||
List<String> failures = XmlParser.extractGroups(events, "member").stream()
|
||||
.filter(event -> "Queue".equals(event.get("LogicalResourceId"))
|
||||
&& "CREATE_FAILED".equals(event.get("ResourceStatus")))
|
||||
.map(event -> event.get("ResourceStatusReason"))
|
||||
.toList();
|
||||
assertThat(failures, contains(containsString("Unknown Attribute FifoQueue.")));
|
||||
cloudFormation(FIFO_FALSE_STACK, "DeleteStack", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFifoQueueAConditionDropsWithNoValueLeavesAStandardQueue() {
|
||||
String template = """
|
||||
{
|
||||
"Conditions": {"Fifo": {"Fn::Equals": ["yes", "no"]}},
|
||||
"Resources": {
|
||||
"Queue": {
|
||||
"Type": "AWS::SQS::Queue",
|
||||
"Properties": {"FifoQueue": {"Fn::If": ["Fifo", true, {"Ref": "AWS::NoValue"}]}}
|
||||
}
|
||||
},
|
||||
"Outputs": {"QueueUrl": {"Value": {"Ref": "Queue"}}}
|
||||
}
|
||||
""";
|
||||
cloudFormation(FIFO_NO_VALUE_STACK, "CreateStack", template);
|
||||
String queueUrl = XmlParser.extractPairs(describeStacks(FIFO_NO_VALUE_STACK, "CREATE_COMPLETE"), "Outputs",
|
||||
"OutputKey", "OutputValue").get("QueueUrl");
|
||||
|
||||
assertFalse(queueAttributes(queueUrl).containsKey("FifoQueue"));
|
||||
cloudFormation(FIFO_NO_VALUE_STACK, "DeleteStack", null);
|
||||
}
|
||||
|
||||
private static void cloudFormation(String stack, String action, String templateBody) {
|
||||
if (templateBody == null) {
|
||||
given()
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.floci.aws.services.sqs;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.sqs.SqsClient;
|
||||
import software.amazon.awssdk.services.sqs.model.InvalidAttributeNameException;
|
||||
import software.amazon.awssdk.services.sqs.model.QueueAttributeName;
|
||||
import software.amazon.awssdk.services.sqs.model.QueueDoesNotExistException;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/** A standard queue has no FifoQueue attribute, so SQS refuses one even when it says {@code false}. */
|
||||
@QuarkusTest
|
||||
class SqsFifoQueueAttributeIntegrationTest {
|
||||
|
||||
@Test
|
||||
void aStandardQueueWithFifoQueueFalseIsRefusedAsAnUnknownAttribute() {
|
||||
String queueName = "standard-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
try (SqsClient sqs = AwsTestClients.create(SqsClient.builder(), "test", Region.US_EAST_1)) {
|
||||
InvalidAttributeNameException refused = assertThrows(InvalidAttributeNameException.class,
|
||||
() -> sqs.createQueue(r -> r.queueName(queueName)
|
||||
.attributes(Map.of(QueueAttributeName.FIFO_QUEUE, "false"))));
|
||||
|
||||
assertEquals("Unknown Attribute FifoQueue.", refused.awsErrorDetails().errorMessage());
|
||||
assertThrows(QueueDoesNotExistException.class, () -> sqs.getQueueUrl(r -> r.queueName(queueName)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user