mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(ec2): honor ZoneName, ZoneId and filters in DescribeAvailabilityZones (#5475)
DescribeAvailabilityZones ignored the ZoneName, ZoneId and Filter parameters and always returned every zone of the region. It now reads and applies all three: - ZoneName and ZoneId are mutually exclusive (InvalidParameterCombination). - A name or id the region does not publish is refused with InvalidParameterValue rather than silently dropped, so a wrong id cannot pass as an empty result. - Filters: zone-name, zone-id, zone-type, state, region-name, message, opt-in-status, group-name, group-long-name, parent-zone-id and parent-zone-name, with repeated same-name filters preserved for AND semantics. - group-name and group-long-name are modelled from the region (its id and display name) so those filters match instead of being compared against zone-type, and opt-in-status is read from the zone. CreateSubnet now refuses a zone name outside the published zones too, so a subnet can always be paired with a zone DescribeAvailabilityZones lists. The published zones stay a/b/c per region, matching the seeded default subnets and the compatibility suite. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
86b32584f3
commit
9cd97f13f4
5 files changed
+463
-20
No files matched your search
@@ -390,6 +390,18 @@ public class Ec2QueryHandler {
|
||||
|
||||
private Map<String, List<String>> getFilters(MultivaluedMap<String, String> p) {
|
||||
Map<String, List<String>> filters = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, List<String>> filter : getFiltersList(p)) {
|
||||
filters.put(filter.getKey(), filter.getValue());
|
||||
}
|
||||
return filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns filters as a list of entries to preserve multiple filters with the same name
|
||||
* (AND semantics across filters, OR within values of the same filter).
|
||||
*/
|
||||
private List<Map.Entry<String, List<String>>> getFiltersList(MultivaluedMap<String, String> p) {
|
||||
List<Map.Entry<String, List<String>>> filters = new ArrayList<>();
|
||||
for (int i = 1; ; i++) {
|
||||
String name = p.getFirst("Filter." + i + ".Name");
|
||||
if (name == null) break;
|
||||
@@ -399,7 +411,7 @@ public class Ec2QueryHandler {
|
||||
if (v == null) break;
|
||||
values.add(v);
|
||||
}
|
||||
filters.put(name, values);
|
||||
filters.add(new AbstractMap.SimpleEntry<>(name, values));
|
||||
}
|
||||
return filters;
|
||||
}
|
||||
@@ -1644,7 +1656,7 @@ public class Ec2QueryHandler {
|
||||
|
||||
private Response handleDescribeVpcEndpointServices(MultivaluedMap<String, String> p, String region) {
|
||||
List<String> requested = getList(p, "ServiceName");
|
||||
List<String> azNames = service.describeAvailabilityZones(region).stream()
|
||||
List<String> azNames = service.describeAvailabilityZones(region, List.of(), List.of(), null).stream()
|
||||
.map(z -> z.get("zoneName")).toList();
|
||||
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
@@ -4369,7 +4381,11 @@ public class Ec2QueryHandler {
|
||||
// ─── Region / AZ / Account handlers ──────────────────────────────────────
|
||||
|
||||
private Response handleDescribeAvailabilityZones(MultivaluedMap<String, String> p, String region) {
|
||||
List<Map<String, String>> zones = service.describeAvailabilityZones(region);
|
||||
List<String> zoneNames = getList(p, "ZoneName");
|
||||
List<String> zoneIds = getList(p, "ZoneId");
|
||||
List<Map.Entry<String, List<String>>> filters = getFiltersList(p);
|
||||
|
||||
List<Map<String, String>> zones = service.describeAvailabilityZones(region, zoneNames, zoneIds, filters);
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("DescribeAvailabilityZonesResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
@@ -4380,7 +4396,10 @@ public class Ec2QueryHandler {
|
||||
.elem("zoneState", az.get("state"))
|
||||
.elem("regionName", az.get("regionName"))
|
||||
.elem("zoneId", az.get("zoneId"))
|
||||
.elem("groupName", az.get("groupName"))
|
||||
.elem("groupLongName", az.get("groupLongName"))
|
||||
.elem("zoneType", az.get("zoneType"))
|
||||
.elem("optInStatus", az.get("optInStatus"))
|
||||
.start("messageSet").end("messageSet")
|
||||
.end("item");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.AvailabilityZoneIds;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartition;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartitions;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.CidrCanonicalizer;
|
||||
import io.github.hectorvent.floci.core.common.ContainerTeardown;
|
||||
@@ -145,7 +146,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
/**
|
||||
* The availability zones every region is modelled with. DescribeAvailabilityZones publishes
|
||||
* exactly these, the seeded default subnets sit in them, and CreateSubnet refuses a zone id
|
||||
* outside them, so the three cannot drift apart.
|
||||
* outside them, so they cannot drift apart.
|
||||
*/
|
||||
private static final String[] MODELLED_ZONE_SUFFIXES = {"a", "b", "c"};
|
||||
private static final DateTimeFormatter ISO_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
|
||||
@@ -213,6 +214,10 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
private static final Set<String> EGRESS_ONLY_INTERNET_GATEWAY_FILTERS = Set.of(
|
||||
"attachment.state", "attachment.vpc-id",
|
||||
"egress-only-internet-gateway-id", "tag-key", "tag-value");
|
||||
private static final Set<String> AVAILABILITY_ZONE_FILTERS = Set.of(
|
||||
"group-long-name", "group-name", "message", "opt-in-status",
|
||||
"parent-zone-id", "parent-zone-name", "region-name", "state",
|
||||
"zone-id", "zone-name", "zone-type");
|
||||
private static final Set<String> SPOT_PRICE_HISTORY_FILTERS = Set.of(
|
||||
"availability-zone", "availability-zone-id",
|
||||
"instance-type", "product-description",
|
||||
@@ -4682,7 +4687,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
// matchesFilters answers true for a name it does not recognise, so without this an
|
||||
// unsupported filter matches every VPC instead of narrowing anything. Real EC2 rejects the
|
||||
// name outright, which is the difference between a wrong result and an error.
|
||||
requireSupportedFilters(filters, VPC_FILTERS);
|
||||
requireSupportedFilters(filters.keySet(), VPC_FILTERS);
|
||||
return vpcs.scan(k -> true).stream()
|
||||
.filter(v -> v.getRegion().equals(region))
|
||||
.filter(v -> vpcIds.isEmpty() || vpcIds.contains(v.getVpcId()))
|
||||
@@ -4692,7 +4697,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
|
||||
public List<String> describeVpnGatewayIds(
|
||||
List<String> gatewayIds, Map<String, List<String>> filters) {
|
||||
requireSupportedFilters(filters, VPN_GATEWAY_FILTERS);
|
||||
requireSupportedFilters(filters.keySet(), VPN_GATEWAY_FILTERS);
|
||||
if (!gatewayIds.isEmpty()) {
|
||||
throw new AwsException("InvalidVpnGatewayID.NotFound",
|
||||
"The vpnGateway ID '" + gatewayIds.getFirst() + "' does not exist", 400);
|
||||
@@ -4703,12 +4708,12 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
// AWS answers an unknown egress-only gateway ID with an empty set, not an error; callers such as
|
||||
// the Terraform provider treat the empty result as "not found".
|
||||
public List<String> describeEgressOnlyInternetGatewayIds(Map<String, List<String>> filters) {
|
||||
requireSupportedFilters(filters, EGRESS_ONLY_INTERNET_GATEWAY_FILTERS);
|
||||
requireSupportedFilters(filters.keySet(), EGRESS_ONLY_INTERNET_GATEWAY_FILTERS);
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private void requireSupportedFilters(Map<String, List<String>> filters, Set<String> supportedFilters) {
|
||||
filters.keySet().stream()
|
||||
private void requireSupportedFilters(Collection<String> filterNames, Set<String> supportedFilters) {
|
||||
filterNames.stream()
|
||||
.filter(name -> !supportedFilters.contains(name)
|
||||
&& !(supportedFilters.contains("tag-key") && name.startsWith("tag:")))
|
||||
.findFirst()
|
||||
@@ -5615,7 +5620,18 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
*/
|
||||
private String resolveSubnetZoneName(String region, String availabilityZone, String availabilityZoneId) {
|
||||
if (!isSet(availabilityZoneId)) {
|
||||
return isSet(availabilityZone) ? availabilityZone : region + "a";
|
||||
String zoneName = isSet(availabilityZone) ? availabilityZone : region + "a";
|
||||
boolean zoneExists = Arrays.stream(MODELLED_ZONE_SUFFIXES)
|
||||
.anyMatch(suffix -> zoneName.equals(region + suffix));
|
||||
if (!zoneExists) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Value (" + zoneName + ") for parameter availabilityZone is invalid. Subnets can "
|
||||
+ "currently only be created in the following availability zones: "
|
||||
+ Arrays.stream(MODELLED_ZONE_SUFFIXES)
|
||||
.map(suffix -> region + suffix)
|
||||
.collect(Collectors.joining(", ")) + ".", 400);
|
||||
}
|
||||
return zoneName;
|
||||
}
|
||||
String fromId = zoneNameForZoneId(region, availabilityZoneId);
|
||||
if (isSet(availabilityZone) && !availabilityZone.equals(fromId)) {
|
||||
@@ -9301,19 +9317,105 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
|
||||
// ─── Availability Zones & Regions ─────────────────────────────────────────
|
||||
|
||||
public List<Map<String, String>> describeAvailabilityZones(String region) {
|
||||
List<Map<String, String>> zones = new ArrayList<>();
|
||||
public List<Map<String, String>> describeAvailabilityZones(String region, List<String> zoneNames,
|
||||
List<String> zoneIds,
|
||||
List<Map.Entry<String, List<String>>> filters) {
|
||||
List<Map<String, String>> allZones = new ArrayList<>();
|
||||
String[] azSuffixes = MODELLED_ZONE_SUFFIXES;
|
||||
for (String suffix : azSuffixes) {
|
||||
String zoneName = region + suffix;
|
||||
Map<String, String> az = new LinkedHashMap<>();
|
||||
az.put("zoneName", region + suffix);
|
||||
az.put("zoneName", zoneName);
|
||||
az.put("state", "available");
|
||||
az.put("regionName", region);
|
||||
az.put("zoneId", AvailabilityZoneIds.forZoneName(region, region + suffix));
|
||||
az.put("zoneId", AvailabilityZoneIds.forZoneName(region, zoneName));
|
||||
az.put("zoneType", "availability-zone");
|
||||
zones.add(az);
|
||||
az.put("optInStatus", "opt-in-not-required");
|
||||
az.put("groupName", zoneGroupName(region));
|
||||
az.put("groupLongName", zoneGroupLongName(region));
|
||||
allZones.add(az);
|
||||
}
|
||||
return zones;
|
||||
|
||||
// Filter by ZoneName
|
||||
if (!zoneNames.isEmpty()) {
|
||||
Set<String> requestedNames = new HashSet<>(zoneNames);
|
||||
for (String requestedName : requestedNames) {
|
||||
boolean found = false;
|
||||
for (Map<String, String> az : allZones) {
|
||||
if (requestedName.equals(az.get("zoneName"))) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"The zone name '" + requestedName + "' is not valid for this region.", 400);
|
||||
}
|
||||
}
|
||||
allZones.removeIf(az -> !requestedNames.contains(az.get("zoneName")));
|
||||
}
|
||||
|
||||
// Filter by ZoneId: an id this region does not publish is a client error, exactly
|
||||
// as an unknown ZoneName is, rather than a silent empty result.
|
||||
if (!zoneIds.isEmpty()) {
|
||||
Set<String> requestedIds = new HashSet<>(zoneIds);
|
||||
Set<String> publishedIds = allZones.stream()
|
||||
.map(az -> az.get("zoneId"))
|
||||
.collect(Collectors.toSet());
|
||||
for (String requestedId : requestedIds) {
|
||||
if (!publishedIds.contains(requestedId)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"The zone ID '" + requestedId + "' is not valid for this region.", 400);
|
||||
}
|
||||
}
|
||||
allZones.removeIf(az -> !requestedIds.contains(az.get("zoneId")));
|
||||
}
|
||||
|
||||
// Apply filters
|
||||
if (filters != null && !filters.isEmpty()) {
|
||||
requireSupportedFilters(filters.stream().map(Map.Entry::getKey).toList(),
|
||||
AVAILABILITY_ZONE_FILTERS);
|
||||
for (Map.Entry<String, List<String>> filter : filters) {
|
||||
allZones.removeIf(az -> !zoneMatchesFilter(az, filter.getKey(), filter.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
return allZones;
|
||||
}
|
||||
|
||||
private boolean zoneMatchesFilter(Map<String, String> az, String filterName, List<String> values) {
|
||||
return switch (filterName) {
|
||||
case "zone-name" -> matchesValue(az.get("zoneName"), values);
|
||||
case "zone-id" -> matchesValue(az.get("zoneId"), values);
|
||||
case "zone-type" -> matchesValue(az.get("zoneType"), values);
|
||||
case "state" -> matchesValue(az.get("state"), values);
|
||||
case "region-name" -> matchesValue(az.get("regionName"), values);
|
||||
case "group-name" -> matchesValue(az.get("groupName"), values);
|
||||
case "group-long-name" -> matchesValue(az.get("groupLongName"), values);
|
||||
case "opt-in-status" -> matchesValue(az.get("optInStatus"), values);
|
||||
case "message", "parent-zone-id", "parent-zone-name" -> matchesValue("", values);
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The zone group of the Availability Zones in a Region. AWS renamed this from the bare
|
||||
* Region code to {@code <region>-zg-1} in October 2024, so the group name is now
|
||||
* distinguishable from a Local Zone group such as {@code us-west-2-lax-1}.
|
||||
*/
|
||||
private static String zoneGroupName(String region) {
|
||||
return region + "-zg-1";
|
||||
}
|
||||
|
||||
/**
|
||||
* The long name of an Availability Zone group, which AWS forms from the Region's display
|
||||
* name and the group number, for example {@code US East (N. Virginia) 1}.
|
||||
*/
|
||||
private static String zoneGroupLongName(String region) {
|
||||
return AwsPartitions.forRegionOrCommercial(region)
|
||||
.region(region)
|
||||
.map(AwsPartition.Region::description)
|
||||
.orElse(region) + " 1";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -9365,7 +9467,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
: "availability-zone";
|
||||
List<String> locations = "region".equals(effectiveLocationType)
|
||||
? List.of(region)
|
||||
: describeAvailabilityZones(region).stream()
|
||||
: describeAvailabilityZones(region, List.of(), List.of(), null).stream()
|
||||
.map(zone -> zone.get("zoneName"))
|
||||
.toList();
|
||||
List<String> locationFilter = filters != null ? filters.get("location") : null;
|
||||
@@ -10993,7 +11095,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
Instant endTime,
|
||||
Map<String, List<String>> filters) {
|
||||
if (filters != null && !filters.isEmpty()) {
|
||||
requireSupportedFilters(filters, SPOT_PRICE_HISTORY_FILTERS);
|
||||
requireSupportedFilters(filters.keySet(), SPOT_PRICE_HISTORY_FILTERS);
|
||||
}
|
||||
if (productDescriptions != null) {
|
||||
for (String desc : productDescriptions) {
|
||||
@@ -11044,7 +11146,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
return new SpotPriceHistoryResult(List.of(), null);
|
||||
}
|
||||
|
||||
List<Map<String, String>> zones = describeAvailabilityZones(region);
|
||||
List<Map<String, String>> zones = describeAvailabilityZones(region, List.of(), List.of(), null);
|
||||
if (availabilityZone != null) {
|
||||
zones = zones.stream()
|
||||
.filter(z -> availabilityZone.equals(z.get("zoneName")))
|
||||
|
||||
+1
-1
@@ -277,7 +277,7 @@ class Ec2DedicatedHostIntegrationTest {
|
||||
@Order(10)
|
||||
void allocateRejectsANonexistentZoneAndStoresNothing() {
|
||||
int before = hostCount();
|
||||
post("Action", "AllocateHosts", "InstanceType", "m5.large", "AvailabilityZone", "us-east-1z")
|
||||
post("Action", "AllocateHosts", "InstanceType", "m5.large", "AvailabilityZone", "us-east-1aa")
|
||||
.statusCode(400).body(containsString("InvalidParameterValue"));
|
||||
org.junit.jupiter.api.Assertions.assertEquals(before, hostCount());
|
||||
}
|
||||
|
||||
@@ -161,8 +161,292 @@ class Ec2IntegrationTest {
|
||||
startsWith("us-east-1"));
|
||||
}
|
||||
|
||||
// DescribeAvailabilityZones parameter validation and filtering
|
||||
@Test
|
||||
@Order(5)
|
||||
void describeAvailabilityZonesWithZoneName() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("ZoneName.1", "us-east-1a")
|
||||
.formParam("ZoneName.2", "us-east-1c")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(2))
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.zoneName",
|
||||
hasItems("us-east-1a", "us-east-1c"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void describeAvailabilityZonesWithZoneId() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("ZoneId.1", "use1-az1")
|
||||
.formParam("ZoneId.2", "use1-az3")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(2))
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.zoneId",
|
||||
hasItems("use1-az1", "use1-az3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void describeAvailabilityZonesRejectsUnknownZoneName() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("ZoneName.1", "us-east-1aa")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void describeAvailabilityZonesRejectsUnknownZoneId() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("ZoneId.1", "use1-az99")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void describeAvailabilityZonesWithZoneNameAndZoneIdTogether() {
|
||||
// Terraform's aws_availability_zone data source sends ZoneIds and ZoneNames together,
|
||||
// so the pair is narrowed to their intersection rather than refused.
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("ZoneName.1", "us-east-1a")
|
||||
.formParam("ZoneName.2", "us-east-1b")
|
||||
.formParam("ZoneId.1", "use1-az1")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(1))
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item[0].zoneName",
|
||||
equalTo("us-east-1a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void describeAvailabilityZonesFilterByZoneName() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "zone-name")
|
||||
.formParam("Filter.1.Value.1", "us-east-1a")
|
||||
.formParam("Filter.1.Value.2", "us-east-1b")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(2))
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.zoneName",
|
||||
hasItems("us-east-1a", "us-east-1b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void describeAvailabilityZonesFilterByZoneId() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "zone-id")
|
||||
.formParam("Filter.1.Value.1", "use1-az2")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(1))
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.zoneId",
|
||||
equalTo("use1-az2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void describeAvailabilityZonesFilterByState() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "state")
|
||||
.formParam("Filter.1.Value.1", "available")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void describeAvailabilityZonesFilterByRegionName() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "region-name")
|
||||
.formParam("Filter.1.Value.1", "us-east-1")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void describeAvailabilityZonesFilterByZoneType() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "zone-type")
|
||||
.formParam("Filter.1.Value.1", "availability-zone")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
void describeAvailabilityZonesFilterByMessage() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "message")
|
||||
.formParam("Filter.1.Value.1", "any")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
void describeAvailabilityZonesFilterByOptInStatus() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "opt-in-status")
|
||||
.formParam("Filter.1.Value.1", "opt-in-not-required")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(3))
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item[0].optInStatus",
|
||||
equalTo("opt-in-not-required"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void describeAvailabilityZonesFilterByGroupName() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "group-name")
|
||||
.formParam("Filter.1.Value.1", "us-east-1-zg-1")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(3))
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item[0].groupName",
|
||||
equalTo("us-east-1-zg-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void describeAvailabilityZonesFilterByGroupLongName() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "group-long-name")
|
||||
.formParam("Filter.1.Value.1", "US East (N. Virginia) 1")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(3))
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item[0].groupLongName",
|
||||
equalTo("US East (N. Virginia) 1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void describeAvailabilityZonesRejectsInvalidFilterName() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "invalid-filter")
|
||||
.formParam("Filter.1.Value.1", "any")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"))
|
||||
.body("Response.Errors.Error.Message",
|
||||
containsString("The filter 'invalid-filter' is invalid"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void describeAvailabilityZonesMultipleFiltersAndSemantics() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "zone-name")
|
||||
.formParam("Filter.1.Value.1", "us-east-1a")
|
||||
.formParam("Filter.1.Value.2", "us-east-1b")
|
||||
.formParam("Filter.2.Name", "state")
|
||||
.formParam("Filter.2.Value.1", "available")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(2))
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.zoneName",
|
||||
hasItems("us-east-1a", "us-east-1b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
void describeAvailabilityZonesMultipleSameNameFiltersAndSemantics() {
|
||||
// Two zone-name filters - should AND them
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("Filter.1.Name", "zone-name")
|
||||
.formParam("Filter.1.Value.1", "us-east-1a")
|
||||
.formParam("Filter.2.Name", "zone-name")
|
||||
.formParam("Filter.2.Value.1", "us-east-1b")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void describeRegions() {
|
||||
given()
|
||||
.formParam("Action", "DescribeRegions")
|
||||
|
||||
+38
@@ -177,4 +177,42 @@ class Ec2SubnetAvailabilityZoneIdIntegrationTest {
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aNonModeledZoneNameIsRefused() {
|
||||
given()
|
||||
.formParam("Action", "CreateSubnet")
|
||||
.formParam("VpcId", vpcId)
|
||||
.formParam("CidrBlock", "10.90.8.0/24")
|
||||
.formParam("AvailabilityZone", "us-east-1-custom")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"))
|
||||
.body("Response.Errors.Error.Message", containsString(
|
||||
"Value (us-east-1-custom) for parameter availabilityZone is invalid. Subnets can "
|
||||
+ "currently only be created in the following availability zones: "
|
||||
+ "us-east-1a, us-east-1b, us-east-1c."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aZoneNameBeyondModeledRangeIsRefused() {
|
||||
given()
|
||||
.formParam("Action", "CreateSubnet")
|
||||
.formParam("VpcId", vpcId)
|
||||
.formParam("CidrBlock", "10.90.9.0/24")
|
||||
.formParam("AvailabilityZone", "us-east-1aa")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"))
|
||||
.body("Response.Errors.Error.Message", containsString(
|
||||
"Value (us-east-1aa) for parameter availabilityZone is invalid. Subnets can "
|
||||
+ "currently only be created in the following availability zones: "
|
||||
+ "us-east-1a, us-east-1b, us-east-1c."));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user