mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudcontrol): reject ListResources for unsupported resource types instead of returning empty (#3141)
Unsupported TypeName values now fail with UnsupportedActionException (HTTP 400) instead of an empty ResourceDescriptions, which was indistinguishable from a genuinely empty result. Documents the supported type list and the new error behavior. Closes #2043 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
e0bf589972
commit
5cf10ece18
4 files changed
+103
-7
No files matched your search
+27
@@ -170,6 +170,33 @@ class CloudControlIntegrationTest {
|
||||
"{\"TypeName\":\"AWS::EC2::VPC\",\"DesiredState\":\"not json\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listResourcesRejectsUnsupportedTypesInsteadOfReturningEmpty() {
|
||||
// AWS::SQS::Queue and AWS::Logs::LogGroup are real Cloud Control types that Floci backs
|
||||
// through their own service APIs but does not enumerate on this read side. Returning an
|
||||
// empty ResourceDescriptions for them was indistinguishable from "no queues exist".
|
||||
String ct = "application/x-amz-json-1.0";
|
||||
assertErrorCode(ct, "CloudApiService.ListResources",
|
||||
"{\"TypeName\":\"AWS::SQS::Queue\"}", 400, "UnsupportedActionException");
|
||||
assertErrorCode(ct, "CloudApiService.ListResources",
|
||||
"{\"TypeName\":\"AWS::Logs::LogGroup\"}", 400, "UnsupportedActionException");
|
||||
|
||||
// A type name that does not exist in AWS at all reports the same error: Floci has no
|
||||
// CloudFormation type registry to tell a real-but-unbacked type from an invented one.
|
||||
assertErrorCode(ct, "CloudApiService.ListResources",
|
||||
"{\"TypeName\":\"AWS::NoSuch::Type\"}", 400, "UnsupportedActionException");
|
||||
|
||||
// A supported type is unaffected.
|
||||
given()
|
||||
.config(config().encoderConfig(encoderConfig().encodeContentTypeAs(ct, TEXT)))
|
||||
.contentType(ct)
|
||||
.header("X-Amz-Target", "CloudApiService.ListResources")
|
||||
.body("{\"TypeName\":\"AWS::S3::Bucket\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("TypeName", org.hamcrest.Matchers.equalTo("AWS::S3::Bucket"));
|
||||
}
|
||||
|
||||
private void assertErrorCode(String contentType, String target, String body) {
|
||||
assertErrorCode(contentType, target, body, 400, "InvalidRequestException");
|
||||
}
|
||||
|
||||
+39
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudcontrol;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.cloudformation.CloudFormationResourceProvisioner;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Tag;
|
||||
@@ -15,6 +16,7 @@ import java.util.Map;
|
||||
|
||||
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.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -50,4 +52,41 @@ class CloudControlServiceTest {
|
||||
assertFalse(properties.contains("ignored-empty"));
|
||||
assertFalse(properties.contains("ignored-blank"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listResourcesRejectsARealButUnbackedTypeInsteadOfReturningEmpty() {
|
||||
CloudControlService service = new CloudControlService(
|
||||
mock(S3Service.class), mock(Ec2Service.class), mock(IamService.class),
|
||||
mock(CloudFormationResourceProvisioner.class), new ObjectMapper());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.listResources("us-east-1", "AWS::SQS::Queue"));
|
||||
|
||||
assertEquals("UnsupportedActionException", e.getErrorCode());
|
||||
assertEquals(400, e.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listResourcesRejectsATypeThatDoesNotExistInAwsAtAll() {
|
||||
CloudControlService service = new CloudControlService(
|
||||
mock(S3Service.class), mock(Ec2Service.class), mock(IamService.class),
|
||||
mock(CloudFormationResourceProvisioner.class), new ObjectMapper());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.listResources("us-east-1", "AWS::NoSuch::Type"));
|
||||
|
||||
assertEquals("UnsupportedActionException", e.getErrorCode());
|
||||
assertEquals(400, e.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listResourcesStillReturnsASupportedType() {
|
||||
S3Service s3Service = mock(S3Service.class);
|
||||
when(s3Service.listBuckets()).thenReturn(List.of());
|
||||
CloudControlService service = new CloudControlService(
|
||||
s3Service, mock(Ec2Service.class), mock(IamService.class),
|
||||
mock(CloudFormationResourceProvisioner.class), new ObjectMapper());
|
||||
|
||||
assertTrue(service.listResources("us-east-1", "AWS::S3::Bucket").isEmpty());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user