2010-10-12 18:07:36 -07:00
|
|
|
Shindo.tests('AWS::Storage | object requests', ['aws']) do
|
2011-10-31 12:18:53 +00:00
|
|
|
@directory = Fog::Storage[:aws].directories.create(:key => 'fogobjecttests-' + Time.now.to_i.to_s(32))
|
2011-10-31 14:49:18 +00:00
|
|
|
@aws_owner = Fog::Storage[:aws].get_bucket_acl(@directory.key).body['Owner']
|
2010-10-12 18:07:36 -07:00
|
|
|
|
|
|
|
tests('success') do
|
|
|
|
|
|
|
|
tests("#put_object('#{@directory.identity}', 'fog_object', lorem_file)").succeeds do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].put_object(@directory.identity, 'fog_object', lorem_file)
|
2010-10-12 18:07:36 -07:00
|
|
|
end
|
|
|
|
|
2010-10-29 17:17:02 -07:00
|
|
|
tests("#copy_object('#{@directory.identity}', 'fog_object', '#{@directory.identity}', 'fog_other_object')").succeeds do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].copy_object(@directory.identity, 'fog_object', @directory.identity, 'fog_other_object')
|
2010-10-29 17:17:02 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
@directory.files.get('fog_other_object').destroy
|
|
|
|
|
2010-10-13 13:27:36 -07:00
|
|
|
tests("#get_object('#{@directory.identity}', 'fog_object')").returns(lorem_file.read) do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].get_object(@directory.identity, 'fog_object').body
|
2010-10-13 13:27:36 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
tests("#get_object('#{@directory.identity}', 'fog_object', &block)").returns(lorem_file.read) do
|
|
|
|
data = ''
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].get_object(@directory.identity, 'fog_object') do |chunk, remaining_bytes, total_bytes|
|
2010-10-13 13:27:36 -07:00
|
|
|
data << chunk
|
|
|
|
end
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("#head_object('#{@directory.identity}', 'fog_object')").succeeds do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].head_object(@directory.identity, 'fog_object')
|
2010-10-13 13:27:36 -07:00
|
|
|
end
|
2010-10-12 18:07:36 -07:00
|
|
|
|
2011-08-24 21:19:55 -04:00
|
|
|
tests("#put_object_acl('#{@directory.identity}', 'fog_object', 'private')").succeeds do
|
|
|
|
Fog::Storage[:aws].put_object_acl(@directory.identity, 'fog_object', 'private')
|
|
|
|
end
|
|
|
|
|
2011-10-31 14:49:18 +00:00
|
|
|
acl = {
|
|
|
|
'Owner' => @aws_owner,
|
|
|
|
'AccessControlList' => [
|
2011-11-14 10:33:28 +01:00
|
|
|
{
|
2011-10-31 14:49:18 +00:00
|
|
|
'Grantee' => @aws_owner,
|
2011-11-14 10:33:28 +01:00
|
|
|
'Permission' => "FULL_CONTROL"
|
2011-10-31 14:49:18 +00:00
|
|
|
}
|
|
|
|
]}
|
|
|
|
tests("#put_object_acl('#{@directory.identity}', 'fog_object', hash with id)").returns(acl) do
|
|
|
|
Fog::Storage[:aws].put_object_acl(@directory.identity, 'fog_object', acl)
|
2011-10-27 20:19:29 +01:00
|
|
|
Fog::Storage[:aws].get_object_acl(@directory.identity, 'fog_object').body
|
|
|
|
end
|
|
|
|
|
2011-10-31 14:49:18 +00:00
|
|
|
tests("#put_object_acl('#{@directory.identity}', 'fog_object', hash with email)").returns({
|
|
|
|
'Owner' => @aws_owner,
|
2011-10-27 20:19:29 +01:00
|
|
|
'AccessControlList' => [
|
|
|
|
{
|
2011-10-31 14:49:18 +00:00
|
|
|
'Grantee' => { 'ID' => 'f62f0218873cfa5d56ae9429ae75a592fec4fd22a5f24a20b1038a7db9a8f150', 'DisplayName' => 'mtd' },
|
2011-10-27 20:19:29 +01:00
|
|
|
'Permission' => "FULL_CONTROL"
|
|
|
|
}
|
2011-10-31 14:49:18 +00:00
|
|
|
]}) do
|
|
|
|
pending if Fog.mocking?
|
2011-10-27 20:19:29 +01:00
|
|
|
Fog::Storage[:aws].put_object_acl(@directory.identity, 'fog_object', {
|
2011-10-31 14:49:18 +00:00
|
|
|
'Owner' => @aws_owner,
|
2011-10-27 20:19:29 +01:00
|
|
|
'AccessControlList' => [
|
|
|
|
{
|
2011-10-31 14:49:18 +00:00
|
|
|
'Grantee' => { 'EmailAddress' => 'mtd@amazon.com' },
|
2011-10-27 20:19:29 +01:00
|
|
|
'Permission' => "FULL_CONTROL"
|
|
|
|
}
|
|
|
|
]})
|
|
|
|
Fog::Storage[:aws].get_object_acl(@directory.identity, 'fog_object').body
|
2011-08-24 21:19:55 -04:00
|
|
|
end
|
|
|
|
|
2011-10-31 14:49:18 +00:00
|
|
|
acl = {
|
|
|
|
'Owner' => @aws_owner,
|
|
|
|
'AccessControlList' => [
|
|
|
|
{
|
|
|
|
'Grantee' => { 'URI' => 'http://acs.amazonaws.com/groups/global/AllUsers' },
|
|
|
|
'Permission' => "FULL_CONTROL"
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
tests("#put_object_acl('#{@directory.identity}', 'fog_object', hash with uri)").returns(acl) do
|
|
|
|
Fog::Storage[:aws].put_object_acl(@directory.identity, 'fog_object', acl)
|
|
|
|
Fog::Storage[:aws].get_object_acl(@directory.identity, 'fog_object').body
|
|
|
|
end
|
|
|
|
|
2010-10-12 18:07:36 -07:00
|
|
|
tests("#delete_object('#{@directory.identity}', 'fog_object')").succeeds do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].delete_object(@directory.identity, 'fog_object')
|
2010-10-12 18:07:36 -07:00
|
|
|
end
|
2012-04-16 19:03:05 +02:00
|
|
|
|
|
|
|
tests("#get_object_http_url('#{@directory.identity}', 'fog_object', expiration timestamp)").returns(true) do
|
|
|
|
object_url = Fog::Storage[:aws].get_object_http_url(@directory.identity, 'fog_object', (Time.now + 60))
|
|
|
|
(object_url =~ /http:\/\/#{Regexp.quote(@directory.identity)}\.s3\.amazonaws\.com\/fog_object/) != nil
|
|
|
|
end
|
2010-10-12 18:07:36 -07:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('failure') do
|
|
|
|
|
2010-10-13 13:27:36 -07:00
|
|
|
tests("#put_object('fognonbucket', 'fog_non_object', lorem_file)").raises(Excon::Errors::NotFound) do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].put_object('fognonbucket', 'fog_non_object', lorem_file)
|
2010-10-13 13:27:36 -07:00
|
|
|
end
|
|
|
|
|
2010-10-29 17:17:02 -07:00
|
|
|
tests("#copy_object('fognonbucket', 'fog_object', '#{@directory.identity}', 'fog_other_object')").raises(Excon::Errors::NotFound) do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].copy_object('fognonbucket', 'fog_object', @directory.identity, 'fog_other_object')
|
2010-10-29 17:17:02 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
tests("#copy_object('#{@directory.identity}', 'fog_non_object', '#{@directory.identity}', 'fog_other_object')").raises(Excon::Errors::NotFound) do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].copy_object(@directory.identity, 'fog_non_object', @directory.identity, 'fog_other_object')
|
2010-10-29 17:17:02 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
tests("#copy_object('#{@directory.identity}', 'fog_object', 'fognonbucket', 'fog_other_object')").raises(Excon::Errors::NotFound) do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].copy_object(@directory.identity, 'fog_object', 'fognonbucket', 'fog_other_object')
|
2010-10-29 17:17:02 -07:00
|
|
|
end
|
|
|
|
|
2010-10-13 13:27:36 -07:00
|
|
|
tests("#get_object('fognonbucket', 'fog_non_object')").raises(Excon::Errors::NotFound) do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].get_object('fognonbucket', 'fog_non_object')
|
2010-10-13 13:27:36 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
tests("#get_object('#{@directory.identity}', 'fog_non_object')").raises(Excon::Errors::NotFound) do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].get_object(@directory.identity, 'fog_non_object')
|
2010-10-13 13:27:36 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
tests("#head_object('fognonbucket', 'fog_non_object')").raises(Excon::Errors::NotFound) do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].head_object('fognonbucket', 'fog_non_object')
|
2010-10-13 13:27:36 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
tests("#head_object('#{@directory.identity}', 'fog_non_object')").raises(Excon::Errors::NotFound) do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].head_object(@directory.identity, 'fog_non_object')
|
2010-10-12 18:07:36 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
tests("#delete_object('fognonbucket', 'fog_non_object')").raises(Excon::Errors::NotFound) do
|
2011-06-15 14:26:43 -07:00
|
|
|
Fog::Storage[:aws].delete_object('fognonbucket', 'fog_non_object')
|
2010-10-12 18:07:36 -07:00
|
|
|
end
|
|
|
|
|
2011-08-24 21:19:55 -04:00
|
|
|
tests("#put_object_acl('#{@directory.identity}', 'fog_object', 'invalid')").raises(Excon::Errors::BadRequest) do
|
|
|
|
Fog::Storage[:aws].put_object_acl('#{@directory.identity}', 'fog_object', 'invalid')
|
|
|
|
end
|
|
|
|
|
2010-10-12 18:07:36 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
@directory.destroy
|
|
|
|
|
2010-10-13 13:27:36 -07:00
|
|
|
end
|