Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add use_ssl flag to Signature generate_temporary_url method. #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/s3/signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,21 @@ def self.generate_temporary_url_signature(options)
# to use when requesting the resource
# * <tt>:add_bucket_to_host</tt> - Use in case of virtual-host style,
# defaults to false
# * <tt>:use_ssl</tt> - If true generates the temporary url with 'https'
# as opposed to 'http'
def self.generate_temporary_url(options)
bucket = options[:bucket]
resource = options[:resource]
access_key = options[:access_key]
expires = options[:expires_at].to_i
protocol = (options[:use_ssl] ? 'https://' : 'http://')
host = S3.host

if options[:add_bucket_to_host]
host = bucket + '.' + host
url = "http://#{host}/#{resource}"
url = "#{protocol}#{host}/#{resource}"
else
url = "http://#{host}/#{bucket}/#{resource}"
url = "#{protocol}#{host}/#{bucket}/#{resource}"
end

options[:host] = host
Expand Down
14 changes: 13 additions & 1 deletion test/signature_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class SignatureTest < Test::Unit::TestCase
expected = "gs6xNznrLJ4Bd%2B1y9pcy2HOSVeg%3D"
assert_equal expected, actual
end

test "temporary signature for object get with non-unreserved URI characters" do
actual = S3::Signature.generate_temporary_url_signature(
:bucket => "johnsmith",
Expand Down Expand Up @@ -212,6 +212,18 @@ class SignatureTest < Test::Unit::TestCase
assert_equal expected, actual
end

test "temporary url for object get using ssl" do
actual = S3::Signature.generate_temporary_url(
:bucket => "johnsmith",
:resource => "photos/puppy.jpg",
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
:expires_at => 1175046589,
:use_ssl => true
)
expected = "https://s3.amazonaws.com/johnsmith/photos/puppy.jpg?AWSAccessKeyId=&Expires=1175046589&Signature=gs6xNznrLJ4Bd%2B1y9pcy2HOSVeg%3D"
assert_equal expected, actual
end

test "temporary url for object put with headers" do
actual = S3::Signature.generate_temporary_url(
:bucket => "johnsmith",
Expand Down