From 9de2caa48894d454a4d3818054141de5ab66b9b8 Mon Sep 17 00:00:00 2001 From: Michiel Sikkes Date: Mon, 16 Apr 2012 19:03:05 +0200 Subject: [PATCH] [aws|storage|] Make get_object_http_url use correct S3 host in returned URL This fixes a previous typo in get_object_http_url to correctly use the configured AWS S3 host name in the URL and adds a test for the default case where the bucket name can be used as a DNS CNAME. For example, a bucket company-testbucket would translate into: http://company-testbucket./company-testbucket./fog_object?AWSAccessKeyId=... Which is now fixed into: http://company-testbucket.s3.amazonaws.com/fog_object?AWSAccessKeyId=... --- lib/fog/aws/requests/storage/get_object_http_url.rb | 2 +- tests/aws/requests/storage/object_tests.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fog/aws/requests/storage/get_object_http_url.rb b/lib/fog/aws/requests/storage/get_object_http_url.rb index 898e4539a..8c30645a7 100644 --- a/lib/fog/aws/requests/storage/get_object_http_url.rb +++ b/lib/fog/aws/requests/storage/get_object_http_url.rb @@ -12,7 +12,7 @@ module Fog raise ArgumentError.new('object_name is required') end host, path = if bucket_name =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/ - ["#{bucket_name}.#{host}", object_name] + ["#{bucket_name}.#{@host}", object_name] else [@host, "#{bucket_name}/#{object_name}"] end diff --git a/tests/aws/requests/storage/object_tests.rb b/tests/aws/requests/storage/object_tests.rb index 346390b7a..a1f0afcda 100644 --- a/tests/aws/requests/storage/object_tests.rb +++ b/tests/aws/requests/storage/object_tests.rb @@ -83,6 +83,11 @@ Shindo.tests('AWS::Storage | object requests', ['aws']) do tests("#delete_object('#{@directory.identity}', 'fog_object')").succeeds do Fog::Storage[:aws].delete_object(@directory.identity, 'fog_object') end + + 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 end