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
def request(params)
unless params[:path] && params[:path][0] == '/'
params[:path] = '/' << params[:path].to_s
params[:path] ||= ''
unless params[:path][0] == '/'
params[:path] = '/' + params[:path].to_s
end
if params[:query]
params[:path] << "?#{params[:query]}"
end
request = "#{params[:method]} #{params[:path]} HTTP/1.1\r\n"
params[:headers] ||= {}
@ -48,15 +52,17 @@ module Fog
header = data.split(': ')
response.headers[header[0]] = header[1]
end
if response.headers['Content-Length']
response.body << @connection.read(response.headers['Content-Length'].to_i)
elsif response.headers['Transfer-Encoding'] == 'chunked'
while true
# 2 == "/r/n".length
chunk_size = @connection.readline.chomp!.to_i(16) + 2
response.body << @connection.read(chunk_size)
if chunk_size == 2
break
unless params[:method] == 'HEAD'
if response.headers['Content-Length']
response.body << @connection.read(response.headers['Content-Length'].to_i)
elsif response.headers['Transfer-Encoding'] == 'chunked'
while true
# 2 == "/r/n".length
chunk_size = @connection.readline.chomp!.to_i(16) + 2
response.body << @connection.read(chunk_size)
if chunk_size == 2
break
end
end
end
end

View file

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

View file

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

View file

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

View file

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

View file

@ -12,7 +12,9 @@ describe 'S3.delete_bucket' do
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.delete_bucket('fogdeletebucket')
actual = s3.delete_bucket('fogdeletebucket')
actual.status.should == 204
p actual
end
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
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

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
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.get_bucket('fogputbucket')
actual = s3.get_bucket('foggetbucket')
actual.status.should == 200
p actual
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
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

View file

@ -12,7 +12,9 @@ describe 'S3.get_service' do
it 'should return proper_attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.get_service
actual = s3.get_service
actual.status.should == 200
p actual
end
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
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

View file

@ -12,7 +12,9 @@ describe 'S3.put_bucket' do
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.put_bucket('fogputbucket')
actual = s3.put_bucket('fogputbucket')
actual.status.should == 200
p actual
end
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
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
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

View file

@ -2,6 +2,14 @@ require File.dirname(__FILE__) + '/../../spec_helper'
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
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.put_request_payment('fogputrequestpayment', 'Requester')