mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
add support for Storage::Rackspace::File#access_control_allow_origin and #origin
Support Access-Control-Allow-Origin and Origin headers, borrowed testing ideas from pull request #1251
This commit is contained in:
parent
7af36b05dd
commit
d2dc10d125
2 changed files with 79 additions and 0 deletions
|
@ -12,6 +12,8 @@ module Fog
|
|||
attribute :content_type, :aliases => ['content_type', 'Content-Type']
|
||||
attribute :etag, :aliases => ['hash', 'Etag']
|
||||
attribute :last_modified, :aliases => ['last_modified', 'Last-Modified'], :type => :time
|
||||
attribute :access_control_allow_origin, :aliases => ['Access-Control-Allow-Origin']
|
||||
attribute :origin, :aliases => ['Origin']
|
||||
|
||||
def body
|
||||
attributes[:body] ||= if last_modified
|
||||
|
@ -32,6 +34,8 @@ module Fog
|
|||
def copy(target_directory_key, target_file_key, options={})
|
||||
requires :directory, :key
|
||||
options['Content-Type'] ||= content_type if content_type
|
||||
options['Access-Control-Allow-Origin'] ||= access_control_allow_origin if access_control_allow_origin
|
||||
options['Origin'] ||= origin if origin
|
||||
connection.copy_object(directory.key, key, target_directory_key, target_file_key, options)
|
||||
target_directory = connection.directories.new(:key => target_directory_key)
|
||||
target_directory.files.get(target_file_key)
|
||||
|
@ -64,6 +68,8 @@ module Fog
|
|||
def save(options = {})
|
||||
requires :body, :directory, :key
|
||||
options['Content-Type'] = content_type if content_type
|
||||
options['Access-Control-Allow-Origin'] ||= access_control_allow_origin if access_control_allow_origin
|
||||
options['Origin'] ||= origin if origin
|
||||
data = connection.put_object(directory.key, key, body, options)
|
||||
merge_attributes(data.headers.reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
|
||||
self.content_length = Fog::Storage.get_body_size(body)
|
||||
|
|
73
tests/rackspace/models/storage/file_tests.rb
Normal file
73
tests/rackspace/models/storage/file_tests.rb
Normal file
|
@ -0,0 +1,73 @@
|
|||
Shindo.tests('Fog::Rackspace::Storage | file', ['rackspace']) do
|
||||
|
||||
file_attributes = {
|
||||
:key => 'fog_file_tests',
|
||||
:body => lorem_file
|
||||
}
|
||||
|
||||
directory_attributes = {
|
||||
# Add a random suffix to prevent collision
|
||||
:key => "fogfilestests-#{rand(65536)}"
|
||||
}
|
||||
|
||||
@directory = Fog::Storage[:rackspace].
|
||||
directories.
|
||||
create(directory_attributes)
|
||||
|
||||
model_tests(@directory.files, file_attributes, Fog.mocking?) do
|
||||
|
||||
tests("#access_control_allow_origin") do
|
||||
|
||||
tests("#access_control_allow_origin should default to nil").returns(nil) do
|
||||
@instance.access_control_allow_origin
|
||||
end
|
||||
|
||||
@instance.access_control_allow_origin = 'http://example.com'
|
||||
tests("#access_control_allow_origin should return access control attribute").returns('http://example.com') do
|
||||
@instance.access_control_allow_origin
|
||||
end
|
||||
|
||||
@instance.access_control_allow_origin = 'foo'
|
||||
tests("#access_control_allow_origin= should update access_control_allow_origin").returns('bar') do
|
||||
@instance.access_control_allow_origin = 'bar'
|
||||
@instance.access_control_allow_origin
|
||||
end
|
||||
|
||||
tests("#access_control_allow_origin= should not blow up on nil") do
|
||||
@instance.access_control_allow_origin = nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
model_tests(@directory.files, file_attributes, Fog.mocking?) do
|
||||
|
||||
tests("#origin") do
|
||||
|
||||
tests("#origin should default to nil").returns(nil) do
|
||||
@instance.origin
|
||||
end
|
||||
|
||||
@instance.origin = 'http://example.com'
|
||||
tests("#origin should return access control attributes").returns('http://example.com') do
|
||||
@instance.origin
|
||||
end
|
||||
@instance.attributes.delete('Origin')
|
||||
|
||||
@instance.attributes['Origin'] = 'foo'
|
||||
tests("#origin= should update origin").returns('bar') do
|
||||
@instance.origin = 'bar'
|
||||
@instance.origin
|
||||
end
|
||||
|
||||
tests("#origin= should not blow up on nil") do
|
||||
@instance.origin = nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@directory.destroy
|
||||
end
|
Loading…
Reference in a new issue