Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fixed wrong permissions ('private' and 'public-read') into the right
Browse files Browse the repository at this point in the history
ones (:private and :public_read) in the s3_test
completed test for lambda permission value
  • Loading branch information
momolog committed Oct 20, 2011
1 parent 1571290 commit 3a6ca7d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
6 changes: 3 additions & 3 deletions lib/paperclip/storage/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def self.extended base
@s3_permissions = set_permissions(@options.s3_permissions)
@s3_protocol = @options.s3_protocol ||
Proc.new do |style, attachment|
permission = (@s3_permissions[style.to_sym] || @s3_permissions[:default])
permission = permission.call(attachment, style) if permission.is_a?(Proc)
permission == :public_read ? 'http' : 'https'
permission = (@s3_permissions[style.to_sym] || @s3_permissions[:default])
permission = permission.call(attachment, style) if permission.is_a?(Proc)
(permission == :public_read) ? 'http' : 'https'
end
@s3_headers = @options.s3_headers || {}

Expand Down
54 changes: 30 additions & 24 deletions test/storage/s3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
end

context "S3 Permissions" do
context "defaults to public-read" do
context "defaults to :public_read" do
setup do
rebuild_model :storage => :s3,
:bucket => "testing",
Expand Down Expand Up @@ -556,7 +556,7 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_permissions => 'private'
:s3_permissions => :private
end

context "when assigned" do
Expand All @@ -575,7 +575,7 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
anything,
'testing',
:content_type => 'image/png',
:access => 'private')
:access => :private)
@dummy.save
end

Expand All @@ -599,8 +599,8 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
'secret_access_key' => "54321"
},
:s3_permissions => {
:original => 'private',
:thumb => 'public-read'
:original => :private,
:thumb => :public_read
}
end

Expand All @@ -621,7 +621,7 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
anything,
'testing',
:content_type => 'image/png',
:access => style == :thumb ? 'public-read' : 'private')
:access => style == :thumb ? :public_read : :private)
end
@dummy.save
end
Expand All @@ -635,17 +635,21 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError

context "proc permission set" do
setup do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:styles => {
:thumb => "80x80>"
},
:s3_credentials => {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_permissions => lambda{|attachment, style| attachment.instance.private_attachment? && style.to_sym != :thumb ? 'private' : 'public-read' }
rebuild_model(
:storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:styles => {
:thumb => "80x80>"
},
:s3_credentials => {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_permissions => lambda {|attachment, style|
attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :public_read
}
)
end

context "when assigned" do
Expand All @@ -662,18 +666,20 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
setup do
AWS::S3::Base.stubs(:establish_connection!)
[:thumb, :original].each do |style|
AWS::S3::S3Object.expects(:store).with("avatars/#{style}/5k.png",
anything,
'testing',
:content_type => 'image/png',
:access => style == :thumb ? 'public-read' : 'private')
AWS::S3::S3Object.expects(:store).with(
"avatars/#{style}/5k.png",
anything,
'testing',
:content_type => 'image/png',
:access => style == :thumb ? :public_read : :private
)
end
@dummy.save
end

should "succeed" do
assert_equal 0, @dummy.avatar.url() =~ /^https:/
assert_equal 0, @dummy.avatar.url(:thumb) =~ /^http:/
assert @dummy.avatar.url().include? "https://"
assert @dummy.avatar.url(:thumb).include? "http://"
end
end
end
Expand Down

0 comments on commit 3a6ca7d

Please sign in to comment.