From 87dfa2e92247bf02f41ad1c634d9d0c6755096d0 Mon Sep 17 00:00:00 2001 From: Daniel Fangl Date: Mon, 7 Feb 2022 20:07:15 +0100 Subject: [PATCH] correctly filter describe_managed_prefix_lists, add test for the behavior (#4837) --- moto/ec2/models.py | 4 ++-- tests/test_ec2/test_vpcs.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 72eac17ae..da2359b9c 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -5566,8 +5566,8 @@ class ManagedPrefixListBackend(object): result = managed_prefix_lists if filters: - result = filter_resources(managed_prefix_lists, filters, attr_pairs) - result = describe_tag_filter(filters, managed_prefix_lists) + result = filter_resources(result, filters, attr_pairs) + result = describe_tag_filter(filters, result) for item in result.copy(): if not item.delete_counter: diff --git a/tests/test_ec2/test_vpcs.py b/tests/test_ec2/test_vpcs.py index 3802d6b02..9938fc27e 100644 --- a/tests/test_ec2/test_vpcs.py +++ b/tests/test_ec2/test_vpcs.py @@ -1097,3 +1097,16 @@ def test_describe_vpcs_dryrun(): ex.value.response["Error"]["Message"].should.equal( "An error occurred (DryRunOperation) when calling the DescribeVpcs operation: Request would have succeeded, but DryRun flag is set" ) + + +@mock_ec2 +def test_describe_prefix_lists(): + client = boto3.client("ec2", region_name="us-east-1") + result_unfiltered = client.describe_prefix_lists() + assert len(result_unfiltered["PrefixLists"]) > 1 + result_filtered = client.describe_prefix_lists( + Filters=[ + {"Name": "prefix-list-name", "Values": ["com.amazonaws.us-east-1.s3"]}, + ] + ) + assert len(result_filtered["PrefixLists"]) == 1