Extend security group testing for VPC.
This commit is contained in:
parent
ece46ecea8
commit
8182b3baa8
@ -42,14 +42,15 @@ def test_create_and_describe_vpc_security_group():
|
||||
all_groups.should.have.length_of(1)
|
||||
all_groups[0].name.should.equal('test security group')
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_create_two_security_groups_with_same_name_in_different_vpc():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
vpc_id = 'vpc-5300000c'
|
||||
vpc_id2 = 'vpc-5300000d'
|
||||
|
||||
sg1 = conn.create_security_group('test security group', 'this is a test security group', vpc_id)
|
||||
sg2 = conn.create_security_group('test security group', 'this is a test security group', vpc_id2)
|
||||
conn.create_security_group('test security group', 'this is a test security group', vpc_id)
|
||||
conn.create_security_group('test security group', 'this is a test security group', vpc_id2)
|
||||
|
||||
all_groups = conn.get_all_security_groups()
|
||||
|
||||
@ -77,6 +78,7 @@ def test_deleting_security_groups():
|
||||
conn.delete_security_group(group_id=security_group1.id)
|
||||
conn.get_all_security_groups().should.have.length_of(0)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_delete_security_group_in_vpc():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
@ -132,18 +134,28 @@ def test_authorize_other_group_and_revoke():
|
||||
security_group = [group for group in conn.get_all_security_groups() if group.name == 'test'][0]
|
||||
security_group.rules.should.have.length_of(0)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_authorize_group_in_vpc():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
vpc_id = "vpc-12345"
|
||||
|
||||
# create 2 groups in a vpc
|
||||
security_group1 = conn.create_security_group('test1', 'test1', vpc_id)
|
||||
security_group2 = conn.create_security_group('test2', 'test2', vpc_id)
|
||||
security_group = conn.create_security_group('test1', 'test1', vpc_id)
|
||||
other_security_group = conn.create_security_group('test2', 'test2', vpc_id)
|
||||
|
||||
success = security_group1.authorize(ip_protocol="tcp", from_port="22", to_port="2222", src_group=security_group2)
|
||||
success.should.be.true
|
||||
success = security_group1.revoke(ip_protocol="tcp", from_port="22", to_port="2222", src_group=security_group2)
|
||||
success = security_group.authorize(ip_protocol="tcp", from_port="22", to_port="2222", src_group=other_security_group)
|
||||
success.should.be.true
|
||||
|
||||
# Check that the rule is accurate
|
||||
security_group = [group for group in conn.get_all_security_groups() if group.name == 'test1'][0]
|
||||
int(security_group.rules[0].to_port).should.equal(2222)
|
||||
security_group.rules[0].grants[0].group_id.should.equal(other_security_group.id)
|
||||
|
||||
# Now revome the rule
|
||||
success = security_group.revoke(ip_protocol="tcp", from_port="22", to_port="2222", src_group=other_security_group)
|
||||
success.should.be.true
|
||||
|
||||
# And check that it gets revoked
|
||||
security_group = [group for group in conn.get_all_security_groups() if group.name == 'test1'][0]
|
||||
security_group.rules.should.have.length_of(0)
|
||||
|
Loading…
Reference in New Issue
Block a user