Skip to content

Commit

Permalink
Resolved an issue/regression with s3 presigned URLs with x-amz-* head…
Browse files Browse the repository at this point in the history
…ers.

Fixes #816.
  • Loading branch information
trevorrowe committed May 15, 2015
1 parent 8693c82 commit 62766c9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Unreleased Changes
------------------

* Issue - Resolved a regression with presigned S3 urls where input parameters
that are normally sent as x-amz-* headers had to be serialized onto the
GET or PUT request. This restores the behavior where they are hoisted
onto the request uri as query string parameters.

See [related GitHub issue #816](https://github.com/aws/aws-sdk-ruby/pull/816)

2.0.43 (2015-05-14)
------------------

Expand Down
10 changes: 10 additions & 0 deletions aws-sdk-core/features/s3/presigned.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ Feature: S3 Presigned Operations
Then I make an unauthenticated GET request for key "test"
And the response should be "hello"

Scenario: Presigning a put object request with x-amz-*
When I create a presigned url for "put_object" with:
| key | test |
| acl | public-read |
| storage_class | REDUCED_REDUNDANCY |
And I send an HTTP put request for the presigned url with body "hello"
Then the object "test" should have a "REDUCED_REDUNDANCY" storage class
Then I make an unauthenticated GET request for key "test"
And the response should be "hello"

Scenario: Presigned PUT with content-type
When I create a presigned url for "put_object" with:
| key | test |
Expand Down
9 changes: 7 additions & 2 deletions aws-sdk-core/features/s3/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def create_bucket(options = {})
When(/^I send an HTTP put request for the presigned url with body "(.*?)"$/) do |body|
uri = URI(@url)
http = Net::HTTP.new(uri.host)
req = Net::HTTP::Put.new(uri, 'x-amz-acl' => 'public-read')
req = Net::HTTP::Put.new(uri)
req.body = body
@resp = http.request(req)
expect(@resp.code).to eq('200')
Expand Down Expand Up @@ -240,11 +240,16 @@ def create_bucket(options = {})
When(/^I send an HTTP put request with the content type as "(.*?)"$/) do |content_type|
uri = URI(@url)
http = Net::HTTP.new(uri.host)
req = Net::HTTP::Put.new(uri, 'x-amz-acl' => 'public-read', 'content-type' => content_type)
req = Net::HTTP::Put.new(uri, 'content-type' => content_type)
req.body = 'data'
@resp = http.request(req)
end

When(/^the response should have a (\d+) status code$/) do |code|
expect(@resp.code).to eq(code)
end

Then(/^the object "([^"]*)" should have a "([^"]*)" storage class$/) do |key, sc|
resp = @client.list_objects(bucket: @bucket_name, prefix: key, max_keys: 1)
expect(resp.contents.first.storage_class).to eq(sc)
end
7 changes: 7 additions & 0 deletions aws-sdk-core/lib/aws-sdk-core/signers/v4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def presigned_url(request, options = {})
request.headers.delete('User-Agent')

params = Aws::Query::ParamList.new

request.headers.keys.each do |key|
if key.match(/^x-amz/i)
params.set(key, request.headers.delete(key))
end
end

params.set("X-Amz-Algorithm", "AWS4-HMAC-SHA256")
params.set("X-Amz-Credential", credential(now))
params.set("X-Amz-Date", now)
Expand Down

0 comments on commit 62766c9

Please sign in to comment.