Skip to content

Commit

Permalink
Merge pull request #861 from didacte/bugfix/s3-presigned-default-expires
Browse files Browse the repository at this point in the history
Ensure S3 presigned default expires time is not changing
  • Loading branch information
trevorrowe committed Jul 6, 2015
2 parents 109ab53 + 3a09755 commit f5a3664
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/aws/s3/presigned_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def initialize(bucket, opts = {})
@content_length = range_value(opts[:content_length])
@conditions = opts[:conditions] || {}
@ignored_fields = [opts[:ignore]].flatten.compact
@expires = opts[:expires]
@expires = opts[:expires] || Time.now.utc + 60*60

super

Expand Down Expand Up @@ -397,17 +397,16 @@ def with_condition(field, condition)
# @api private
private
def format_expiration
time = expires || Time.now.utc + 60*60
time =
case time
case expires
when Time
time
expires
when DateTime
Time.parse(time.to_s)
Time.parse(expires.to_s)
when Integer
(Time.now + time)
(Time.now + expires)
when String
Time.parse(time)
Time.parse(expires)
end
time.utc.iso8601
end
Expand Down
11 changes: 11 additions & 0 deletions spec/aws/s3/presigned_post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,17 @@ def policy_conditions(post)
policy["expiration"].should == "2011-05-25T01:51:04Z"
end

it "should reuse the default expire set during initialize" do
now = Time.parse("2011-05-24T17:54:04-07:00Z")
Time.stub(:now).and_return(now)
policy["expiration"].should == "2011-05-25T01:54:04Z"

later = Time.parse("2011-05-24T17:54:05-07:00Z")
Time.stub(:now).and_return(later)
later_policy = JSON.load(Base64.decode64(post.policy))
later_policy["expiration"].should == "2011-05-25T01:54:04Z"
end

context 'when :expires is provided' do

it 'should support Time' do
Expand Down

0 comments on commit f5a3664

Please sign in to comment.