1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Additional mocks

This commit is contained in:
Edward Muller 2012-02-06 17:55:44 -08:00
parent 5171df8ede
commit 4c8ca82b6c
14 changed files with 219 additions and 20 deletions

View file

@ -29,6 +29,30 @@ module Fog
end
end
class Mock
def add_user_to_group(group_name, user_name)
if data[:groups].has_key? group_name
if data[:users].has_key? user_name
unless data[:groups][group_name][:members].include?(user_name)
data[:groups][group_name][:members] << user_name
end
Excon::Response.new.tap do |response|
response.status = 200
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
end
else
raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
end
else
raise Fog::AWS::IAM::NotFound.new("The group with name #{group_name} cannot be found.")
end
end
end
end
end
end

View file

@ -34,6 +34,27 @@ module Fog
end
end
class Mock
def create_group(group_name, path = '/')
if data[:groups].has_key? group_name
raise Fog::AWS::IAM::EntityAlreadyExists.new("Group with name #{group_name} already exists.")
else
data[:groups][group_name][:path] = path
Excon::Response.new.tap do |response|
response.body = { 'Group' => {
'GroupId' => data[:groups][group_name][:group_id],
'GroupName' => group_name,
'Path' => path,
'Arn' => data[:groups][group_name][:arn] },
'RequestId' => Fog::AWS::Mock.request_id }
response.status = 200
end
end
end
end
end
end
end

View file

@ -29,6 +29,23 @@ module Fog
end
end
class Mock
def delete_access_key(access_key_id, options = {})
user_name = options['UserName']
if user_name && data[:users].has_key?(user_name) && data[:users][user_name][:access_keys].any? { |akey| akey['AccessKeyId'] == access_key_id }
data[:users][user_name][:access_keys].delete_if { |akey| akey['AccessKeyId'] == access_key_id }
Excon::Response.new.tap do |response|
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
response.status = 200
end
else
raise Fog::AWS::IAM::NotFound.new("The Access Key with id #{access_key_id} cannot be found.")
end
end
end
end
end
end

View file

@ -27,6 +27,25 @@ module Fog
end
end
class Mock
def delete_group(group_name)
if data[:groups].has_key? group_name
if data[:groups][group_name][:members].empty?
data[:groups].delete group_name
Excon::Response.new.tap do |response|
response.status = 200
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
end
else
raise Fog::AWS::IAM::Error.new("DeleteConflict => Cannot delete entity, must delete users in group first.")
end
else
raise Fog::AWS::IAM::NotFound.new("The group with name #{group_name} cannot be found.")
end
end
end
end
end
end

View file

@ -27,6 +27,23 @@ module Fog
end
end
class Mock
def delete_user(user_name)
if data[:users].has_key? user_name
data[:users].delete user_name
Excon::Response.new.tap do |response|
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
response.status = 200
end
else
raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
end
end
end
end
end
end

View file

@ -35,6 +35,27 @@ module Fog
end
end
class Mock
def list_access_keys(options = {})
#FIXME: Doesn't do anything with options, aside from UserName
user = options['UserName']
if data[:users].has_key? user
Excon::Response.new.tap do |response|
response.body = { 'AccessKeys' => data[:users][user][:access_keys].map do |akey|
{'Status' => akey['Status'], 'AccessKeyId' => akey['AccessKeyId']}
end,
'IsTruncated' => false,
'RequestId' => Fog::AWS::Mock.request_id }
response.status = 200
end
else
Fog::AWS::IAM::NotFound.new("The user with name #{user} cannot be found.")
end
end
end
end
end
end

View file

@ -37,6 +37,24 @@ module Fog
end
end
class Mock
def list_groups(options = {} )
#FIXME: Doesn't observe options
Excon::Response.new.tap do |response|
response.status = 200
response.body = { 'Groups' => data[:groups].map do |name, group|
{ 'GroupId' => group[:group_id],
'GroupName' => name,
'Path' => group[:path],
'Arn' => group[:arn] }
end,
'IsTruncated' => false,
'RequestId' => Fog::AWS::Mock.request_id }
end
end
end
end
end
end

View file

@ -38,6 +38,30 @@ module Fog
end
end
class Mock
def list_groups_for_user(user_name, options = {})
#FIXME: Does not consider options
if data[:users].has_key? user_name
Excon::Response.new.tap do |response|
response.status = 200
response.body = { 'GroupsForUser' => data[:groups].select do |name, group|
group[:members].include? user_name
end.map do |name, group|
{ 'GroupId' => group[:group_id],
'GroupName' => name,
'Path' => group[:path],
'Arn' => group[:arn] }
end,
'IsTruncated' => false,
'RequestId' => Fog::AWS::Mock.request_id
}
end
else
raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
end
end
end
end
end
end

View file

@ -34,6 +34,24 @@ module Fog
end
end
class Mock
def list_user_policies(user_name, options = {})
#FIXME: doesn't use options atm
if data[:users].has_key? user_name
Excon::Response.new.tap do |response|
response.body = { 'PolicyNames' => data[:users][user_name][:policies].keys,
'IsTruncated' => false,
'RequestId' => Fog::AWS::Mock.request_id }
response.status = 200
end
else
raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
end
end
end
end
end
end

View file

@ -29,6 +29,25 @@ module Fog
end
end
class Mock
def remove_user_from_group(group_name, user_name)
if data[:groups].has_key? group_name
if data[:users].has_key? user_name
data[:groups][group_name][:members].delete_if { |item| item == user_name }
Excon::Response.new.tap do |response|
response.status = 200
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
end
else
raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
end
else
raise Fog::AWS::IAM::NotFound.new("The group with name #{group_name} cannot be found.")
end
end
end
end
end
end

View file

@ -30,7 +30,6 @@ Shindo.tests('AWS::IAM | access key requests', ['aws']) do
}
tests("#list_access_keys('Username' => 'fog_access_key_tests')").formats(@access_keys_format) do
pending if Fog.mocking?
Fog::AWS[:iam].list_access_keys('UserName' => 'fog_access_key_tests').body
end
@ -40,7 +39,6 @@ Shindo.tests('AWS::IAM | access key requests', ['aws']) do
end
tests("#delete_access_key('#{@access_key_id}', 'UserName' => 'fog_access_key_tests)").formats(AWS::IAM::Formats::BASIC) do
pending if Fog.mocking?
Fog::AWS[:iam].delete_access_key(@access_key_id, 'UserName' => 'fog_access_key_tests').body
end

View file

@ -13,7 +13,6 @@ Shindo.tests('AWS::IAM | group requests', ['aws']) do
}
tests("#create_group('fog_group')").formats(@group_format) do
pending if Fog.mocking?
Fog::AWS[:iam].create_group('fog_group').body
end
@ -29,12 +28,10 @@ Shindo.tests('AWS::IAM | group requests', ['aws']) do
}
tests("#list_groups").formats(@groups_format) do
pending if Fog.mocking?
Fog::AWS[:iam].list_groups.body
end
tests("#delete_group('fog_group')").formats(AWS::IAM::Formats::BASIC) do
pending if Fog.mocking?
Fog::AWS[:iam].delete_group('fog_group').body
end
@ -44,4 +41,4 @@ Shindo.tests('AWS::IAM | group requests', ['aws']) do
test('failing conditions')
end
end
end

View file

@ -16,8 +16,7 @@ Shindo.tests('AWS::IAM | user policy requests', ['aws']) do
'RequestId' => String
}
tests("list_user_policies('fog_user_policy_tests')").formats(@user_policies_format) do
pending if Fog.mocking?
tests("#list_user_policies('fog_user_policy_tests')").formats(@user_policies_format) do
Fog::AWS[:iam].list_user_policies('fog_user_policy_tests').body
end
@ -31,8 +30,6 @@ Shindo.tests('AWS::IAM | user policy requests', ['aws']) do
test('failing conditions')
end
unless Fog.mocking?
Fog::AWS[:iam].delete_user('fog_user_policy_tests')
end
Fog::AWS[:iam].delete_user('fog_user_policy_tests')
end

View file

@ -1,8 +1,6 @@
Shindo.tests('AWS::IAM | user requests', ['aws']) do
unless Fog.mocking?
Fog::AWS[:iam].create_group('fog_user_tests')
end
Fog::AWS[:iam].create_group('fog_user_tests')
tests('success') do
@ -36,28 +34,39 @@ Shindo.tests('AWS::IAM | user requests', ['aws']) do
end
tests("#add_user_to_group('fog_user_tests', 'fog_user')").formats(AWS::IAM::Formats::BASIC) do
pending if Fog.mocking?
Fog::AWS[:iam].add_user_to_group('fog_user_tests', 'fog_user').body
end
@groups_format = {
'GroupsForUser' => [{
'Arn' => String,
'GroupId' => String,
'GroupName' => String,
'Path' => String
}],
'IsTruncated' => Fog::Boolean,
'RequestId' => String
}
tests("#list_groups_for_user('fog_user')").formats(@groups_format) do
Fog::AWS[:iam].list_groups_for_user('fog_user').body
end
tests("#remove_user_from_group('fog_user_tests', 'fog_user')").formats(AWS::IAM::Formats::BASIC) do
pending if Fog.mocking?
Fog::AWS[:iam].remove_user_from_group('fog_user_tests', 'fog_user').body
end
tests("#delete_user('fog_user')").formats(AWS::IAM::Formats::BASIC) do
pending if Fog.mocking?
Fog::AWS[:iam].delete_user('fog_user').body
end
end
tests('failure') do
test('failing conditions')
end
unless Fog.mocking?
Fog::AWS[:iam].delete_group('fog_user_tests')
end
Fog::AWS[:iam].delete_group('fog_user_tests')
end