From 98bb99ef61902c1073cc51a52ab7954c0ca922a5 Mon Sep 17 00:00:00 2001 From: claudiob Date: Tue, 1 Aug 2017 10:56:39 -0700 Subject: Don't depend on HTTParty "httparty" is only added in #30020 to write two tests to make PUT requests against S3 and GCS. The same requests can be made with net/http, removing a dependency from the Gemfile. --- activestorage/test/service/s3_service_test.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'activestorage/test/service/s3_service_test.rb') diff --git a/activestorage/test/service/s3_service_test.rb b/activestorage/test/service/s3_service_test.rb index fa2df263a6..a8bec0736d 100644 --- a/activestorage/test/service/s3_service_test.rb +++ b/activestorage/test/service/s3_service_test.rb @@ -1,5 +1,5 @@ require "service/shared_service_tests" -require "httparty" +require "net/http" if SERVICE_CONFIGURATIONS[:s3] class ActiveStorage::Service::S3ServiceTest < ActiveSupport::TestCase @@ -14,12 +14,14 @@ if SERVICE_CONFIGURATIONS[:s3] checksum = Digest::MD5.base64digest(data) url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size, checksum: checksum) - HTTParty.put( - url, - body: data, - headers: { "Content-Type" => "text/plain", "Content-MD5" => checksum }, - debug_output: STDOUT - ) + uri = URI.parse url + request = Net::HTTP::Put.new uri.request_uri + request.body = data + request.add_field 'Content-Type', 'text/plain' + request.add_field 'Content-MD5', checksum + Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| + http.request request + end assert_equal data, @service.download(key) ensure -- cgit v1.2.3 From ff3dad07bacd4f41cb2d7857794acdff9c1c7ee2 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 1 Aug 2017 17:22:20 -0500 Subject: Skip if credentials aren't provided --- activestorage/test/service/s3_service_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activestorage/test/service/s3_service_test.rb') diff --git a/activestorage/test/service/s3_service_test.rb b/activestorage/test/service/s3_service_test.rb index a8bec0736d..ae17eb32aa 100644 --- a/activestorage/test/service/s3_service_test.rb +++ b/activestorage/test/service/s3_service_test.rb @@ -1,7 +1,7 @@ require "service/shared_service_tests" require "net/http" -if SERVICE_CONFIGURATIONS[:s3] +if SERVICE_CONFIGURATIONS[:s3] && SERVICE_CONFIGURATIONS[:s3][:access_key_id].present? class ActiveStorage::Service::S3ServiceTest < ActiveSupport::TestCase SERVICE = ActiveStorage::Service.configure(:s3, SERVICE_CONFIGURATIONS) -- cgit v1.2.3 From 815d1abf3962d65c0bb9043c99a507580b4360df Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Thu, 3 Aug 2017 03:13:11 +0900 Subject: Fix `Style/StringLiterals` violations for Active Storage ``` % be rubocop -a --only Style/StringLiterals activestorage Inspecting 74 files ........................................CCCCCCCCCC.C........CC.......C.C.. (snip) 74 files inspected, 31 offenses detected, 31 offenses corrected ``` --- activestorage/test/service/s3_service_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activestorage/test/service/s3_service_test.rb') diff --git a/activestorage/test/service/s3_service_test.rb b/activestorage/test/service/s3_service_test.rb index ae17eb32aa..23b94f25ed 100644 --- a/activestorage/test/service/s3_service_test.rb +++ b/activestorage/test/service/s3_service_test.rb @@ -17,8 +17,8 @@ if SERVICE_CONFIGURATIONS[:s3] && SERVICE_CONFIGURATIONS[:s3][:access_key_id].pr uri = URI.parse url request = Net::HTTP::Put.new uri.request_uri request.body = data - request.add_field 'Content-Type', 'text/plain' - request.add_field 'Content-MD5', checksum + request.add_field "Content-Type", "text/plain" + request.add_field "Content-MD5", checksum Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| http.request request end -- cgit v1.2.3 From 9d636c9e2fae61712164c9293d947547443fed5e Mon Sep 17 00:00:00 2001 From: claudiob Date: Thu, 3 Aug 2017 11:41:23 -0700 Subject: Make Rubocop happier about ActiveStorage Running `rubocop activestorage` before this commit resulted in 20 offenses. This commit only fixes: - Trailing whitespace detected - Space inside } missing - Put one space between the method name and the first argument. The other offenses are left since they are intentional according to @georgeclaghorn (https://github.com/rails/rails/pull/30061#issuecomment-319999190) --- activestorage/test/service/s3_service_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activestorage/test/service/s3_service_test.rb') diff --git a/activestorage/test/service/s3_service_test.rb b/activestorage/test/service/s3_service_test.rb index 23b94f25ed..ec80cbce61 100644 --- a/activestorage/test/service/s3_service_test.rb +++ b/activestorage/test/service/s3_service_test.rb @@ -35,7 +35,7 @@ if SERVICE_CONFIGURATIONS[:s3] && SERVICE_CONFIGURATIONS[:s3][:access_key_id].pr end test "uploading with server-side encryption" do - config = SERVICE_CONFIGURATIONS.deep_merge(s3: { upload: { server_side_encryption: "AES256" }}) + config = SERVICE_CONFIGURATIONS.deep_merge(s3: { upload: { server_side_encryption: "AES256" } }) service = ActiveStorage::Service.configure(:s3, config) begin -- cgit v1.2.3 From b9f0eb24ed6a86aec3881b43e6b0028a306465b2 Mon Sep 17 00:00:00 2001 From: Claudio B Date: Fri, 4 Aug 2017 15:56:14 -0700 Subject: Fix tests for AWS buckets that include a . (#30059) If an AWS bucket name includes a `.` (e.g. `bucket.name`), then the canonical URL for an object will start with "https://s3.amazonaws.com/bucket.name/" and not with "https://bucket.name.s3.amazonaws.com/". The URL tests have now been separated into two separate asserts, to ensure that both the "s3.amazonaws.com" and the "bucket.name" components are included, but not specifically in that order. --- activestorage/test/service/s3_service_test.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'activestorage/test/service/s3_service_test.rb') diff --git a/activestorage/test/service/s3_service_test.rb b/activestorage/test/service/s3_service_test.rb index ec80cbce61..6d613fd4fc 100644 --- a/activestorage/test/service/s3_service_test.rb +++ b/activestorage/test/service/s3_service_test.rb @@ -30,8 +30,11 @@ if SERVICE_CONFIGURATIONS[:s3] && SERVICE_CONFIGURATIONS[:s3][:access_key_id].pr end test "signed URL generation" do - assert_match /#{SERVICE_CONFIGURATIONS[:s3][:bucket]}\.s3.(\S+)?amazonaws.com.*response-content-disposition=inline.*avatar\.png.*response-content-type=image%2Fpng/, - @service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: "avatar.png", content_type: "image/png") + url = @service.url(FIXTURE_KEY, expires_in: 5.minutes, + disposition: :inline, filename: "avatar.png", content_type: "image/png") + + assert_match /s3\.(\S+)?amazonaws.com.*response-content-disposition=inline.*avatar\.png.*response-content-type=image%2Fpng/, url + assert_match SERVICE_CONFIGURATIONS[:s3][:bucket], url end test "uploading with server-side encryption" do -- cgit v1.2.3