From a9cb1968b6a01572a472a3df3aa750ebc022e076 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 31 Jul 2017 17:51:16 -0500 Subject: Setup travis to be able to run CI tests against S3 --- activestorage/test/service/.gitignore | 1 - .../test/service/configurations-example.yml | 31 ---------------------- activestorage/test/service/configurations.yml | 30 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 32 deletions(-) delete mode 100644 activestorage/test/service/.gitignore delete mode 100644 activestorage/test/service/configurations-example.yml create mode 100644 activestorage/test/service/configurations.yml (limited to 'activestorage/test/service') diff --git a/activestorage/test/service/.gitignore b/activestorage/test/service/.gitignore deleted file mode 100644 index c102131f3d..0000000000 --- a/activestorage/test/service/.gitignore +++ /dev/null @@ -1 +0,0 @@ -configurations.yml diff --git a/activestorage/test/service/configurations-example.yml b/activestorage/test/service/configurations-example.yml deleted file mode 100644 index 68f6ae4224..0000000000 --- a/activestorage/test/service/configurations-example.yml +++ /dev/null @@ -1,31 +0,0 @@ -# Copy this file to configurations.yml and edit the credentials to match your IAM test account and bucket -s3: - service: S3 - access_key_id: - secret_access_key: - region: - bucket: - -gcs: - service: GCS - keyfile: { - type: "service_account", - project_id: "", - private_key_id: "", - private_key: "", - client_email: "", - client_id: "", - auth_uri: "https://accounts.google.com/o/oauth2/auth", - token_uri: "https://accounts.google.com/o/oauth2/token", - auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs", - client_x509_cert_url: "" - } - project: - bucket: - -azure: - service: Azure - path: "" - storage_account_name: "" - storage_access_key: "" - container: "" diff --git a/activestorage/test/service/configurations.yml b/activestorage/test/service/configurations.yml new file mode 100644 index 0000000000..90b6baf0db --- /dev/null +++ b/activestorage/test/service/configurations.yml @@ -0,0 +1,30 @@ +s3: + service: S3 + access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %> + secret_access_key: <%= ENV["AWS_SECRET_KEY"] %> + region: us-east-2 + bucket: rails-ci-activestorage + +# gcs: +# service: GCS +# keyfile: { +# type: "service_account", +# project_id: "", +# private_key_id: "", +# private_key: "", +# client_email: "", +# client_id: "", +# auth_uri: "https://accounts.google.com/o/oauth2/auth", +# token_uri: "https://accounts.google.com/o/oauth2/token", +# auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs", +# client_x509_cert_url: "" +# } +# project: +# bucket: +# +# azure: +# service: Azure +# path: "" +# storage_account_name: "" +# storage_access_key: "" +# container: "" -- cgit v1.2.3 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/azure_service_test.rb | 1 - activestorage/test/service/gcs_service_test.rb | 16 +++++++++------- activestorage/test/service/s3_service_test.rb | 16 +++++++++------- 3 files changed, 18 insertions(+), 15 deletions(-) (limited to 'activestorage/test/service') diff --git a/activestorage/test/service/azure_service_test.rb b/activestorage/test/service/azure_service_test.rb index 0ddbac83e7..fb617db019 100644 --- a/activestorage/test/service/azure_service_test.rb +++ b/activestorage/test/service/azure_service_test.rb @@ -1,5 +1,4 @@ require "service/shared_service_tests" -require "httparty" require "uri" if SERVICE_CONFIGURATIONS[:azure] diff --git a/activestorage/test/service/gcs_service_test.rb b/activestorage/test/service/gcs_service_test.rb index 134a06e3a4..aca779c167 100644 --- a/activestorage/test/service/gcs_service_test.rb +++ b/activestorage/test/service/gcs_service_test.rb @@ -1,5 +1,5 @@ require "service/shared_service_tests" -require "httparty" +require "net/http" if SERVICE_CONFIGURATIONS[:gcs] class ActiveStorage::Service::GCSServiceTest < ActiveSupport::TestCase @@ -14,12 +14,14 @@ if SERVICE_CONFIGURATIONS[:gcs] 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 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') 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/gcs_service_test.rb | 4 ++-- activestorage/test/service/s3_service_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'activestorage/test/service') diff --git a/activestorage/test/service/gcs_service_test.rb b/activestorage/test/service/gcs_service_test.rb index aca779c167..03048731bc 100644 --- a/activestorage/test/service/gcs_service_test.rb +++ b/activestorage/test/service/gcs_service_test.rb @@ -17,8 +17,8 @@ if SERVICE_CONFIGURATIONS[:gcs] 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 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') 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') 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 From 3179f089be4f631b9c0f8b431567992164f2bdb4 Mon Sep 17 00:00:00 2001 From: Dino Maric Date: Sat, 5 Aug 2017 00:57:02 +0200 Subject: Rename Azure to AzureStorage (#30057) --- activestorage/test/service/azure_service_test.rb | 13 ------------- activestorage/test/service/azure_storage_service_test.rb | 13 +++++++++++++ activestorage/test/service/configurations.yml | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) delete mode 100644 activestorage/test/service/azure_service_test.rb create mode 100644 activestorage/test/service/azure_storage_service_test.rb (limited to 'activestorage/test/service') diff --git a/activestorage/test/service/azure_service_test.rb b/activestorage/test/service/azure_service_test.rb deleted file mode 100644 index fb617db019..0000000000 --- a/activestorage/test/service/azure_service_test.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "service/shared_service_tests" -require "uri" - -if SERVICE_CONFIGURATIONS[:azure] - class ActiveStorage::Service::AzureServiceTest < ActiveSupport::TestCase - SERVICE = ActiveStorage::Service.configure(:azure, SERVICE_CONFIGURATIONS) - - include ActiveStorage::Service::SharedServiceTests - end - -else - puts "Skipping Azure Storage Service tests because no Azure configuration was supplied" -end diff --git a/activestorage/test/service/azure_storage_service_test.rb b/activestorage/test/service/azure_storage_service_test.rb new file mode 100644 index 0000000000..e2be510b60 --- /dev/null +++ b/activestorage/test/service/azure_storage_service_test.rb @@ -0,0 +1,13 @@ +require "service/shared_service_tests" +require "uri" + +if SERVICE_CONFIGURATIONS[:azure] + class ActiveStorage::Service::AzureStorageServiceTest < ActiveSupport::TestCase + SERVICE = ActiveStorage::Service.configure(:azure, SERVICE_CONFIGURATIONS) + + include ActiveStorage::Service::SharedServiceTests + end + +else + puts "Skipping Azure Storage Service tests because no Azure configuration was supplied" +end diff --git a/activestorage/test/service/configurations.yml b/activestorage/test/service/configurations.yml index 90b6baf0db..d7aa672573 100644 --- a/activestorage/test/service/configurations.yml +++ b/activestorage/test/service/configurations.yml @@ -21,9 +21,9 @@ s3: # } # project: # bucket: -# +# # azure: -# service: Azure +# service: AzureStorage # path: "" # storage_account_name: "" # storage_access_key: "" -- cgit v1.2.3