1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/openstack/models/identity/ec2_credentials_tests.rb
Eric Hodel 97d50bbeae Added OpenStack EC2 credential management models
Altered the paths for EC2 credential requests to remove an extra / in
the request URIs.

Altered Fog::Open::Identity::Real#request to retry only once when given
a 401 error response code.  The EC2 API returns 401 when attempting to
fetch nonexistent EC2 credentials instead of something sensible like
404, leading to an infinite loop.  Also, the "Bad username or password"
check was removed.  My version of OpenStack does not return this message
when a token is expired, but returns the same message as for a missing
EC2 credential.
2012-12-05 14:27:10 -08:00

58 lines
1.4 KiB
Ruby

Shindo.tests("Fog::Identity[:openstack] | ec2_credentials", ['openstack']) do
before do
openstack = Fog::Identity[:openstack]
tenant_id = openstack.list_tenants.body['tenants'].first['id']
@user = openstack.users.find { |user| user.name == 'foobar' }
@user ||= openstack.users.create({
:name => 'foobar',
:email => 'foo@bar.com',
:tenant_id => tenant_id,
:password => 'spoof',
:enabled => true
})
@ec2_credential = openstack.ec2_credentials.create({
:user_id => @user.id,
:tenant_id => tenant_id,
})
end
after do
@user.ec2_credentials.each do |ec2_credential|
ec2_credential.destroy
end
@user.destroy
end
tests('success') do
tests('#find_by_access_key').succeeds do
ec2_credential =
@user.ec2_credentials.find_by_access_key(@ec2_credential.access)
ec2_credential.access == @ec2_credential.access
end
tests('#create').succeeds do
@user.ec2_credentials.create
end
tests('#destroy').succeeds do
@user.ec2_credentials.destroy(@ec2_credential.access)
end
end
tests('fails') do
pending if Fog.mocking?
tests('#find_by_access_key').raises(Fog::Identity::OpenStack::NotFound) do
@user.ec2_credentials.find_by_access_key('fake')
end
tests('#destroy').raises(Fog::Identity::OpenStack::NotFound) do
@user.ec2_credentials.destroy('fake')
end
end
end