mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
* 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>
137 lines
4.5 KiB
Bash
137 lines
4.5 KiB
Bash
#!/usr/bin/env bats
|
|
# EC2 tests
|
|
|
|
setup() {
|
|
load 'test_helper/common-setup'
|
|
PREFIX_LIST_NAME="bats-prefix-list-$(unique_name)"
|
|
PREFIX_LIST_ID=""
|
|
}
|
|
|
|
teardown() {
|
|
if [ -n "$PREFIX_LIST_ID" ]; then
|
|
aws_cmd ec2 delete-managed-prefix-list --prefix-list-id "$PREFIX_LIST_ID" >/dev/null 2>&1 || true
|
|
fi
|
|
}
|
|
|
|
# Creates a prefix list holding 10.0.0.0/8 and sets PREFIX_LIST_ID.
|
|
create_prefix_list() {
|
|
local out
|
|
out=$(aws_cmd ec2 create-managed-prefix-list \
|
|
--prefix-list-name "$PREFIX_LIST_NAME" \
|
|
--address-family IPv4 \
|
|
--max-entries 5 \
|
|
--entries 'Cidr=10.0.0.0/8,Description=corporate')
|
|
PREFIX_LIST_ID=$(json_get "$out" '.PrefixList.PrefixListId')
|
|
}
|
|
|
|
@test "EC2: create managed prefix list" {
|
|
run aws_cmd ec2 create-managed-prefix-list \
|
|
--prefix-list-name "$PREFIX_LIST_NAME" \
|
|
--address-family IPv4 \
|
|
--max-entries 5 \
|
|
--entries 'Cidr=10.0.0.0/8,Description=corporate'
|
|
assert_success
|
|
PREFIX_LIST_ID=$(json_get "$output" '.PrefixList.PrefixListId')
|
|
[ -n "$PREFIX_LIST_ID" ]
|
|
|
|
state=$(json_get "$output" '.PrefixList.State')
|
|
[ "$state" = "create-complete" ]
|
|
version=$(json_get "$output" '.PrefixList.Version')
|
|
[ "$version" = "1" ]
|
|
}
|
|
|
|
@test "EC2: describe managed prefix list by id" {
|
|
create_prefix_list
|
|
|
|
run aws_cmd ec2 describe-managed-prefix-lists --prefix-list-ids "$PREFIX_LIST_ID"
|
|
assert_success
|
|
name=$(json_get "$output" '.PrefixLists[0].PrefixListName')
|
|
[ "$name" = "$PREFIX_LIST_NAME" ]
|
|
}
|
|
|
|
@test "EC2: describe managed prefix lists exposes the AWS-managed S3 list" {
|
|
run aws_cmd ec2 describe-managed-prefix-lists \
|
|
--filters "Name=prefix-list-name,Values=com.amazonaws.${AWS_DEFAULT_REGION}.s3"
|
|
assert_success
|
|
id=$(json_get "$output" '.PrefixLists[0].PrefixListId')
|
|
[ "$id" = "pl-63a5400a" ]
|
|
owner=$(json_get "$output" '.PrefixLists[0].OwnerId')
|
|
[ "$owner" = "AWS" ]
|
|
}
|
|
|
|
@test "EC2: get managed prefix list entries" {
|
|
create_prefix_list
|
|
|
|
run aws_cmd ec2 get-managed-prefix-list-entries --prefix-list-id "$PREFIX_LIST_ID"
|
|
assert_success
|
|
cidr=$(json_get "$output" '.Entries[0].Cidr')
|
|
[ "$cidr" = "10.0.0.0/8" ]
|
|
desc=$(json_get "$output" '.Entries[0].Description')
|
|
[ "$desc" = "corporate" ]
|
|
}
|
|
|
|
@test "EC2: modify managed prefix list bumps version and keeps history" {
|
|
create_prefix_list
|
|
|
|
run aws_cmd ec2 modify-managed-prefix-list \
|
|
--prefix-list-id "$PREFIX_LIST_ID" \
|
|
--add-entries 'Cidr=192.168.0.0/16,Description=lab'
|
|
assert_success
|
|
version=$(json_get "$output" '.PrefixList.Version')
|
|
[ "$version" = "2" ]
|
|
|
|
run aws_cmd ec2 get-managed-prefix-list-entries --prefix-list-id "$PREFIX_LIST_ID"
|
|
assert_success
|
|
count=$(json_get "$output" '.Entries | length')
|
|
[ "$count" = "2" ]
|
|
|
|
run aws_cmd ec2 get-managed-prefix-list-entries --prefix-list-id "$PREFIX_LIST_ID" --target-version 1
|
|
assert_success
|
|
count=$(json_get "$output" '.Entries | length')
|
|
[ "$count" = "1" ]
|
|
}
|
|
|
|
@test "EC2: modify with a stale current version is rejected" {
|
|
create_prefix_list
|
|
aws_cmd ec2 modify-managed-prefix-list --prefix-list-id "$PREFIX_LIST_ID" \
|
|
--add-entries 'Cidr=192.168.0.0/16' >/dev/null
|
|
|
|
run aws_cmd ec2 modify-managed-prefix-list \
|
|
--prefix-list-id "$PREFIX_LIST_ID" \
|
|
--current-version 1 \
|
|
--add-entries 'Cidr=172.16.0.0/12'
|
|
assert_failure
|
|
assert_output --partial "PrefixListVersionMismatch"
|
|
}
|
|
|
|
@test "EC2: AWS-managed prefix list cannot be modified" {
|
|
run aws_cmd ec2 modify-managed-prefix-list \
|
|
--prefix-list-id pl-63a5400a \
|
|
--add-entries 'Cidr=10.1.0.0/16'
|
|
assert_failure
|
|
assert_output --partial "UnsupportedOperation"
|
|
}
|
|
|
|
@test "EC2: delete managed prefix list" {
|
|
create_prefix_list
|
|
local created_id="$PREFIX_LIST_ID"
|
|
|
|
run aws_cmd ec2 delete-managed-prefix-list --prefix-list-id "$created_id"
|
|
assert_success
|
|
state=$(json_get "$output" '.PrefixList.State')
|
|
[ "$state" = "delete-complete" ]
|
|
PREFIX_LIST_ID=""
|
|
|
|
run aws_cmd ec2 describe-managed-prefix-lists --prefix-list-ids "$created_id"
|
|
assert_failure
|
|
assert_output --partial "InvalidPrefixListID.NotFound"
|
|
}
|
|
|
|
@test "EC2: legacy describe-prefix-lists still serves the gateway lists" {
|
|
run aws_cmd ec2 describe-prefix-lists \
|
|
--filters "Name=prefix-list-name,Values=com.amazonaws.${AWS_DEFAULT_REGION}.s3"
|
|
assert_success
|
|
id=$(json_get "$output" '.PrefixLists[0].PrefixListId')
|
|
[ "$id" = "pl-63a5400a" ]
|
|
}
|