mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ec2): support managed prefix lists (#2105)
* feat(ec2): support managed prefix lists Implement CreateManagedPrefixList, DescribeManagedPrefixLists, GetManagedPrefixListEntries, ModifyManagedPrefixList and DeleteManagedPrefixList. Entries are versioned: a list starts at version 1 and every modification that changes entries stores a new version, so GetManagedPrefixListEntries can serve an earlier TargetVersion. Renaming or raising MaxEntries does not create a version, CurrentVersion makes a modification conditional, and removals apply before additions so one call can replace an entry's description. The AWS-managed gateway-endpoint lists are now built once and served by both DescribeManagedPrefixLists and the existing DescribePrefixLists, so the two surfaces cannot report different CIDRs for the same list. They are read-only. Closes #2100 * fix(ec2): validate prefix list input and keep tag copies in sync Three defects in the managed prefix list surface: ModifyManagedPrefixList only checked the resulting entry count against MaxEntries, so a zero or negative MaxEntries on an empty list passed the check and persisted an impossible capacity. CreateTags and DeleteTags update the generic tag store and then mirror the result onto the resource, but updateResourceTags had no arm for prefix lists, leaving the copy on the model stale for describe responses and tag filters. MaxEntries and TargetVersion were converted with Integer/Long.valueOf, so malformed input escaped as an unchecked NumberFormatException and became a 500 rather than a structured EC2 client error. * fix(ec2): reject a missing PrefixListId and infer the prefix-list tag type A null PrefixListId reached List.of() inside describeManagedPrefixLists and threw NullPointerException, so DeleteManagedPrefixList, GetManagedPrefixListEntries and ModifyManagedPrefixList answered a request that never named a list with a 500 rather than a client error. Guard the lookup and raise MissingParameter. inferResourceType had no pl- arm, so tags on a prefix list were stored but reported as resourceType "unknown" and were invisible to a DescribeTags filter on resource-type. The existing test only covered describe and tag: filters, which is why this went unnoticed. Also cover the accepting branch of the address-family check, which until now was only reached by the rejecting case. * fix(ec2): treat a blank numeric parameter as malformed rather than absent intOrNull and longOrNull returned null for a present but blank value, which the callers read as "parameter not supplied". For CurrentVersion that silently downgraded a conditional ModifyManagedPrefixList to an unconditional one, so a request that asked to be gated on a version was applied anyway. Only an absent parameter is null now; a blank one reaches the parse and surfaces as InvalidParameterValue. * fix(ec2): report PrefixListVersionMismatch for a stale CurrentVersion A conditional ModifyManagedPrefixList that loses the version check returns PrefixListVersionMismatch on AWS, not IncorrectState; verified against a live account, which also supplies the message. The Terraform provider keys its retry handling on that code, so the previous one would have left a caller unable to recognise a losing conditional update. --------- Co-authored-by: Michal Schreiber <michal.p.schreiber@gmail.com>
This commit is contained in:
1 parent
3ce5041c71
commit
ac4b865a34
9 files changed
+1228
-8
No files matched your search
+292
@@ -0,0 +1,292 @@
|
||||
package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Integration tests for managed prefix lists over the EC2 Query protocol: create, describe with
|
||||
* filters, entry versioning through modify, and delete.
|
||||
*
|
||||
* <p>Ordered because the cases build on one prefix list, mirroring how a client drives the
|
||||
* resource through its lifecycle.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class Ec2ManagedPrefixListIntegrationTest {
|
||||
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/ec2/aws4_request";
|
||||
|
||||
private static final String LIST_NAME = "integration-prefix-list";
|
||||
|
||||
private static String prefixListId;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createManagedPrefixList() {
|
||||
prefixListId = given()
|
||||
.formParam("Action", "CreateManagedPrefixList")
|
||||
.formParam("PrefixListName", LIST_NAME)
|
||||
.formParam("AddressFamily", "IPv4")
|
||||
.formParam("MaxEntries", "5")
|
||||
.formParam("Entry.1.Cidr", "10.0.0.0/8")
|
||||
.formParam("Entry.1.Description", "corporate")
|
||||
.formParam("TagSpecification.1.ResourceType", "prefix-list")
|
||||
.formParam("TagSpecification.1.Tag.1.Key", "env")
|
||||
.formParam("TagSpecification.1.Tag.1.Value", "test")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CreateManagedPrefixListResponse.prefixList.prefixListName", equalTo(LIST_NAME))
|
||||
.body("CreateManagedPrefixListResponse.prefixList.addressFamily", equalTo("IPv4"))
|
||||
.body("CreateManagedPrefixListResponse.prefixList.state", equalTo("create-complete"))
|
||||
.body("CreateManagedPrefixListResponse.prefixList.version", equalTo("1"))
|
||||
.body("CreateManagedPrefixListResponse.prefixList.maxEntries", equalTo("5"))
|
||||
.body("CreateManagedPrefixListResponse.prefixList.prefixListArn",
|
||||
containsString(":prefix-list/pl-"))
|
||||
.body("CreateManagedPrefixListResponse.prefixList.tagSet.item.key", equalTo("env"))
|
||||
.extract().path("CreateManagedPrefixListResponse.prefixList.prefixListId");
|
||||
|
||||
org.junit.jupiter.api.Assertions.assertTrue(prefixListId.startsWith("pl-"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void describeByIdReturnsTheCreatedList() {
|
||||
given()
|
||||
.formParam("Action", "DescribeManagedPrefixLists")
|
||||
.formParam("PrefixListId.1", prefixListId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeManagedPrefixListsResponse.prefixListSet.item.prefixListName", equalTo(LIST_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void describeIncludesAwsManagedGatewayLists() {
|
||||
given()
|
||||
.formParam("Action", "DescribeManagedPrefixLists")
|
||||
.formParam("Filter.1.Name", "prefix-list-name")
|
||||
.formParam("Filter.1.Value.1", "com.amazonaws.us-east-1.s3")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeManagedPrefixListsResponse.prefixListSet.item.prefixListId", equalTo("pl-63a5400a"))
|
||||
.body("DescribeManagedPrefixListsResponse.prefixListSet.item.ownerId", equalTo("AWS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void getEntriesReturnsTheInitialEntry() {
|
||||
given()
|
||||
.formParam("Action", "GetManagedPrefixListEntries")
|
||||
.formParam("PrefixListId", prefixListId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("GetManagedPrefixListEntriesResponse.entrySet.item.cidr", equalTo("10.0.0.0/8"))
|
||||
.body("GetManagedPrefixListEntriesResponse.entrySet.item.description", equalTo("corporate"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void modifyAddsAnEntryAndBumpsVersion() {
|
||||
given()
|
||||
.formParam("Action", "ModifyManagedPrefixList")
|
||||
.formParam("PrefixListId", prefixListId)
|
||||
.formParam("AddEntry.1.Cidr", "192.168.0.0/16")
|
||||
.formParam("AddEntry.1.Description", "lab")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ModifyManagedPrefixListResponse.prefixList.version", equalTo("2"))
|
||||
.body("ModifyManagedPrefixListResponse.prefixList.state", equalTo("modify-complete"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "GetManagedPrefixListEntries")
|
||||
.formParam("PrefixListId", prefixListId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("GetManagedPrefixListEntriesResponse.entrySet.item.cidr",
|
||||
hasItems("10.0.0.0/8", "192.168.0.0/16"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void earlierVersionRemainsRetrievable() {
|
||||
given()
|
||||
.formParam("Action", "GetManagedPrefixListEntries")
|
||||
.formParam("PrefixListId", prefixListId)
|
||||
.formParam("TargetVersion", "1")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("GetManagedPrefixListEntriesResponse.entrySet.item.cidr", equalTo("10.0.0.0/8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void modifyWithStaleCurrentVersionIsRejected() {
|
||||
given()
|
||||
.formParam("Action", "ModifyManagedPrefixList")
|
||||
.formParam("PrefixListId", prefixListId)
|
||||
.formParam("CurrentVersion", "1")
|
||||
.formParam("AddEntry.1.Cidr", "172.16.0.0/12")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("PrefixListVersionMismatch"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void modifyingAnAwsManagedListIsRejected() {
|
||||
given()
|
||||
.formParam("Action", "ModifyManagedPrefixList")
|
||||
.formParam("PrefixListId", "pl-63a5400a")
|
||||
.formParam("AddEntry.1.Cidr", "10.1.0.0/16")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("UnsupportedOperation"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void describeUnknownIdIsRejected() {
|
||||
given()
|
||||
.formParam("Action", "DescribeManagedPrefixLists")
|
||||
.formParam("PrefixListId.1", "pl-doesnotexist")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidPrefixListID.NotFound"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void legacyDescribePrefixListsStillServesGatewayLists() {
|
||||
given()
|
||||
.formParam("Action", "DescribePrefixLists")
|
||||
.formParam("Filter.1.Name", "prefix-list-name")
|
||||
.formParam("Filter.1.Value.1", "com.amazonaws.us-east-1.s3")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribePrefixListsResponse.prefixListSet.item.prefixListId", equalTo("pl-63a5400a"))
|
||||
.body("DescribePrefixListsResponse.prefixListSet.item.cidrSet.item",
|
||||
hasItems("52.216.0.0/15", "54.231.0.0/16"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void malformedNumericParametersReturnAClientError() {
|
||||
given()
|
||||
.formParam("Action", "GetManagedPrefixListEntries")
|
||||
.formParam("PrefixListId", prefixListId)
|
||||
.formParam("TargetVersion", "not-a-number")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "CreateManagedPrefixList")
|
||||
.formParam("PrefixListName", "malformed-max-entries")
|
||||
.formParam("AddressFamily", "IPv4")
|
||||
.formParam("MaxEntries", "plenty")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A blank value is present-but-malformed, not absent. Treating it as absent would drop the
|
||||
* conditional-version check and let a modification through that CurrentVersion asked to gate.
|
||||
*/
|
||||
@Test
|
||||
@Order(11)
|
||||
void blankNumericParametersReturnAClientError() {
|
||||
given()
|
||||
.formParam("Action", "ModifyManagedPrefixList")
|
||||
.formParam("PrefixListId", prefixListId)
|
||||
.formParam("CurrentVersion", " ")
|
||||
.formParam("AddEntry.1.Cidr", "172.16.0.0/12")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "GetManagedPrefixListEntries")
|
||||
.formParam("PrefixListId", prefixListId)
|
||||
.formParam("TargetVersion", "")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void deleteManagedPrefixList() {
|
||||
given()
|
||||
.formParam("Action", "DeleteManagedPrefixList")
|
||||
.formParam("PrefixListId", prefixListId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DeleteManagedPrefixListResponse.prefixList.state", equalTo("delete-complete"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeManagedPrefixLists")
|
||||
.formParam("PrefixListId.1", prefixListId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidPrefixListID.NotFound"));
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Address;
|
||||
import io.github.hectorvent.floci.services.ec2.model.BlockDeviceMapping;
|
||||
import io.github.hectorvent.floci.services.ec2.model.EbsBlockDevice;
|
||||
import io.github.hectorvent.floci.services.ec2.model.ManagedPrefixList;
|
||||
import io.github.hectorvent.floci.services.ec2.model.PrefixListEntry;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Instance;
|
||||
import io.github.hectorvent.floci.services.ec2.model.InternetGateway;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Image;
|
||||
@@ -89,6 +91,32 @@ class Ec2ServicePersistenceTest {
|
||||
assertEquals(12, snapshots.getFirst().getVolumeSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
void managedPrefixListAndItsVersionHistorySurviveRestart(@TempDir Path dir) {
|
||||
Ec2Service first = newService(dir);
|
||||
ManagedPrefixList created = first.createManagedPrefixList(REGION, "persisted-list", "IPv4", 5,
|
||||
List.of(new PrefixListEntry("10.0.0.0/8", "corporate")), List.of());
|
||||
first.modifyManagedPrefixList(REGION, created.getPrefixListId(), null, null, null,
|
||||
List.of(new PrefixListEntry("192.168.0.0/16", "lab")), List.of());
|
||||
|
||||
Ec2Service restarted = newService(dir);
|
||||
|
||||
List<ManagedPrefixList> lists =
|
||||
restarted.describeManagedPrefixLists(REGION, List.of(created.getPrefixListId()), Map.of());
|
||||
assertEquals(1, lists.size(), "managed prefix list must survive restart");
|
||||
assertEquals("persisted-list", lists.getFirst().getPrefixListName());
|
||||
assertEquals(2, lists.getFirst().getVersion());
|
||||
|
||||
// Entry history is a nested map on the model, so a restart is the first place a broken
|
||||
// serialization round trip would show up.
|
||||
assertEquals(2,
|
||||
restarted.getManagedPrefixListEntries(REGION, created.getPrefixListId(), null).size());
|
||||
List<PrefixListEntry> firstVersion =
|
||||
restarted.getManagedPrefixListEntries(REGION, created.getPrefixListId(), 1L);
|
||||
assertEquals(1, firstVersion.size(), "earlier version must survive restart");
|
||||
assertEquals("corporate", firstVersion.getFirst().getDescription());
|
||||
}
|
||||
|
||||
private BlockDeviceMapping blockDeviceMapping(String snapshotId, int volumeSize) {
|
||||
EbsBlockDevice ebs = new EbsBlockDevice();
|
||||
ebs.setSnapshotId(snapshotId);
|
||||
@@ -123,6 +151,7 @@ class Ec2ServicePersistenceTest {
|
||||
load(dir, "ec2-nat-gateways.json", new TypeReference<Map<String, NatGateway>>() {}),
|
||||
load(dir, "ec2-spot-instance-requests.json", new TypeReference<Map<String, SpotInstanceRequest>>() {}),
|
||||
load(dir, "ec2-network-acls.json", new TypeReference<Map<String, NetworkAcl>>() {}),
|
||||
load(dir, "ec2-managed-prefix-lists.json", new TypeReference<Map<String, ManagedPrefixList>>() {}),
|
||||
load(dir, "ec2-tags.json", new TypeReference<Map<String, List<Tag>>>() {}));
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import io.github.hectorvent.floci.services.ec2.model.EbsBlockDevice;
|
||||
import io.github.hectorvent.floci.services.ec2.model.GroupIdentifier;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Instance;
|
||||
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplate;
|
||||
import io.github.hectorvent.floci.services.ec2.model.ManagedPrefixList;
|
||||
import io.github.hectorvent.floci.services.ec2.model.PrefixListEntry;
|
||||
import io.github.hectorvent.floci.services.ec2.model.NetworkInterface;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Reservation;
|
||||
import io.github.hectorvent.floci.services.ec2.model.SecurityGroup;
|
||||
@@ -561,6 +563,265 @@ class Ec2ServiceTest {
|
||||
assertEquals("available", detached.getState());
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Managed prefix lists
|
||||
// =========================================================================
|
||||
|
||||
private static Ec2Service prefixListService() {
|
||||
return new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
|
||||
mock(Ec2PortForwardManager.class),
|
||||
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
|
||||
new InMemoryStorageFactory());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createManagedPrefixListStoresEntriesAtVersionOne() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
ManagedPrefixList list = service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5,
|
||||
List.of(new PrefixListEntry("10.0.0.0/8", "corporate")), List.of());
|
||||
|
||||
assertTrue(list.getPrefixListId().startsWith("pl-"));
|
||||
assertEquals("create-complete", list.getState());
|
||||
assertEquals(1, list.getVersion());
|
||||
assertEquals("000000000000", list.getOwnerId());
|
||||
assertEquals("arn:aws:ec2:us-east-1:000000000000:prefix-list/" + list.getPrefixListId(),
|
||||
list.getPrefixListArn());
|
||||
assertEquals(1, list.currentEntries().size());
|
||||
assertEquals("corporate", list.currentEntries().getFirst().getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createManagedPrefixListRejectsMoreEntriesThanMaxEntries() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createManagedPrefixList(
|
||||
"us-east-1", "corp", "IPv4", 1,
|
||||
List.of(new PrefixListEntry("10.0.0.0/8", null), new PrefixListEntry("10.1.0.0/16", null)),
|
||||
List.of()));
|
||||
assertEquals("InvalidParameterValue", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createManagedPrefixListRejectsCidrOfTheWrongAddressFamily() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createManagedPrefixList(
|
||||
"us-east-1", "corp", "IPv4", 5,
|
||||
List.of(new PrefixListEntry("2001:db8::/32", null)), List.of()));
|
||||
assertEquals("InvalidParameterValue", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeManagedPrefixListsIncludesAwsManagedAndIsRegionScoped() {
|
||||
Ec2Service service = prefixListService();
|
||||
service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5, List.of(), List.of());
|
||||
|
||||
List<ManagedPrefixList> east = service.describeManagedPrefixLists("us-east-1", List.of(), Map.of());
|
||||
assertEquals(3, east.size());
|
||||
assertTrue(east.stream().anyMatch(l -> "com.amazonaws.us-east-1.s3".equals(l.getPrefixListName())));
|
||||
assertTrue(east.stream().anyMatch(l -> "corp".equals(l.getPrefixListName())));
|
||||
|
||||
// The customer list belongs to us-east-1; only the AWS-managed pair shows up elsewhere.
|
||||
List<ManagedPrefixList> west = service.describeManagedPrefixLists("us-west-2", List.of(), Map.of());
|
||||
assertEquals(2, west.size());
|
||||
assertTrue(west.stream().allMatch(ManagedPrefixList::isAwsManaged));
|
||||
assertTrue(west.stream().anyMatch(l -> "com.amazonaws.us-west-2.s3".equals(l.getPrefixListName())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createManagedPrefixListAcceptsIpv6Entries() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
ManagedPrefixList list = service.createManagedPrefixList("us-east-1", "corp-v6", "IPv6", 5,
|
||||
List.of(new PrefixListEntry("2001:db8::/32", "lab")), List.of());
|
||||
|
||||
assertEquals("IPv6", list.getAddressFamily());
|
||||
assertEquals("2001:db8::/32", list.currentEntries().getFirst().getCidr());
|
||||
|
||||
service.modifyManagedPrefixList("us-east-1", list.getPrefixListId(), null, null, null,
|
||||
List.of(new PrefixListEntry("2001:db8:1::/48", null)), List.of());
|
||||
assertEquals(2, service.getManagedPrefixListEntries("us-east-1", list.getPrefixListId(), null).size());
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.modifyManagedPrefixList(
|
||||
"us-east-1", list.getPrefixListId(), null, null, null,
|
||||
List.of(new PrefixListEntry("10.0.0.0/8", null)), List.of()));
|
||||
assertEquals("InvalidParameterValue", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void managedPrefixListLookupsRejectAMissingId() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
for (String missing : new String[] {null, " "}) {
|
||||
assertEquals("MissingParameter", assertThrows(AwsException.class, () ->
|
||||
service.getManagedPrefixListEntries("us-east-1", missing, null)).getErrorCode());
|
||||
assertEquals("MissingParameter", assertThrows(AwsException.class, () ->
|
||||
service.deleteManagedPrefixList("us-east-1", missing)).getErrorCode());
|
||||
assertEquals("MissingParameter", assertThrows(AwsException.class, () ->
|
||||
service.modifyManagedPrefixList("us-east-1", missing, null, null, null,
|
||||
List.of(), List.of())).getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeManagedPrefixListsFiltersByName() {
|
||||
Ec2Service service = prefixListService();
|
||||
service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5, List.of(), List.of());
|
||||
|
||||
List<ManagedPrefixList> found = service.describeManagedPrefixLists("us-east-1", List.of(),
|
||||
Map.of("prefix-list-name", List.of("corp")));
|
||||
|
||||
assertEquals(1, found.size());
|
||||
assertEquals("corp", found.getFirst().getPrefixListName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeManagedPrefixListsRejectsUnknownId() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () ->
|
||||
service.describeManagedPrefixLists("us-east-1", List.of("pl-missing"), Map.of()));
|
||||
assertEquals("InvalidPrefixListID.NotFound", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyBumpsVersionAndKeepsEarlierVersionsRetrievable() {
|
||||
Ec2Service service = prefixListService();
|
||||
ManagedPrefixList created = service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5,
|
||||
List.of(new PrefixListEntry("10.0.0.0/8", null)), List.of());
|
||||
|
||||
ManagedPrefixList modified = service.modifyManagedPrefixList("us-east-1", created.getPrefixListId(),
|
||||
null, null, null, List.of(new PrefixListEntry("192.168.0.0/16", "lab")), List.of());
|
||||
|
||||
assertEquals(2, modified.getVersion());
|
||||
assertEquals("modify-complete", modified.getState());
|
||||
assertEquals(2, service.getManagedPrefixListEntries("us-east-1", created.getPrefixListId(), null).size());
|
||||
assertEquals(1, service.getManagedPrefixListEntries("us-east-1", created.getPrefixListId(), 1L).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyAppliesRemovalsBeforeAdditionsSoADescriptionCanBeReplaced() {
|
||||
Ec2Service service = prefixListService();
|
||||
ManagedPrefixList created = service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5,
|
||||
List.of(new PrefixListEntry("10.0.0.0/8", "old")), List.of());
|
||||
|
||||
service.modifyManagedPrefixList("us-east-1", created.getPrefixListId(), null, null, null,
|
||||
List.of(new PrefixListEntry("10.0.0.0/8", "new")), List.of("10.0.0.0/8"));
|
||||
|
||||
List<PrefixListEntry> entries =
|
||||
service.getManagedPrefixListEntries("us-east-1", created.getPrefixListId(), null);
|
||||
assertEquals(1, entries.size());
|
||||
assertEquals("new", entries.getFirst().getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
void renamingDoesNotCreateANewVersion() {
|
||||
Ec2Service service = prefixListService();
|
||||
ManagedPrefixList created = service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5,
|
||||
List.of(new PrefixListEntry("10.0.0.0/8", null)), List.of());
|
||||
|
||||
ManagedPrefixList renamed = service.modifyManagedPrefixList("us-east-1", created.getPrefixListId(),
|
||||
null, "corp-renamed", null, List.of(), List.of());
|
||||
|
||||
assertEquals("corp-renamed", renamed.getPrefixListName());
|
||||
assertEquals(1, renamed.getVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyWithStaleCurrentVersionIsRejected() {
|
||||
Ec2Service service = prefixListService();
|
||||
ManagedPrefixList created = service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5,
|
||||
List.of(new PrefixListEntry("10.0.0.0/8", null)), List.of());
|
||||
service.modifyManagedPrefixList("us-east-1", created.getPrefixListId(), null, null, null,
|
||||
List.of(new PrefixListEntry("192.168.0.0/16", null)), List.of());
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () ->
|
||||
service.modifyManagedPrefixList("us-east-1", created.getPrefixListId(), 1L, null, null,
|
||||
List.of(new PrefixListEntry("172.16.0.0/12", null)), List.of()));
|
||||
assertEquals("PrefixListVersionMismatch", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void awsManagedListsCannotBeModifiedOrDeleted() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
AwsException modifyError = assertThrows(AwsException.class, () ->
|
||||
service.modifyManagedPrefixList("us-east-1", "pl-63a5400a", null, "hijacked", null,
|
||||
List.of(), List.of()));
|
||||
assertEquals("UnsupportedOperation", modifyError.getErrorCode());
|
||||
|
||||
AwsException deleteError = assertThrows(AwsException.class, () ->
|
||||
service.deleteManagedPrefixList("us-east-1", "pl-63a5400a"));
|
||||
assertEquals("UnsupportedOperation", deleteError.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRemovesTheListFromDescribe() {
|
||||
Ec2Service service = prefixListService();
|
||||
ManagedPrefixList created = service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5,
|
||||
List.of(), List.of());
|
||||
|
||||
ManagedPrefixList deleted = service.deleteManagedPrefixList("us-east-1", created.getPrefixListId());
|
||||
|
||||
assertEquals("delete-complete", deleted.getState());
|
||||
assertThrows(AwsException.class, () ->
|
||||
service.describeManagedPrefixLists("us-east-1", List.of(created.getPrefixListId()), Map.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyDescribePrefixListsProjectsTheSameAwsManagedData() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
var legacy = service.describePrefixLists("us-east-1", List.of(),
|
||||
Map.of("prefix-list-name", List.of("com.amazonaws.us-east-1.s3")));
|
||||
|
||||
assertEquals(1, legacy.size());
|
||||
assertEquals("pl-63a5400a", legacy.getFirst().getPrefixListId());
|
||||
assertEquals(List.of("52.216.0.0/15", "54.231.0.0/16"), legacy.getFirst().getCidrs());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyRejectsANonPositiveMaxEntries() {
|
||||
Ec2Service service = prefixListService();
|
||||
ManagedPrefixList created = service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5,
|
||||
List.of(), List.of());
|
||||
|
||||
// The list is empty, so a size check alone would let a zero capacity through.
|
||||
AwsException error = assertThrows(AwsException.class, () ->
|
||||
service.modifyManagedPrefixList("us-east-1", created.getPrefixListId(), null, null, 0,
|
||||
List.of(), List.of()));
|
||||
assertEquals("InvalidParameterValue", error.getErrorCode());
|
||||
assertEquals(5, service.describeManagedPrefixLists("us-east-1",
|
||||
List.of(created.getPrefixListId()), Map.of()).getFirst().getMaxEntries());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTagsOnAPrefixListIsVisibleToDescribeAndTagFilters() {
|
||||
Ec2Service service = prefixListService();
|
||||
ManagedPrefixList created = service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5,
|
||||
List.of(), List.of());
|
||||
|
||||
service.createTags("us-east-1", List.of(created.getPrefixListId()), List.of(new Tag("env", "prod")));
|
||||
|
||||
ManagedPrefixList described = service.describeManagedPrefixLists("us-east-1",
|
||||
List.of(created.getPrefixListId()), Map.of()).getFirst();
|
||||
assertEquals(1, described.getTags().size());
|
||||
assertEquals("prod", described.getTags().getFirst().getValue());
|
||||
|
||||
assertEquals(1, service.describeManagedPrefixLists("us-east-1", List.of(),
|
||||
Map.of("tag:env", List.of("prod"))).size());
|
||||
|
||||
assertEquals("prefix-list", service.describeTags("us-east-1",
|
||||
Map.of("resource-id", List.of(created.getPrefixListId()))).getFirst().get("resourceType"));
|
||||
assertEquals(1, service.describeTags("us-east-1",
|
||||
Map.of("resource-type", List.of("prefix-list"))).size());
|
||||
|
||||
service.deleteTags("us-east-1", List.of(created.getPrefixListId()), List.of(new Tag("env", null)));
|
||||
assertTrue(service.describeManagedPrefixLists("us-east-1", List.of(created.getPrefixListId()), Map.of())
|
||||
.getFirst().getTags().isEmpty());
|
||||
}
|
||||
|
||||
private static EmulatorConfig mockConfig(boolean ec2Mock) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
|
||||
Reference in new issue
Block a user