mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Merge pull request #593 from midhunkrishna/fix/duplicate-subdomain-in-url
Fixes domain name duplication in url
This commit is contained in:
commit
6455ecbed8
3 changed files with 116 additions and 3 deletions
|
@ -298,6 +298,8 @@ module Fog
|
||||||
host = params.fetch(:cname, bucket_name)
|
host = params.fetch(:cname, bucket_name)
|
||||||
elsif path_style
|
elsif path_style
|
||||||
path = bucket_to_path bucket_name, path
|
path = bucket_to_path bucket_name, path
|
||||||
|
elsif host.start_with?("#{bucket_name}.")
|
||||||
|
# no-op
|
||||||
else
|
else
|
||||||
host = [bucket_name, host].join('.')
|
host = [bucket_name, host].join('.')
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,117 @@
|
||||||
Shindo.tests("Storage[:aws] | directory", ["aws"]) do
|
Shindo.tests("Storage[:aws] | directory", ["aws"]) do
|
||||||
|
tests('Fog::Storage[:aws]', "#request_params") do
|
||||||
|
def slice(hash, *args)
|
||||||
|
hash.select { |k, _| args.include?(k) }
|
||||||
|
end
|
||||||
|
|
||||||
|
instance = Fog::Storage[:aws]
|
||||||
|
method = instance.method(:request_params)
|
||||||
|
|
||||||
|
params = {bucket_name: 'profile-uploads', host: 'profile-uploads.s3.us-west-2.amazonaws.com'}
|
||||||
|
tests("given #{params}, request_params[:host]").returns("profile-uploads.s3.us-west-2.amazonaws.com") do
|
||||||
|
method.call(params)[:host]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {bucket_name: 'profile-uploads.johnsmith.net', cname: 'profile-uploads.johnsmith.net', virtual_host: true}
|
||||||
|
tests("given #{params}, request_params[:host]").returns("profile-uploads.johnsmith.net") do
|
||||||
|
method.call(params)[:host]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {bucket_name: 'profile-uploads.johnsmith.net', cname: 'profile-uploads.johnsmith.net', virtual_host: false}
|
||||||
|
tests("given #{params}, request_params[:host], request_params[:path]").
|
||||||
|
returns({host: "s3.amazonaws.com", path: "/profile-uploads.johnsmith.net/"}) do
|
||||||
|
slice(method.call(params), :host, :path)
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {bucket_name: 'profile-uploads.johnsmith.net', bucket_cname: 'profile-uploads.johnsmith.net'}
|
||||||
|
tests("given #{params}, request_params[:host]").returns("profile-uploads.johnsmith.net") do
|
||||||
|
method.call(params)[:host]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {bucket_name: 'profile-uploads'}
|
||||||
|
tests("given #{params}, request_params[:path], request_params[:host]").
|
||||||
|
returns({path: "/", host: "profile-uploads.s3.amazonaws.com"}) do
|
||||||
|
slice(method.call(params), :path, :host)
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {bucket_name: 'profile-uploads', path_style: true}
|
||||||
|
tests("given #{params}, request_params[:path], request_params[:host]").
|
||||||
|
returns({path: "/profile-uploads/", host: "s3.amazonaws.com"}) do
|
||||||
|
slice(method.call(params), :path, :host)
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {bucket_name: 'profile-uploads', path_style: false}
|
||||||
|
tests("given #{params}, request_params[:path], request_params[:host]").
|
||||||
|
returns({path: "/", host: "profile-uploads.s3.amazonaws.com"}) do
|
||||||
|
slice(method.call(params), :path, :host)
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {scheme: 'https', bucket_name: 'profile.uploads', path_style: false}
|
||||||
|
tests("given #{params}, request_params[:path], request_params[:host]").
|
||||||
|
returns(path: "/profile.uploads/", host: "s3.amazonaws.com") do
|
||||||
|
slice(method.call(params), :path, :host)
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {:headers=>{:"Content-Type"=>"application/json"}}
|
||||||
|
tests("given #{params}, request_params[:headers]").returns({:"Content-Type"=>"application/json"}) do
|
||||||
|
method.call(params)[:headers]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {headers: {}}
|
||||||
|
tests("given #{params}, request_params[:headers]").returns({}) do
|
||||||
|
method.call(params)[:headers]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {scheme: 'http'}
|
||||||
|
tests("given #{params}, request_params[:scheme]").returns('http') do
|
||||||
|
method.call(params)[:scheme]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {}
|
||||||
|
tests("given #{params}, request_params[:scheme]").returns('https') do
|
||||||
|
method.call(params)[:scheme]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {scheme: 'http', port: 8080}
|
||||||
|
tests("given #{params} (default scheme), request_params[:port]").returns(8080) do
|
||||||
|
method.call(params)[:port]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {scheme: 'https', port: 443}
|
||||||
|
tests("given #{params}, request_params[:port]").returns(nil) do
|
||||||
|
method.call(params)[:port]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {}
|
||||||
|
tests("given #{params}, request_params[:host]").returns("s3.amazonaws.com") do
|
||||||
|
method.call(params)[:host]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {region: 'us-east-1'}
|
||||||
|
tests("given #{params}, request_params[:host]").returns("s3.amazonaws.com") do
|
||||||
|
method.call(params)[:host]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {region: 'us-west-2'}
|
||||||
|
tests("given #{params}, request_params[:host]").returns("s3.us-west-2.amazonaws.com") do
|
||||||
|
method.call(params)[:host]
|
||||||
|
end
|
||||||
|
|
||||||
|
params= {region: 'us-east-1', host: 's3.us-west-2.amazonaws.com'}
|
||||||
|
tests("given #{params}, request_params[:host]").returns("s3.us-west-2.amazonaws.com") do
|
||||||
|
method.call(params)[:host]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {object_name: 'image.png'}
|
||||||
|
tests("given #{params}, request_params[:host]").returns("/image.png") do
|
||||||
|
method.call(params)[:path]
|
||||||
|
end
|
||||||
|
|
||||||
|
params = {object_name: 'image.png', path: '/images/image.png'}
|
||||||
|
tests("given #{params}, request_params[:host]").returns("/images/image.png") do
|
||||||
|
method.call(params)[:path]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
directory_attributes = {
|
directory_attributes = {
|
||||||
:key => uniq_id('fogdirectorytests')
|
:key => uniq_id('fogdirectorytests')
|
||||||
|
@ -85,7 +198,5 @@ Shindo.tests("Storage[:aws] | directory", ["aws"]) do
|
||||||
@instance.versioning?
|
@instance.versioning?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -158,7 +158,7 @@ Shindo.tests('Fog::Storage[:aws] | bucket requests', ["aws"]) do
|
||||||
Fog::Storage[:aws].put_bucket_website(@aws_bucket_name, :IndexDocument => 'index.html')
|
Fog::Storage[:aws].put_bucket_website(@aws_bucket_name, :IndexDocument => 'index.html')
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#put_bucket_website('#{@aws_bucket_name}', :RedirectAllRequestsTo => 'redirect.example..com')").succeeds do
|
tests("#put_bucket_website('#{@aws_bucket_name}', :RedirectAllRequestsTo => 'redirect.example.com')").succeeds do
|
||||||
Fog::Storage[:aws].put_bucket_website(@aws_bucket_name, :RedirectAllRequestsTo => 'redirect.example.com')
|
Fog::Storage[:aws].put_bucket_website(@aws_bucket_name, :RedirectAllRequestsTo => 'redirect.example.com')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue