mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): refuse a DescribeStackResource missing StackName or LogicalResourceId (#9808)
This commit is contained in:
1 parent
10cec1d376
commit
8e5725cc6f
2 files changed
+60
No files matched your search
@@ -3,6 +3,7 @@ package io.floci.aws.services.cloudformation;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.AwsQueryResponse;
|
||||
import io.floci.aws.core.common.RequestContext;
|
||||
import io.floci.aws.core.common.SmithyValidationErrors;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import io.floci.aws.core.common.XmlBuilder;
|
||||
import io.floci.aws.services.cloudformation.model.ChangeSet;
|
||||
@@ -564,6 +565,16 @@ public class CloudFormationQueryHandler {
|
||||
private Response describeStackResource(MultivaluedMap<String, String> params, String region) {
|
||||
String stackName = params.getFirst("StackName");
|
||||
String logicalId = params.getFirst("LogicalResourceId");
|
||||
List<String> missing = new ArrayList<>();
|
||||
if (stackName == null) {
|
||||
missing.add(SmithyValidationErrors.notNull("stackName"));
|
||||
}
|
||||
if (logicalId == null) {
|
||||
missing.add(SmithyValidationErrors.notNull("logicalResourceId"));
|
||||
}
|
||||
if (!missing.isEmpty()) {
|
||||
return xmlError("ValidationError", SmithyValidationErrors.message(missing), 400);
|
||||
}
|
||||
try {
|
||||
CloudFormationService.StackResourcesView view =
|
||||
cfnService.describeStackResourcesView(stackName, null, null, region);
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package io.floci.aws.services.cloudformation;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* DescribeStackResource requires StackName and LogicalResourceId (botocore's DescribeStackResourceInput). SDKs check
|
||||
* them client side, so only a raw Query call leaves one out; CloudFormation answers it with the model validation error.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationDescribeStackResourceRequiredIntegrationTest {
|
||||
|
||||
private static final String CFN_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260101/us-east-1/cloudformation/aws4_request";
|
||||
|
||||
@Test
|
||||
void aMissingLogicalResourceIdIsAValidationError() {
|
||||
describeStackResource().formParam("StackName", "no-such-stack")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value null at "
|
||||
+ "'logicalResourceId' failed to satisfy constraint: Member must not be null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bothMembersMissingAreReportedTogether() {
|
||||
describeStackResource()
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Message", equalTo("2 validation errors detected: Value null at 'stackName' "
|
||||
+ "failed to satisfy constraint: Member must not be null; Value null at 'logicalResourceId' "
|
||||
+ "failed to satisfy constraint: Member must not be null"));
|
||||
}
|
||||
|
||||
private static RequestSpecification describeStackResource() {
|
||||
return given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DescribeStackResource");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user