mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[ec2] fix gaps in mocking revealed by new shindo tests
This commit is contained in:
parent
063b0b42d1
commit
4577e2d093
6 changed files with 92 additions and 55 deletions
|
@ -96,40 +96,42 @@ module Fog
|
|||
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
hash[key] = {
|
||||
:deleted_at => {},
|
||||
:addresses => {},
|
||||
:instances => {},
|
||||
:key_pairs => {},
|
||||
:limits => { :addresses => 5 },
|
||||
:addresses => {},
|
||||
:instances => {},
|
||||
:key_pairs => {},
|
||||
:limits => { :addresses => 5 },
|
||||
:owner_id => owner_id,
|
||||
:security_groups => {
|
||||
'default' => {
|
||||
'groupDescription' => 'default group',
|
||||
'groupName' => 'default',
|
||||
'ipPermissions' => [
|
||||
{
|
||||
'groups' => [{'groupName' => 'default', 'userId' => @owner_id}],
|
||||
'groups' => [{'groupName' => 'default', 'userId' => owner_id}],
|
||||
'fromPort' => -1,
|
||||
'toPort' => -1,
|
||||
'ipProtocol' => 'icmp',
|
||||
'ipRanges' => []
|
||||
},
|
||||
{
|
||||
'groups' => [{'groupName' => 'default', 'userId' => @owner_id}],
|
||||
'groups' => [{'groupName' => 'default', 'userId' => owner_id}],
|
||||
'fromPort' => 0,
|
||||
'toPort' => 65535,
|
||||
'ipProtocol' => 'tcp',
|
||||
'ipRanges' => []
|
||||
},
|
||||
{
|
||||
'groups' => [{'groupName' => 'default', 'userId' => @owner_id}],
|
||||
'groups' => [{'groupName' => 'default', 'userId' => owner_id}],
|
||||
'fromPort' => 0,
|
||||
'toPort' => 65535,
|
||||
'ipProtocol' => 'udp',
|
||||
'ipRanges' => []
|
||||
}
|
||||
],
|
||||
'ownerId' => @owner_id
|
||||
'ownerId' => owner_id
|
||||
}
|
||||
},
|
||||
:snapshots => {},
|
||||
|
@ -146,8 +148,8 @@ module Fog
|
|||
|
||||
def initialize(options={})
|
||||
@aws_access_key_id = options[:aws_access_key_id]
|
||||
@owner_id = Fog::AWS::Mock.owner_id
|
||||
@data = self.class.data[@aws_access_key_id]
|
||||
@owner_id = @data[:owner_id]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -37,32 +37,47 @@ module Fog
|
|||
def authorize_security_group_ingress(options = {})
|
||||
response = Excon::Response.new
|
||||
group = @data[:security_groups][options['GroupName']]
|
||||
group['ipPermissions'] ||= []
|
||||
|
||||
if options['GroupName'] && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId']
|
||||
['icmp', 'tcp', 'udp'].each do |protocol|
|
||||
if group
|
||||
group['ipPermissions'] ||= []
|
||||
if options['GroupName'] && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId']
|
||||
['tcp', 'udp'].each do |protocol|
|
||||
group['ipPermissions'] << {
|
||||
'groups' => [{'groupName' => options['GroupName'], 'userId' => @owner_id}],
|
||||
'fromPort' => 1,
|
||||
'ipRanges' => [],
|
||||
'ipProtocol' => protocol,
|
||||
'toPort' => 65535
|
||||
}
|
||||
end
|
||||
group['ipPermissions'] << {
|
||||
'groups' => [{'groupName' => options['GroupName'], 'userId' => @owner_id}],
|
||||
'fromPort' => 1,
|
||||
'fromPort' => -1,
|
||||
'ipRanges' => [],
|
||||
'ipProtocol' => protocol,
|
||||
'toPort' => 65535
|
||||
'ipProtocol' => 'icmp',
|
||||
'toPort' => -1
|
||||
}
|
||||
else
|
||||
group['ipPermissions'] << {
|
||||
'groups' => [],
|
||||
'fromPort' => options['FromPort'],
|
||||
'ipRanges' => [],
|
||||
'ipProtocol' => options['IpProtocol'],
|
||||
'toPort' => options['ToPort']
|
||||
}
|
||||
if options['CidrIp']
|
||||
group['ipPermissions'].last['ipRanges'] << { 'cidrIp' => options['CidrIp'] }
|
||||
end
|
||||
end
|
||||
else
|
||||
group['ipPermissions'] << {
|
||||
'groups' => [],
|
||||
'fromPort' => options['FromPort'],
|
||||
'ipRanges' => [{ 'cidrIp' => options['CidrIp'] }],
|
||||
'ipProtocol' => options['IpProtocol'],
|
||||
'toPort' => options['ToPort']
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'return' => true
|
||||
}
|
||||
else
|
||||
response.status = 400
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'return' => true
|
||||
}
|
||||
response
|
||||
end
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ module Fog
|
|||
response = Excon::Response.new
|
||||
unless @data[:security_groups][name]
|
||||
data = {
|
||||
'groupDescription' => description,
|
||||
'groupName' => name,
|
||||
'groupDescription' => CGI.escape(description).gsub('%20', '+'),
|
||||
'groupName' => CGI.escape(name).gsub('%20', '+'),
|
||||
'ipPermissions' => [],
|
||||
'ownerId' => @owner_id
|
||||
}
|
||||
|
|
|
@ -44,11 +44,16 @@ module Fog
|
|||
availability_zone_info = zones.values
|
||||
end
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'availabilityZoneInfo' => availability_zone_info
|
||||
}
|
||||
if zone_name.length == 0 || zone_name.length == availability_zone_info.length
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'availabilityZoneInfo' => availability_zone_info
|
||||
}
|
||||
else
|
||||
response.status = 400
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
|
|
|
@ -41,11 +41,16 @@ module Fog
|
|||
region_info = regions.values
|
||||
end
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'regionInfo' => region_info
|
||||
}
|
||||
if region_name.length == 0 || region_name.length == region_info.length
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'regionInfo' => region_info
|
||||
}
|
||||
else
|
||||
response.status = 400
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
|
|
|
@ -35,28 +35,38 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def revoke_security_group_ingress(options = {})
|
||||
if options['GroupName'] && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId']
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
else
|
||||
response = Excon::Response.new
|
||||
group = @data[:security_groups][options['GroupName']]
|
||||
|
||||
ingress = group['ipPermissions'].select {|permission|
|
||||
permission['fromPort'] == options['FromPort'] &&
|
||||
permission['ipProtocol'] == options['IpProtocol'] &&
|
||||
permission['toPort'] == options['ToPort'] &&
|
||||
permission['ipRanges'].first['cidrIp'] == options['CidrIp']
|
||||
}.first
|
||||
|
||||
group['ipPermissions'].delete(ingress)
|
||||
|
||||
response = Excon::Response.new
|
||||
group = @data[:security_groups][options['GroupName']]
|
||||
if group
|
||||
if options['GroupName'] && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId']
|
||||
group['ipPermissions'].delete_if {|permission|
|
||||
permission['groups'].first['groupName'] == options['GroupName']
|
||||
}
|
||||
else
|
||||
ingress = group['ipPermissions'].select {|permission|
|
||||
permission['fromPort'] == options['FromPort'] &&
|
||||
permission['ipProtocol'] == options['IpProtocol'] &&
|
||||
permission['toPort'] == options['ToPort'] &&
|
||||
(
|
||||
permission['ipRanges'].empty? ||
|
||||
(
|
||||
permission['ipRanges'].first &&
|
||||
permission['ipRanges'].first['cidrIp'] == options['CidrIp']
|
||||
)
|
||||
)
|
||||
}.first
|
||||
group['ipPermissions'].delete(ingress)
|
||||
end
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'return' => true
|
||||
}
|
||||
response
|
||||
else
|
||||
response.status = 400
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue