2011-09-27 11:03:11 -04:00
|
|
|
Shindo.tests('AWS::Elasticache | security group requests', ['aws', 'elasticache']) do
|
2011-09-27 10:52:46 -04:00
|
|
|
|
|
|
|
tests('success') do
|
|
|
|
pending if Fog.mocking?
|
|
|
|
|
|
|
|
name = 'fog-test'
|
|
|
|
description = 'Fog Test Group'
|
|
|
|
|
2011-09-02 12:49:21 -04:00
|
|
|
tests(
|
|
|
|
'#create_cache_security_group'
|
|
|
|
).formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
|
2011-09-27 11:03:11 -04:00
|
|
|
body = AWS[:elasticache].create_cache_security_group(name, description).body
|
2011-09-27 10:52:46 -04:00
|
|
|
group = body['CacheSecurityGroup']
|
|
|
|
returns(name) { group['CacheSecurityGroupName'] }
|
2011-09-02 11:59:50 -04:00
|
|
|
returns(description) { group['Description'] }
|
2011-09-27 10:52:46 -04:00
|
|
|
returns([], "no authorized security group") { group['EC2SecurityGroups'] }
|
|
|
|
body
|
|
|
|
end
|
|
|
|
|
2011-09-02 12:49:21 -04:00
|
|
|
tests(
|
|
|
|
'#describe_cache_security_groups without options'
|
|
|
|
).formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
|
2011-09-27 11:03:11 -04:00
|
|
|
body = AWS[:elasticache].describe_cache_security_groups.body
|
2011-09-27 10:52:46 -04:00
|
|
|
returns(true, "has #{name}") do
|
2011-09-02 12:49:21 -04:00
|
|
|
body['CacheSecurityGroups'].any? do |group|
|
|
|
|
group['CacheSecurityGroupName'] == name
|
|
|
|
end
|
2011-09-27 10:52:46 -04:00
|
|
|
end
|
|
|
|
body
|
|
|
|
end
|
|
|
|
|
2011-09-02 12:49:21 -04:00
|
|
|
tests(
|
|
|
|
'#describe_cache_security_groups with name'
|
|
|
|
).formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
|
2011-09-09 11:21:56 -04:00
|
|
|
body = AWS[:elasticache].describe_cache_security_groups(name).body
|
2011-09-27 10:52:46 -04:00
|
|
|
returns(1, "size of 1") { body['CacheSecurityGroups'].size }
|
2011-09-02 12:49:21 -04:00
|
|
|
returns(name, "has #{name}") do
|
|
|
|
body['CacheSecurityGroups'].first['CacheSecurityGroupName']
|
|
|
|
end
|
2011-09-27 10:52:46 -04:00
|
|
|
body
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('authorization') do
|
2011-09-02 12:49:21 -04:00
|
|
|
ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(
|
|
|
|
:name => 'fog-test-elasticache', :description => 'Fog Test Elasticache'
|
|
|
|
)
|
2011-09-27 10:52:46 -04:00
|
|
|
# Reload to get the owner_id
|
|
|
|
ec2_group.reload
|
|
|
|
|
2011-09-02 12:49:21 -04:00
|
|
|
tests(
|
|
|
|
'#authorize_cache_security_group_ingress'
|
|
|
|
).formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
|
|
|
|
body = AWS[:elasticache].authorize_cache_security_group_ingress(
|
|
|
|
name, ec2_group.name, ec2_group.owner_id
|
|
|
|
).body
|
2011-09-27 10:52:46 -04:00
|
|
|
group = body['CacheSecurityGroup']
|
2011-09-02 12:49:21 -04:00
|
|
|
expected_ec2_groups = [{
|
|
|
|
'Status' => 'authorizing', 'EC2SecurityGroupName' => ec2_group.name,
|
|
|
|
'EC2SecurityGroupOwnerId' => ec2_group.owner_id
|
|
|
|
}]
|
|
|
|
returns(expected_ec2_groups, 'has correct EC2 groups') do
|
|
|
|
group['EC2SecurityGroups']
|
|
|
|
end
|
2011-09-27 10:52:46 -04:00
|
|
|
body
|
|
|
|
end
|
|
|
|
|
|
|
|
# Wait for the state to be active
|
|
|
|
Fog.wait_for do
|
2011-09-09 11:21:56 -04:00
|
|
|
response = AWS[:elasticache].describe_cache_security_groups(name)
|
|
|
|
group = response.body['CacheSecurityGroups'].first
|
2011-09-27 10:52:46 -04:00
|
|
|
group['EC2SecurityGroups'].all? {|ec2| ec2['Status'] == 'authorized'}
|
|
|
|
end
|
|
|
|
|
2011-09-02 12:49:21 -04:00
|
|
|
tests(
|
|
|
|
'#revoke_cache_security_group_ingress'
|
|
|
|
).formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
|
|
|
|
body = AWS[:elasticache].revoke_cache_security_group_ingress(
|
|
|
|
name, ec2_group.name, ec2_group.owner_id
|
|
|
|
).body
|
2011-09-27 10:52:46 -04:00
|
|
|
group = body['CacheSecurityGroup']
|
2011-09-02 12:49:21 -04:00
|
|
|
expected_ec2_groups = [{
|
|
|
|
'Status' => 'revoking', 'EC2SecurityGroupName' => ec2_group.name,
|
|
|
|
'EC2SecurityGroupOwnerId' => ec2_group.owner_id
|
|
|
|
}]
|
|
|
|
returns(expected_ec2_groups, 'has correct EC2 groups') do
|
|
|
|
group['EC2SecurityGroups']
|
|
|
|
end
|
2011-09-27 10:52:46 -04:00
|
|
|
body
|
|
|
|
end
|
|
|
|
|
|
|
|
ec2_group.destroy
|
|
|
|
end
|
|
|
|
|
2011-09-02 12:49:21 -04:00
|
|
|
tests(
|
|
|
|
'#delete_cache_security_group'
|
|
|
|
).formats(AWS::Elasticache::Formats::BASIC) do
|
2011-09-27 11:03:11 -04:00
|
|
|
body = AWS[:elasticache].delete_cache_security_group(name).body
|
2011-09-27 10:52:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('failure') do
|
|
|
|
# TODO:
|
|
|
|
# Create a duplicate security group
|
|
|
|
# List a missing security group
|
|
|
|
# Delete a missing security group
|
|
|
|
end
|
|
|
|
end
|