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

check return types and fixes from broken specs

This commit is contained in:
Wesley Beary 2009-06-25 00:32:27 -07:00
parent b7a7f07e6c
commit 0e9740c53a
16 changed files with 107 additions and 63 deletions

View file

@ -23,8 +23,12 @@ module Fog
end end
def request(params) def request(params)
unless params[:path] && params[:path][0] == '/' params[:path] ||= ''
params[:path] = '/' << params[:path].to_s unless params[:path][0] == '/'
params[:path] = '/' + params[:path].to_s
end
if params[:query]
params[:path] << "?#{params[:query]}"
end end
request = "#{params[:method]} #{params[:path]} HTTP/1.1\r\n" request = "#{params[:method]} #{params[:path]} HTTP/1.1\r\n"
params[:headers] ||= {} params[:headers] ||= {}
@ -48,6 +52,7 @@ module Fog
header = data.split(': ') header = data.split(': ')
response.headers[header[0]] = header[1] response.headers[header[0]] = header[1]
end end
unless params[:method] == 'HEAD'
if response.headers['Content-Length'] if response.headers['Content-Length']
response.body << @connection.read(response.headers['Content-Length'].to_i) response.body << @connection.read(response.headers['Content-Length'].to_i)
elsif response.headers['Transfer-Encoding'] == 'chunked' elsif response.headers['Transfer-Encoding'] == 'chunked'
@ -60,6 +65,7 @@ module Fog
end end
end end
end end
end
response response
end end

View file

@ -42,6 +42,7 @@ module Fog
def get_service def get_service
request({ request({
:headers => {}, :headers => {},
:host => @host,
:method => 'GET', :method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetServiceParser.new, :parser => Fog::Parsers::AWS::S3::GetServiceParser.new,
:url => @host :url => @host
@ -56,7 +57,8 @@ module Fog
# :location_constraint sets the location for the bucket # :location_constraint sets the location for the bucket
def put_bucket(bucket_name, options = {}) def put_bucket(bucket_name, options = {})
if options[:location_constraint] if options[:location_constraint]
data = <<-DATA data =
<<-DATA
<CreateBucketConfiguration> <CreateBucketConfiguration>
<LocationConstraint>#{options[:location_constraint]}</LocationConstraint> <LocationConstraint>#{options[:location_constraint]}</LocationConstraint>
</CreateBucketConfiguration> </CreateBucketConfiguration>
@ -79,7 +81,8 @@ module Fog
# bucket_name<~String>:: name of bucket to modify # bucket_name<~String>:: name of bucket to modify
# payer<~String>:: valid values are BucketOwner or Requester # payer<~String>:: valid values are BucketOwner or Requester
def put_request_payment(bucket_name, payer) def put_request_payment(bucket_name, payer)
data = <<-DATA data =
<<-DATA
<RequestPaymentConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <RequestPaymentConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Payer>#{payer}</Payer> <Payer>#{payer}</Payer>
</RequestPaymentConfiguration> </RequestPaymentConfiguration>
@ -89,7 +92,8 @@ module Fog
:headers => {}, :headers => {},
:host => "#{bucket_name}.#{@host}", :host => "#{bucket_name}.#{@host}",
:method => 'PUT', :method => 'PUT',
:parser => Fog::Parsers::AWS::S3::BasicParser.new :parser => Fog::Parsers::AWS::S3::BasicParser.new,
:query => "requestPayment"
}) })
end end
@ -116,7 +120,7 @@ module Fog
:host => "#{bucket_name}.#{@host}", :host => "#{bucket_name}.#{@host}",
:method => 'GET', :method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucketParser.new, :parser => Fog::Parsers::AWS::S3::GetBucketParser.new,
:path => query :query => query
}) })
end end
@ -127,18 +131,18 @@ module Fog
:host => "#{bucket_name}.#{@host}", :host => "#{bucket_name}.#{@host}",
:method => 'GET', :method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetRequestPayment.new, :parser => Fog::Parsers::AWS::S3::GetRequestPayment.new,
:path => '?requestpayment' :query => 'requestpayment'
}) })
end end
# Get location constraint for an S3 bucket # Get location constraint for an S3 bucket
def get_location(bucket_name) def get_bucket_location(bucket_name)
request({ request({
:headers => {}, :headers => {},
:host => "#{bucket_name}.#{@host}", :host => "#{bucket_name}.#{@host}",
:method => 'GET', :method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetRequestPayment.new, :parser => Fog::Parsers::AWS::S3::GetBucketLocation.new,
:path => '?location' :query => 'location'
}) })
end end
@ -195,7 +199,6 @@ module Fog
:headers => {}, :headers => {},
:host => "#{bucket_name}.#{@host}", :host => "#{bucket_name}.#{@host}",
:method => 'HEAD', :method => 'HEAD',
:parser => Fog::Parsers::AWS::S3::BasicParser.new,
:path => object_name :path => object_name
}) })
end end
@ -213,13 +216,6 @@ module Fog
private private
def url(bucket_name = nil, path = nil)
url = "#{@scheme}://"
url << "#{bucket_name}." if bucket_name
url << "#{@host}:#{@port}/#{path}"
url
end
def parse_file(file) def parse_file(file)
metadata = { metadata = {
:body => nil, :body => nil,
@ -239,7 +235,6 @@ module Fog
def sign(params) def sign(params)
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000") params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
params[:path] ||= ''
string_to_sign = string_to_sign =
<<-DATA <<-DATA
@ -250,18 +245,16 @@ module Fog
DATA DATA
amz_headers, canonical_amz_headers = {}, '' amz_headers, canonical_amz_headers = {}, ''
for key, value in amz_headers for key, value in params[:headers]
if key[0..5] == 'x-amz-' if key[0..5] == 'x-amz-'
amz_headers[key] = value amz_headers[key] = value
end end
end end
amz_headers = amz_headers.sort {|x, y| x[0] <=> y[0]} amz_headers = amz_headers.sort {|x, y| x[0] <=> y[0]}
for pair in amz_headers for pair in amz_headers
canonical_amz_headers << "#{pair[0]}: #{pair[1]}\r\n" canonical_amz_headers << "#{pair[0]}:#{pair[1]}\n"
end
unless canonical_amz_headers.empty?
string_to_sign << "#{canonical_amz_headers}\n"
end end
string_to_sign << "#{canonical_amz_headers}"
canonical_resource = "/" canonical_resource = "/"
# [0..-18] is anything prior to .s3.amazonaws.com # [0..-18] is anything prior to .s3.amazonaws.com
@ -270,6 +263,9 @@ DATA
canonical_resource << "#{subdomain}/" canonical_resource << "#{subdomain}/"
end end
canonical_resource << "#{params[:path]}" canonical_resource << "#{params[:path]}"
if params[:query] && !params[:query].empty?
canonical_resource << "?#{params[:query]}"
end
# canonical_resource << "?acl" if params[:path].include?('?acl') # canonical_resource << "?acl" if params[:path].include?('?acl')
# canonical_resource << "?location" if params[:path].include?('?location') # canonical_resource << "?location" if params[:path].include?('?location')
# canonical_resource << "?torrent" if params[:path].include?('?torrent') # canonical_resource << "?torrent" if params[:path].include?('?torrent')
@ -289,7 +285,8 @@ DATA
:headers => params[:headers], :headers => params[:headers],
:host => params[:host], :host => params[:host],
:method => params[:method], :method => params[:method],
:path => params[:path] :path => params[:path],
:query => params[:query]
}) })
if params[:parser] && !response.body.empty? if params[:parser] && !response.body.empty?

View file

@ -104,7 +104,7 @@ module Fog
end end
class GetLocation < Fog::Parsers::AWS::S3::BasicParser class GetBucketLocation < Fog::Parsers::AWS::S3::BasicParser
def end_element(name) def end_element(name)
case name case name

View file

@ -303,7 +303,7 @@ module Fog
response = @connection.request({ response = @connection.request({
:host => @host, :host => @host,
:method => method, :method => method,
:path => method == 'GET' ? "?#{query}" : "" :query => query
}) })
if parser && !response.body.empty? if parser && !response.body.empty?

View file

@ -18,10 +18,12 @@ describe 'S3.copy_object' do
it 'should return proper attributes' do it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES' p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.copy_object( actual = s3.copy_object(
'fogcopyobjectsource', 'fog_copy_object_source', 'fogcopyobjectsource', 'fog_copy_object_source',
'fogcopyobjectdestination', 'fog_copy_object_destination' 'fogcopyobjectdestination', 'fog_copy_object_destination'
) )
actual.status.should == 200
p actual
end end
end end

View file

@ -12,7 +12,9 @@ describe 'S3.delete_bucket' do
it 'should return proper attributes' do it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES' p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.delete_bucket('fogdeletebucket') actual = s3.delete_bucket('fogdeletebucket')
actual.status.should == 204
p actual
end end
it 'should not include fogdeletebucket in get_service after delete_bucket' do it 'should not include fogdeletebucket in get_service after delete_bucket' do

View file

@ -14,7 +14,9 @@ describe 'S3.delete_object' do
it 'should return proper attributes' do it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES' p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.delete_object('fogdeleteobject', 'fog_delete_object') actual = s3.delete_object('fogdeleteobject', 'fog_delete_object')
actual.status.should == 204
p actual
end end
end end

View file

@ -0,0 +1,25 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe 'S3.get_location' do
before(:all) do
s3.put_bucket('foggetlocation')
end
after(:all) do
s3.delete_bucket('foggetlocation')
end
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
actual = s3.get_bucket('foggetbucket')
actual.status.should == 200
p actual
end
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
actual s3.get_location('foggetlocation')
end
end

View file

@ -12,7 +12,9 @@ describe 'S3.get_bucket' do
it 'should return proper attributes' do it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES' p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.get_bucket('fogputbucket') actual = s3.get_bucket('foggetbucket')
actual.status.should == 200
p actual
end end
end end

View file

@ -1,10 +0,0 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe 'S3.get_location' do
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.get_location('foggetlocation')
end
end

View file

@ -15,7 +15,9 @@ describe 'S3.get_object' do
it 'should return proper attributes' do it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES' p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.get_object('foggetobject', 'fog_get_object') actual = s3.get_object('foggetobject', 'fog_get_object')
actual.status.should == 200
p actual
end end
end end

View file

@ -12,7 +12,9 @@ describe 'S3.get_service' do
it 'should return proper_attributes' do it 'should return proper_attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES' p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.get_service actual = s3.get_service
actual.status.should == 200
p actual
end end
it 'should include foggetservice in get_service' do it 'should include foggetservice in get_service' do

View file

@ -15,7 +15,9 @@ describe 'S3.head_object' do
it 'should return proper attributes' do it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES' p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.head_object('fogheadobject', 'fog_head_object') actual = s3.head_object('fogheadobject', 'fog_head_object')
actual.status.should == 200
p actual
end end
end end

View file

@ -12,7 +12,9 @@ describe 'S3.put_bucket' do
it 'should return proper attributes' do it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES' p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.put_bucket('fogputbucket') actual = s3.put_bucket('fogputbucket')
actual.status.should == 200
p actual
end end
it 'should include fogputbucket in get_service buckets after put_bucket' do it 'should include fogputbucket in get_service buckets after put_bucket' do

View file

@ -14,7 +14,9 @@ describe 'S3.put_object' do
it 'should return proper attributes' do it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES' p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
file = File.open(File.dirname(__FILE__) + '/../../lorem.txt', 'r') file = File.open(File.dirname(__FILE__) + '/../../lorem.txt', 'r')
p s3.put_object('fogputobject', 'fog_put_object', file) actual = s3.put_object('fogputobject', 'fog_put_object', file)
actual.status.should == 200
p actual
end end
end end

View file

@ -2,6 +2,14 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe 'S3.put_request_payment' do describe 'S3.put_request_payment' do
before(:all) do
s3.put_bucket('fogputrequestpayment')
end
after(:all) do
s3.delete_bucket('fogputrequestpayment')
end
it 'should return proper attributes' do it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES' p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.put_request_payment('fogputrequestpayment', 'Requester') p s3.put_request_payment('fogputrequestpayment', 'Requester')