Skip to content
This repository
  • 2 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
5  lib/paperclip/storage/s3.rb
@@ -115,6 +115,8 @@ def self.extended base
115 115
 
116 116
           @s3_headers[:storage_class] = @options[:s3_storage_class] if @options[:s3_storage_class]
117 117
 
  118
+          @s3_server_side_encryption = @options[:s3_server_side_encryption]
  119
+
118 120
           unless @options[:url].to_s.match(/^:s3.*url$/) || @options[:url] == ":asset_host"
119 121
             @options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/^:rails_root\/public\/system/, '')
120 122
             @options[:url]  = ":s3_path_url"
@@ -281,6 +283,9 @@ def flush_writes #:nodoc:
281 283
               :acl => acl
282 284
             }
283 285
             write_options[:metadata] = @s3_metadata unless @s3_metadata.empty?
  286
+            unless @s3_server_side_encryption.blank?
  287
+              write_options[:server_side_encryption] = @s3_server_side_encryption
  288
+            end
284 289
             write_options.merge!(@s3_headers)
285 290
             s3_object(style).write(file, write_options)
286 291
           rescue AWS::S3::Errors::NoSuchBucket => e
36  test/storage/s3_live_test.rb
@@ -134,5 +134,41 @@ class S3LiveTest < Test::Unit::TestCase
134 134
         assert_not_found_response url
135 135
       end
136 136
     end
  137
+
  138
+    context "An attachment that uses S3 for storage and uses AES256 encryption" do
  139
+      setup do
  140
+        rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
  141
+                      :storage => :s3,
  142
+                      :bucket => ENV["S3_BUCKET"],
  143
+                      :path => ":class/:attachment/:id/:style.:extension",
  144
+                      :s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml")),
  145
+                      :s3_server_side_encryption => :aes256
  146
+
  147
+        Dummy.delete_all
  148
+        @dummy = Dummy.new
  149
+      end
  150
+
  151
+      context "when assigned" do
  152
+        setup do
  153
+          @file = File.new(fixture_file('5k.png'), 'rb')
  154
+          @dummy.avatar = @file
  155
+        end
  156
+
  157
+        teardown do
  158
+          @file.close
  159
+          @dummy.destroy
  160
+        end
  161
+
  162
+        context "and saved" do
  163
+          setup do
  164
+            @dummy.save
  165
+          end
  166
+
  167
+          should "be encrypted on S3" do
  168
+            assert @dummy.avatar.s3_object.server_side_encryption == :aes256
  169
+          end
  170
+        end
  171
+      end
  172
+    end
137 173
   end
138 174
 end
39  test/storage/s3_test.rb
@@ -684,6 +684,45 @@ def counter
684 684
     end
685 685
   end
686 686
 
  687
+  context "An attachment with S3 storage and using AES256 encryption" do
  688
+    setup do
  689
+      rebuild_model :storage => :s3,
  690
+                    :bucket => "testing",
  691
+                    :path => ":attachment/:style/:basename.:extension",
  692
+                    :s3_credentials => {
  693
+                      'access_key_id' => "12345",
  694
+                      'secret_access_key' => "54321"
  695
+                    },
  696
+                    :s3_server_side_encryption => :aes256
  697
+    end
  698
+
  699
+    context "when assigned" do
  700
+      setup do
  701
+        @file = File.new(File.join(File.dirname(__FILE__), '..', 'fixtures', '5k.png'), 'rb')
  702
+        @dummy = Dummy.new
  703
+        @dummy.avatar = @file
  704
+      end
  705
+
  706
+      teardown { @file.close }
  707
+
  708
+      context "and saved" do
  709
+        setup do
  710
+          object = stub
  711
+          @dummy.avatar.stubs(:s3_object).returns(object)
  712
+          object.expects(:write).with(anything,
  713
+                                      :content_type => "image/png",
  714
+                                      :acl => :public_read,
  715
+                                      :server_side_encryption => :aes256)
  716
+          @dummy.save
  717
+        end
  718
+
  719
+        should "succeed" do
  720
+          assert true
  721
+        end
  722
+      end
  723
+    end
  724
+  end
  725
+
687 726
   context "An attachment with S3 storage and storage class set using the :storage_class option" do
688 727
     setup do
689 728
       rebuild_model :storage => :s3,

No commit comments for this range

Something went wrong with that request. Please try again.