mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(servicequotas): filter ListServiceQuotas by QuotaAppliedAtLevel (#7238)
This commit is contained in:
1 parent
d44e96eab8
commit
be696ff51d
4 files changed
+114
-16
No files matched your search
+79
@@ -12,6 +12,7 @@ import org.junit.jupiter.params.provider.CsvSource;
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
@@ -536,4 +537,82 @@ class ServiceQuotasIntegrationTest {
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("UnknownOperationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listServiceQuotas_filterByQuotaAppliedAtLevelResource() {
|
||||
// EC2 quotas are ACCOUNT-level; RESOURCE filter should return empty
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "ServiceQuotasV20190624.ListServiceQuotas")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{\"ServiceCode\":\"ec2\",\"QuotaAppliedAtLevel\":\"RESOURCE\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Quotas.size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listServiceQuotas_filterByQuotaAppliedAtLevelAll() {
|
||||
// ALL should return all quotas (4 for EC2)
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "ServiceQuotasV20190624.ListServiceQuotas")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{\"ServiceCode\":\"ec2\",\"QuotaAppliedAtLevel\":\"ALL\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Quotas.size()", equalTo(4))
|
||||
.body("Quotas.find { it.QuotaCode == 'L-1216C47A' }.QuotaAppliedAtLevel", equalTo("ACCOUNT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listServiceQuotas_filterByQuotaAppliedAtLevelAccount() {
|
||||
// ACCOUNT (default) should return ACCOUNT-level quotas
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "ServiceQuotasV20190624.ListServiceQuotas")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{\"ServiceCode\":\"ec2\",\"QuotaAppliedAtLevel\":\"ACCOUNT\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Quotas.size()", equalTo(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listAwsDefaultServiceQuotas_noQuotaAppliedAtLevelFilter() {
|
||||
// ListAWSDefaultServiceQuotas does not have QuotaAppliedAtLevel parameter
|
||||
// Should return same as default (all quotas for EC2)
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "ServiceQuotasV20190624.ListAWSDefaultServiceQuotas")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{\"ServiceCode\":\"ec2\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Quotas.size()", equalTo(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listServiceQuotas_filterByQuotaAppliedAtLevelInvalid() {
|
||||
// Invalid value should return IllegalArgumentException
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "ServiceQuotasV20190624.ListServiceQuotas")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{\"ServiceCode\":\"ec2\",\"QuotaAppliedAtLevel\":\"ACOUNT\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("IllegalArgumentException"))
|
||||
.body("message", containsString("Invalid value for QuotaAppliedAtLevel"));
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -60,7 +60,7 @@ class ServiceQuotasServiceTest {
|
||||
String code = "L-1216C47A";
|
||||
assertEquals((double) value, configured.getServiceQuota("ec2", code, "us-east-1", ACCOUNT_ID)
|
||||
.path("Quota").path("Value").asDouble());
|
||||
assertEquals((double) value, configured.listServiceQuotas("ec2", code, null, null, "us-east-1", ACCOUNT_ID)
|
||||
assertEquals((double) value, configured.listServiceQuotas("ec2", code, null, null, null, "us-east-1", ACCOUNT_ID)
|
||||
.path("Quotas").get(0).path("Value").asDouble());
|
||||
assertEquals(5.0, configured.getAwsDefaultServiceQuota("ec2", code, "us-east-1", ACCOUNT_ID)
|
||||
.path("Quota").path("Value").asDouble());
|
||||
@@ -102,7 +102,7 @@ class ServiceQuotasServiceTest {
|
||||
assertEquals("ACCOUNT", quota.path("QuotaAppliedAtLevel").asText());
|
||||
assertEquals("arn:aws:servicequotas:us-east-1:" + ACCOUNT_ID + ":ec2/" + code,
|
||||
quota.path("QuotaArn").asText());
|
||||
JsonNode listed = service.listServiceQuotas("ec2", null, null, 100, "us-east-1", ACCOUNT_ID).path("Quotas");
|
||||
JsonNode listed = service.listServiceQuotas("ec2", null, null, null, 100, "us-east-1", ACCOUNT_ID).path("Quotas");
|
||||
assertEquals(4, listed.size());
|
||||
int matching = 0;
|
||||
for (JsonNode entry : listed) {
|
||||
@@ -136,7 +136,7 @@ class ServiceQuotasServiceTest {
|
||||
assertEquals("Amazon Virtual Private Cloud (Amazon VPC)", quota.path("ServiceName").asText());
|
||||
}
|
||||
Map<String, String> listed = new HashMap<>();
|
||||
service.listServiceQuotas("vpc", null, null, 100, "us-east-1", "000000000000").withArray("Quotas")
|
||||
service.listServiceQuotas("vpc", null, null, null, 100, "us-east-1", "000000000000").withArray("Quotas")
|
||||
.forEach(q -> listed.put(q.path("QuotaCode").asText(), q.path("QuotaName").asText()));
|
||||
want.forEach((code, name) -> assertEquals(name, listed.get(code), listed.toString()));
|
||||
assertEquals(want.size() + 3, listed.size(), "synthetic quotas still appended: " + listed);
|
||||
@@ -166,7 +166,7 @@ class ServiceQuotasServiceTest {
|
||||
void malformedServiceCodeIsRejected() {
|
||||
for (String bad : List.of("!!!", "1codebuild", "-codebuild", "code build", "c", "a".repeat(64))) {
|
||||
AwsException listing = assertThrows(AwsException.class,
|
||||
() -> service.listServiceQuotas(bad, null, null, null, "us-east-1", "000000000000"),
|
||||
() -> service.listServiceQuotas(bad, null, null, null, null, "us-east-1", "000000000000"),
|
||||
"expected ListServiceQuotas to reject " + bad);
|
||||
assertEquals("IllegalArgumentException", listing.getErrorCode(), bad);
|
||||
assertEquals(400, listing.getHttpStatus(), bad);
|
||||
@@ -182,7 +182,7 @@ class ServiceQuotasServiceTest {
|
||||
void wellFormedServiceCodesAreStillAccepted() {
|
||||
// Including an unknown-but-valid code: generating a catalog for those is deliberate.
|
||||
for (String good : List.of("codebuild", "widgetfactory", "elasticloadbalancing", "AWS-Thing", "ec")) {
|
||||
assertTrue(service.listServiceQuotas(good, null, null, null, "us-east-1", ACCOUNT_ID)
|
||||
assertTrue(service.listServiceQuotas(good, null, null, null, null, "us-east-1", ACCOUNT_ID)
|
||||
.withArray("Quotas").size() > 0, good);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user