2017-07-06 06:22:44 -04:00
|
|
|
require "service/shared_service_tests"
|
2017-07-09 12:03:13 -04:00
|
|
|
require "httparty"
|
2017-07-06 06:22:44 -04:00
|
|
|
|
|
|
|
if SERVICE_CONFIGURATIONS[:s3]
|
|
|
|
class ActiveStorage::Service::S3ServiceTest < ActiveSupport::TestCase
|
2017-07-08 19:55:50 -04:00
|
|
|
SERVICE = ActiveStorage::Service.configure(:s3, SERVICE_CONFIGURATIONS)
|
2017-07-06 06:22:44 -04:00
|
|
|
|
|
|
|
include ActiveStorage::Service::SharedServiceTests
|
2017-07-09 11:04:37 -04:00
|
|
|
|
2017-07-09 12:03:13 -04:00
|
|
|
test "direct upload" do
|
|
|
|
begin
|
|
|
|
key = SecureRandom.base58(24)
|
|
|
|
data = "Something else entirely!"
|
2017-07-16 19:17:18 -04:00
|
|
|
url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size)
|
2017-07-09 12:03:13 -04:00
|
|
|
|
2017-07-16 19:17:18 -04:00
|
|
|
HTTParty.put(
|
2017-07-09 12:03:13 -04:00
|
|
|
url,
|
|
|
|
body: data,
|
2017-07-16 19:17:18 -04:00
|
|
|
headers: { "Content-Type" => "text/plain" },
|
2017-07-09 12:03:13 -04:00
|
|
|
debug_output: STDOUT
|
|
|
|
)
|
2017-07-13 15:54:06 -04:00
|
|
|
|
2017-07-09 12:03:13 -04:00
|
|
|
assert_equal data, @service.download(key)
|
|
|
|
ensure
|
|
|
|
@service.delete key
|
|
|
|
end
|
|
|
|
end
|
2017-07-13 15:54:06 -04:00
|
|
|
|
2017-07-09 11:04:37 -04:00
|
|
|
test "signed URL generation" do
|
2017-07-13 15:54:06 -04:00
|
|
|
assert_match /.+s3.+amazonaws.com.*response-content-disposition=inline.*avatar\.png/,
|
|
|
|
@service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: "avatar.png")
|
2017-07-09 11:04:37 -04:00
|
|
|
end
|
2017-07-06 06:22:44 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
puts "Skipping S3 Service tests because no S3 configuration was supplied"
|
|
|
|
end
|