mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(servicequotas): report the standard EC2 quota default (#5778)
* fix(servicequotas): report the standard EC2 quota default * test(servicequotas): cover paged quotas and account isolation
This commit is contained in:
1 parent
f897dfc3b6
commit
167336fc73
7 files changed
+191
-5
No files matched your search
+78
@@ -6,6 +6,8 @@ import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -182,6 +184,82 @@ class ServiceQuotasIntegrationTest {
|
||||
.body("Quota.GlobalQuota", equalTo(true));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(value = {"us-east-1|111111111111|aws", "cn-north-1|333333333333|aws-cn"}, delimiter = '|')
|
||||
void ec2StandardQuotaUsesAwsCodeAndRegionalOwner(String region, String account, String partition) {
|
||||
String code = "L-1216C47A";
|
||||
String name = "Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances";
|
||||
String authorization = "AWS4-HMAC-SHA256 Credential=" + account + "/20261015/"
|
||||
+ region + "/servicequotas/aws4_request";
|
||||
for (String action : List.of("GetServiceQuota", "GetAWSDefaultServiceQuota")) {
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "ServiceQuotasV20190624." + action)
|
||||
.header("Authorization", authorization)
|
||||
.body("{\"ServiceCode\":\"ec2\",\"QuotaCode\":\"" + code + "\"}")
|
||||
.when().post("/")
|
||||
.then().log().ifValidationFails().statusCode(200)
|
||||
.body("Quota.QuotaCode", equalTo(code))
|
||||
.body("Quota.QuotaName", equalTo(name))
|
||||
.body("Quota.Value", equalTo(5.0f))
|
||||
.body("Quota.Adjustable", equalTo(true))
|
||||
.body("Quota.GlobalQuota", equalTo(false))
|
||||
.body("Quota.QuotaAppliedAtLevel", equalTo("ACCOUNT"))
|
||||
.body("Quota.QuotaArn", equalTo("arn:" + partition + ":servicequotas:" + region + ":"
|
||||
+ account + ":ec2/" + code));
|
||||
}
|
||||
for (String action : List.of("ListServiceQuotas", "ListAWSDefaultServiceQuotas")) {
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "ServiceQuotasV20190624." + action)
|
||||
.header("Authorization", authorization)
|
||||
.body("{\"ServiceCode\":\"ec2\",\"MaxResults\":100}")
|
||||
.when().post("/")
|
||||
.then().log().ifValidationFails().statusCode(200)
|
||||
.body("Quotas.find { it.QuotaCode == 'L-1216C47A' }.QuotaName", equalTo(name))
|
||||
.body("Quotas.find { it.QuotaCode == 'L-1216C47A' }.Value", equalTo(5.0f))
|
||||
.body("Quotas.size()", equalTo(4));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"us-east-1,aws", "cn-north-1,aws-cn"})
|
||||
void ec2IncreaseRequestsRemainIsolatedByAccount(String region, String partition) {
|
||||
String firstAccount = "111111111111";
|
||||
String secondAccount = "333333333333";
|
||||
String requestBody = "{\"ServiceCode\":\"ec2\",\"QuotaCode\":\"L-1216C47A\",\"DesiredValue\":10}";
|
||||
String firstId = quotaRequest("RequestServiceQuotaIncrease", requestBody, region, firstAccount)
|
||||
.then().statusCode(200)
|
||||
.body("RequestedQuota.QuotaArn", equalTo("arn:" + partition + ":servicequotas:" + region
|
||||
+ ":" + firstAccount + ":ec2/L-1216C47A"))
|
||||
.extract().path("RequestedQuota.Id");
|
||||
String secondId = quotaRequest("RequestServiceQuotaIncrease", requestBody, region, secondAccount)
|
||||
.then().statusCode(200)
|
||||
.body("RequestedQuota.QuotaArn", equalTo("arn:" + partition + ":servicequotas:" + region
|
||||
+ ":" + secondAccount + ":ec2/L-1216C47A"))
|
||||
.extract().path("RequestedQuota.Id");
|
||||
assertNotEquals(firstId, secondId);
|
||||
for (String account : List.of(firstAccount, secondAccount)) {
|
||||
String ownId = account.equals(firstAccount) ? firstId : secondId;
|
||||
String otherId = account.equals(firstAccount) ? secondId : firstId;
|
||||
quotaRequest("RequestServiceQuotaIncrease", requestBody, region, account)
|
||||
.then().statusCode(400).body("__type", equalTo("ResourceAlreadyExistsException"));
|
||||
quotaRequest("ListRequestedServiceQuotaChangeHistoryByQuota",
|
||||
"{\"ServiceCode\":\"ec2\",\"QuotaCode\":\"L-1216C47A\"}", region, account)
|
||||
.then().statusCode(200).body("RequestedQuotas.Id", equalTo(List.of(ownId)));
|
||||
quotaRequest("GetRequestedServiceQuotaChange", "{\"RequestId\":\"" + ownId + "\"}", region, account)
|
||||
.then().statusCode(200).body("RequestedQuota.Id", equalTo(ownId));
|
||||
quotaRequest("GetRequestedServiceQuotaChange", "{\"RequestId\":\"" + otherId + "\"}", region, account)
|
||||
.then().statusCode(400).body("__type", equalTo("NoSuchResourceException"));
|
||||
}
|
||||
}
|
||||
|
||||
private Response quotaRequest(String action, String body, String region, String account) {
|
||||
return given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "ServiceQuotasV20190624." + action)
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=" + account
|
||||
+ "/20261016/" + region + "/servicequotas/aws4_request")
|
||||
.body(body).when().post("/");
|
||||
}
|
||||
|
||||
@Test
|
||||
void vpcQuotasUseAwsQuotaCodesAsDefaultAndApplied() {
|
||||
for (String target : new String[] {"GetAWSDefaultServiceQuota", "GetServiceQuota"}) {
|
||||
|
||||
+29
@@ -11,7 +11,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
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;
|
||||
|
||||
@@ -41,6 +43,33 @@ class ServiceQuotasServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void ec2StandardQuotaRetainsCanonicalMetadataWhenListingAndReading() {
|
||||
String code = "L-1216C47A";
|
||||
String name = "Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances";
|
||||
JsonNode quota = assertDoesNotThrow(() ->
|
||||
service.getServiceQuota("ec2", code, "us-east-1", ACCOUNT_ID)).path("Quota");
|
||||
assertEquals(code, quota.path("QuotaCode").asText());
|
||||
assertEquals(name, quota.path("QuotaName").asText());
|
||||
assertEquals(5.0, quota.path("Value").asDouble());
|
||||
assertTrue(quota.path("Adjustable").asBoolean());
|
||||
assertTrue(quota.path("GlobalQuota").isBoolean());
|
||||
assertFalse(quota.path("GlobalQuota").asBoolean());
|
||||
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");
|
||||
assertEquals(4, listed.size());
|
||||
int matching = 0;
|
||||
for (JsonNode entry : listed) {
|
||||
if (code.equals(entry.path("QuotaCode").asText())) {
|
||||
assertEquals(quota, entry);
|
||||
matching++;
|
||||
}
|
||||
}
|
||||
assertEquals(1, matching);
|
||||
}
|
||||
|
||||
@Test
|
||||
void codebuildIncludesConcurrentlyRunningBuilds() {
|
||||
List<String> codes = service.quotasFor("codebuild").stream()
|
||||
|
||||
Reference in new issue
Block a user