From de68c94a0afe99b8603d30542ac6ceec2fa8f6ee Mon Sep 17 00:00:00 2001 From: Yann Lambret Date: Tue, 19 Apr 2016 23:50:46 +0200 Subject: [PATCH] Add the default outboud rule for security groups --- moto/ec2/models.py | 1 + tests/test_ec2/test_security_groups.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 4c523bc33..6d35e5282 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -1102,6 +1102,7 @@ class SecurityGroup(TaggedEC2Resource): self.enis = {} self.vpc_id = vpc_id self.owner_id = "123456789012" + self.egress_rules.append(SecurityRule(-1, -1, -1, ['0.0.0.0/0'], [])) @classmethod def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name): diff --git a/tests/test_ec2/test_security_groups.py b/tests/test_ec2/test_security_groups.py index a36713d68..0d4e1f11f 100644 --- a/tests/test_ec2/test_security_groups.py +++ b/tests/test_ec2/test_security_groups.py @@ -157,8 +157,8 @@ def test_authorize_ip_range_and_revoke(): success = conn.authorize_security_group_egress(egress_security_group.id, "tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32") assert success.should.be.true egress_security_group = conn.get_all_security_groups(groupnames='testegress')[0] - int(egress_security_group.rules_egress[0].to_port).should.equal(2222) - egress_security_group.rules_egress[0].grants[0].cidr_ip.should.equal("123.123.123.123/32") + int(egress_security_group.rules_egress[1].to_port).should.equal(2222) + egress_security_group.rules_egress[1].grants[0].cidr_ip.should.equal("123.123.123.123/32") # Wrong Cidr should throw error egress_security_group.revoke.when.called_with(ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.122/32").should.throw(EC2ResponseError) @@ -167,7 +167,7 @@ def test_authorize_ip_range_and_revoke(): conn.revoke_security_group_egress(egress_security_group.id, "tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32") egress_security_group = conn.get_all_security_groups()[0] - egress_security_group.rules_egress.should.have.length_of(0) + egress_security_group.rules_egress.should.have.length_of(1) @mock_ec2