diff --git a/moto/ec2/responses/security_groups.py b/moto/ec2/responses/security_groups.py index 034a0152f..5d1df1475 100644 --- a/moto/ec2/responses/security_groups.py +++ b/moto/ec2/responses/security_groups.py @@ -194,7 +194,7 @@ class SecurityGroups(EC2BaseResponse): def describe_security_group_rules(self) -> str: group_id = self._get_param("GroupId") - filters = self._get_param("Filter") + filters = self._filters_from_querystring() self.error_on_dryrun() diff --git a/tests/test_ec2/test_security_groups.py b/tests/test_ec2/test_security_groups.py index 208963974..8a00d637d 100644 --- a/tests/test_ec2/test_security_groups.py +++ b/tests/test_ec2/test_security_groups.py @@ -565,45 +565,27 @@ def test_authorize_all_protocols_with_no_port_specification(): @mock_ec2 def test_create_and_describe_security_grp_rule(): - ip_protocol = "tcp" - from_port = 27017 - to_port = 27017 - cidr_ip_range = "1.2.3.4/32" - ec2 = boto3.resource("ec2", "us-east-1") client = boto3.client("ec2", "us-east-1") vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16") + sg_name = str(uuid4()) - sg = ec2.create_security_group( + sg = client.create_security_group( Description="Test SG", GroupName=sg_name, VpcId=vpc.id ) - # Ingress rule - ip_permissions = [ - { - "IpProtocol": ip_protocol, - "FromPort": from_port, - "ToPort": to_port, - "IpRanges": [{"CidrIp": cidr_ip_range}], - } - ] - sgr = sg.authorize_ingress(IpPermissions=ip_permissions) - # Describing the ingress rule - sgr_id = sgr["SecurityGroupRules"][0]["SecurityGroupRuleId"] response = client.describe_security_group_rules( - Filters=[{"Name": "ip-permission-id", "Values": [sgr_id]}] + Filters=[{"Name": "group-id", "Values": [sg["GroupId"]]}] ) - ingress_rule = response["SecurityGroupRules"] - rule_found = False - for rule in ingress_rule: - if rule["SecurityGroupRuleId"] == sgr_id: - assert rule["IpProtocol"] == ip_protocol - assert rule["FromPort"] == from_port - assert rule["ToPort"] == to_port - assert rule["CidrIpv4"] == cidr_ip_range - rule_found = True - break - assert rule_found, True + rules = response["SecurityGroupRules"] + + # Only the default rule is present + assert len(rules) == 1 + + # Test default egress rule content + assert rules[0]["IsEgress"] is True + assert rules[0]["IpProtocol"] == "-1" + assert rules[0]["CidrIpv4"] == "0.0.0.0/0" @mock_ec2