1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/aws/requests/elasticache/security_group_tests.rb

112 lines
3.6 KiB
Ruby
Raw Normal View History

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'
tests(
'#create_cache_security_group'
).formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
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'] }
returns(description) { group['Description'] }
2011-09-27 10:52:46 -04:00
returns([], "no authorized security group") { group['EC2SecurityGroups'] }
body
end
tests(
'#describe_cache_security_groups without options'
).formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
body = AWS[:elasticache].describe_cache_security_groups.body
2011-09-27 10:52:46 -04:00
returns(true, "has #{name}") do
body['CacheSecurityGroups'].any? do |group|
group['CacheSecurityGroupName'] == name
end
2011-09-27 10:52:46 -04:00
end
body
end
tests(
'#describe_cache_security_groups with name'
).formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
body = AWS[:elasticache].describe_cache_security_groups(
'CacheSecurityGroupName' => name
).body
2011-09-27 10:52:46 -04:00
returns(1, "size of 1") { body['CacheSecurityGroups'].size }
returns(name, "has #{name}") do
body['CacheSecurityGroups'].first['CacheSecurityGroupName']
end
2011-09-27 10:52:46 -04:00
body
end
tests('authorization') do
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
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']
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
group = AWS[:elasticache].describe_cache_security_groups(
'CacheSecurityGroupName' => name
).body['CacheSecurityGroups'].first
2011-09-27 10:52:46 -04:00
group['EC2SecurityGroups'].all? {|ec2| ec2['Status'] == 'authorized'}
end
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']
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
tests(
'#delete_cache_security_group'
).formats(AWS::Elasticache::Formats::BASIC) do
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