mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
shindo tests for IAM models: users, policies and access_keys. Mock implementation for get_user_policy
This commit is contained in:
parent
d258e36c98
commit
5e55a151ee
4 changed files with 129 additions and 10 deletions
|
@ -31,6 +31,22 @@ module Fog
|
|||
end
|
||||
|
||||
end
|
||||
class Mock
|
||||
def get_user_policy(policy_name, user_name)
|
||||
raise Fog::AWS::IAM::NotFound.new("The user with name #{user} cannot be found.") unless self.data[:users].key?(user_name)
|
||||
raise Fog::AWS::IAM::NotFound.new("The policy with name #{policy_name} cannot be found.") unless self.data[:users][user_name][:policies].key?(policy_name)
|
||||
Excon::Response.new.tap do |response|
|
||||
response.body = {
|
||||
'PolicyName' => policy_name,
|
||||
'UserName' => user_name,
|
||||
'PolicyDocument' => data[:users][user_name][:policies][policy_name],
|
||||
'IsTruncated' => false,
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
response.status = 200
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
52
tests/aws/models/iam/access_keys_tests.rb
Normal file
52
tests/aws/models/iam/access_keys_tests.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
Shindo.tests("Fog::Compute[:iam] | access_keys", ['aws','iam']) do
|
||||
|
||||
Fog.mock!
|
||||
iam = Fog::AWS[:iam]
|
||||
|
||||
@username = 'fake_user'
|
||||
@users = iam.users.create(:id => @username)
|
||||
|
||||
|
||||
tests('#all', 'there are no access keys for a new user').succeeds do
|
||||
@users.access_keys.empty?
|
||||
end
|
||||
|
||||
|
||||
tests('#create','an access key').succeeds do
|
||||
access_key = @users.access_keys.create
|
||||
access_key.id =~ /[A-Z0-9]{20}/
|
||||
access_key.secret_access_key =~ /[\S]{40}/
|
||||
access_key.status == "Active"
|
||||
access_key.username == @username
|
||||
@access_key_id = access_key.id
|
||||
end
|
||||
|
||||
@users.access_keys.create
|
||||
|
||||
tests('#all','there are two access keys').succeeds do
|
||||
@users.access_keys.size == 2
|
||||
end
|
||||
|
||||
tests('#get') do
|
||||
tests('a valid access key id').succeeds do
|
||||
access_key = @users.access_keys.get(@access_key_id)
|
||||
access_key.id == @access_key_id
|
||||
access_key.secret_access_key == nil
|
||||
access_key.status == "Active"
|
||||
access_key.username == @username
|
||||
end
|
||||
|
||||
tests('an invalid access key').succeeds do
|
||||
@users.access_keys.get('non-existing') == nil
|
||||
end
|
||||
end
|
||||
|
||||
tests('#destroy', decrease by one the number of access keys).succeeds do
|
||||
size = @users.access_keys.size
|
||||
@users.access_keys.get(@access_key_id).destroy
|
||||
@users.access_keys.size == ( size - 1 )
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
48
tests/aws/models/iam/policies_tests.rb
Normal file
48
tests/aws/models/iam/policies_tests.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
Shindo.tests("Fog::Compute[:iam] | policies", ['aws','iam']) do
|
||||
|
||||
Fog.mock!
|
||||
iam = Fog::AWS[:iam]
|
||||
|
||||
@username = 'fake_user'
|
||||
@users = iam.users.create(:id => @username)
|
||||
@policy_document = {"Statement"=>[{"Action"=>["sqs:*"], "Effect"=>"Allow", "Resource"=>"*"}]}
|
||||
@policy_name = 'fake-sqs-policy'
|
||||
|
||||
tests('#all', 'there is no policies').succeeds do
|
||||
@users.policies.empty?
|
||||
end
|
||||
|
||||
|
||||
tests('#create','a policy').succeeds do
|
||||
policy = @users.policies.create(id: @policy_name, document: @policy_document)
|
||||
policy.id == @policy_name
|
||||
policy.username == @username
|
||||
#policy.document == @policy_document # FIXME, the format isn't right
|
||||
end
|
||||
|
||||
@users.policies.create(id: 'another-policy', document: {})
|
||||
|
||||
tests('#all','there are two policies').succeeds do
|
||||
@users.policies.size == 2
|
||||
end
|
||||
|
||||
tests('#get') do
|
||||
tests('a valid policy').succeeds do
|
||||
policy = @users.policies.get(@policy_name)
|
||||
policy.id == @policy_name
|
||||
policy.username == @username
|
||||
#policy.document == @policy_document # FIXME, the format isn't right
|
||||
end
|
||||
|
||||
tests('an invalid policy').succeeds do
|
||||
@users.policies.get('non-existing') == nil
|
||||
end
|
||||
end
|
||||
|
||||
tests('#destroy').succeeds do
|
||||
@users.policies.get(@policy_name).destroy
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
Shindo.tests("Fog::Compute[:iam] | user", ['aws','iam']) do
|
||||
Shindo.tests("Fog::Compute[:iam] | users", ['aws','iam']) do
|
||||
|
||||
Fog.mock!
|
||||
@iam = Fog::AWS[:iam]
|
||||
|
@ -9,13 +9,12 @@ Shindo.tests("Fog::Compute[:iam] | user", ['aws','iam']) do
|
|||
@user_one = @iam.users.create(:id => @user_one_name)
|
||||
@user_one.id == @user_one_name
|
||||
end
|
||||
#@user_two = @iam.users.create(:id => 'fake_user_two')
|
||||
|
||||
tests('#users','there is only one user').succeeds do
|
||||
tests('#all','there is only one user').succeeds do
|
||||
@iam.users.size == 1
|
||||
end
|
||||
|
||||
tests('#users','the only user should match').succeeds do
|
||||
tests('#all','the only user should match').succeeds do
|
||||
@iam.users.first.id == @user_one_name
|
||||
end
|
||||
|
||||
|
@ -24,7 +23,7 @@ Shindo.tests("Fog::Compute[:iam] | user", ['aws','iam']) do
|
|||
@user_two.id == @user_two_name
|
||||
end
|
||||
|
||||
tests('#users','there are two users').succeeds do
|
||||
tests('#all','there are two users').succeeds do
|
||||
@iam.users.size == 2
|
||||
end
|
||||
|
||||
|
@ -32,20 +31,24 @@ Shindo.tests("Fog::Compute[:iam] | user", ['aws','iam']) do
|
|||
@iam.users.get(@user_one_name).id == @user_one_name
|
||||
end
|
||||
|
||||
tests('#get','nil if the user doesnt exists').succeeds do
|
||||
tests('#get',"returns nil if the user doesn't exists").succeeds do
|
||||
@iam.users.get('non-exists') == nil
|
||||
end
|
||||
|
||||
tests('#policies').succeeds do
|
||||
|
||||
tests('#policies','it has no policies').succeeds do
|
||||
@iam.users.get(@user_one_name).policies.empty?
|
||||
end
|
||||
|
||||
tests('#access_keys').succeeds do
|
||||
|
||||
tests('#access_keys','it has no keys').succeeds do
|
||||
@iam.users.get(@user_one_name).access_keys.empty?
|
||||
end
|
||||
|
||||
tests('#destroy','an existing user').succeeds do
|
||||
@iam.users.get(@user_one_name).destroy
|
||||
end
|
||||
|
||||
tests('#destroy','clean up remaining user').succeeds do
|
||||
@iam.users.get(@user_two_name).destroy
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue