Skip to content

Commit

Permalink
[ec2] consolidate security group tests
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed May 22, 2010
1 parent fb7555b commit 881e725
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 179 deletions.
36 changes: 0 additions & 36 deletions spec/aws/requests/ec2/authorize_security_group_ingress_spec.rb

This file was deleted.

34 changes: 0 additions & 34 deletions spec/aws/requests/ec2/create_security_group_spec.rb

This file was deleted.

26 changes: 0 additions & 26 deletions spec/aws/requests/ec2/delete_security_group_spec.rb

This file was deleted.

51 changes: 0 additions & 51 deletions spec/aws/requests/ec2/describe_security_groups_spec.rb

This file was deleted.

32 changes: 0 additions & 32 deletions spec/aws/requests/ec2/revoke_security_group_ingress_spec.rb

This file was deleted.

16 changes: 16 additions & 0 deletions tests/aws/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ module Formats
'return' => ::Fog::Boolean
}

SECURITY_GROUPS = {
'requestId' => String,
'securityGroupInfo' => [{
'groupDescription' => String,
'groupName' => String,
'ipPermissions' => [{
'fromPort' => Integer,
'groups' => [{ 'groupName' => String, 'userId' => String }],
'ipProtocol' => String,
'ipRanges' => [],
'toPort' => Integer,
}],
'ownerId' => String
}]
}

SNAPSHOT = {
'description' => NilClass,
'ownerId' => String,
Expand Down
112 changes: 112 additions & 0 deletions tests/aws/requests/ec2/security_group_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Shindo.tests('AWS::EC2 | security group requests', ['aws']) do

@owner_id = AWS[:ec2].describe_security_groups('default').body['securityGroupInfo'].first['ownerId']

tests('success') do

tests("#create_security_group('fog_security_group', 'tests group')").formats(AWS::EC2::Formats::BASIC) do
AWS[:ec2].create_security_group('fog_security_group', 'tests group').body
end

tests("#authorize_security_group_ingress({'FromPort' => 80, 'GroupName' => 'fog_security_group', 'IpProtocol' => 'tcp', 'toPort' => 80})").formats(AWS::EC2::Formats::BASIC) do
AWS[:ec2].authorize_security_group_ingress({
'FromPort' => 80,
'GroupName' => 'fog_security_group',
'IpProtocol' => 'tcp',
'ToPort' => 80,
}).body
end

tests("#authorize_security_group_ingress({'GroupName' => 'fog_security_group', 'SourceSecurityGroupName' => 'fog_security_group', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").formats(AWS::EC2::Formats::BASIC) do
AWS[:ec2].authorize_security_group_ingress({
'GroupName' => 'fog_security_group',
'SourceSecurityGroupName' => 'fog_security_group',
'SourceSecurityGroupOwnerId' => @owner_id
}).body
end

tests("#describe_security_groups").formats(AWS::EC2::Formats::SECURITY_GROUPS) do
AWS[:ec2].describe_security_groups.body
end

tests("#describe_security_groups('fog_security_group')").formats(AWS::EC2::Formats::SECURITY_GROUPS) do
AWS[:ec2].describe_security_groups('fog_security_group').body
end

tests("#revoke_security_group_ingress({'FromPort' => 80, 'GroupName' => 'fog_security_group', 'IpProtocol' => 'tcp', 'toPort' => 80})").formats(AWS::EC2::Formats::BASIC) do
AWS[:ec2].revoke_security_group_ingress({
'FromPort' => 80,
'GroupName' => 'fog_security_group',
'IpProtocol' => 'tcp',
'ToPort' => 80,
}).body
end

tests("#revoke_security_group_ingress({'GroupName' => 'fog_security_group', 'SourceSecurityGroupName' => 'fog_security_group', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").formats(AWS::EC2::Formats::BASIC) do
AWS[:ec2].revoke_security_group_ingress({
'GroupName' => 'fog_security_group',
'SourceSecurityGroupName' => 'fog_security_group',
'SourceSecurityGroupOwnerId' => @owner_id
}).body
end

tests("#delete_security_group('fog_security_group')").formats(AWS::EC2::Formats::BASIC) do
AWS[:ec2].delete_security_group('fog_security_group').body
end

end
tests('failure') do

@security_group = AWS[:ec2].security_groups.create(:description => 'tests group', :name => 'fog_security_group')

tests("duplicate #create_security_group(#{@security_group.name}, #{@security_group.description})").raises(Excon::Errors::BadRequest) do
AWS[:ec2].create_security_group(@security_group.name, @security_group.description)
end

tests("#authorize_security_group_ingress({'FromPort' => 80, 'GroupName' => 'not_a_group_name', 'IpProtocol' => 'tcp', 'toPort' => 80})").raises(Excon::Errors::BadRequest) do
AWS[:ec2].authorize_security_group_ingress({
'FromPort' => 80,
'GroupName' => 'not_a_group_name',
'IpProtocol' => 'tcp',
'ToPort' => 80,
})
end

tests("#authorize_security_group_ingress({'GroupName' => 'not_a_group_name', 'SourceSecurityGroupName' => 'not_a_group_name', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").raises(Excon::Errors::BadRequest) do
AWS[:ec2].authorize_security_group_ingress({
'GroupName' => 'not_a_group_name',
'SourceSecurityGroupName' => 'not_a_group_name',
'SourceSecurityGroupOwnerId' => @owner_id
})
end

tests("#describe_security_group('not_a_group_name)").raises(Excon::Errors::BadRequest) do
AWS[:ec2].describe_security_groups('not_a_group_name')
end

tests("#revoke_security_group_ingress({'FromPort' => 80, 'GroupName' => 'not_a_group_name', 'IpProtocol' => 'tcp', 'toPort' => 80})").raises(Excon::Errors::BadRequest) do
AWS[:ec2].revoke_security_group_ingress({
'FromPort' => 80,
'GroupName' => 'not_a_group_name',
'IpProtocol' => 'tcp',
'ToPort' => 80,
})
end

tests("#revoke_security_group_ingress({'GroupName' => 'not_a_group_name', 'SourceSecurityGroupName' => 'not_a_group_name', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").raises(Excon::Errors::BadRequest) do
AWS[:ec2].revoke_security_group_ingress({
'GroupName' => 'not_a_group_name',
'SourceSecurityGroupName' => 'not_a_group_name',
'SourceSecurityGroupOwnerId' => @owner_id
})
end

tests("#delete_security_group('not_a_group_name')").raises(Excon::Errors::BadRequest) do
AWS[:ec2].delete_security_group('not_a_group_name')
end

@security_group.destroy

end

end

0 comments on commit 881e725

Please sign in to comment.