Generate a new key for each service test

Sidestep Google Cloud Storage's restrictive per-object rate limit.
This commit is contained in:
George Claghorn 2018-06-25 18:49:26 -04:00
parent 9858811825
commit 56b9d0fd3a
6 changed files with 20 additions and 20 deletions

View File

@ -10,7 +10,7 @@ if SERVICE_CONFIGURATIONS[:azure]
include ActiveStorage::Service::SharedServiceTests
test "signed URL generation" do
url = @service.url(FIXTURE_KEY, expires_in: 5.minutes,
url = @service.url(@key, expires_in: 5.minutes,
disposition: :inline, filename: ActiveStorage::Filename.new("avatar.png"), content_type: "image/png")
assert_match(/(\S+)&rscd=inline%3B\+filename%3D%22avatar\.png%22%3B\+filename\*%3DUTF-8%27%27avatar\.png&rsct=image%2Fpng/, url)

View File

@ -9,10 +9,10 @@ class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase
test "url generation" do
assert_match(/^https:\/\/example.com\/rails\/active_storage\/disk\/.*\/avatar\.png\?content_type=image%2Fpng&disposition=inline/,
@service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: ActiveStorage::Filename.new("avatar.png"), content_type: "image/png"))
@service.url(@key, expires_in: 5.minutes, disposition: :inline, filename: ActiveStorage::Filename.new("avatar.png"), content_type: "image/png"))
end
test "headers_for_direct_upload generation" do
assert_equal({ "Content-Type" => "application/json" }, @service.headers_for_direct_upload(FIXTURE_KEY, content_type: "application/json"))
assert_equal({ "Content-Type" => "application/json" }, @service.headers_for_direct_upload(@key, content_type: "application/json"))
end
end

View File

@ -33,7 +33,7 @@ if SERVICE_CONFIGURATIONS[:gcs]
test "signed URL generation" do
assert_match(/storage\.googleapis\.com\/.*response-content-disposition=inline.*test\.txt.*response-content-type=text%2Fplain/,
@service.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: ActiveStorage::Filename.new("test.txt"), content_type: "text/plain"))
@service.url(@key, expires_in: 2.minutes, disposition: :inline, filename: ActiveStorage::Filename.new("test.txt"), content_type: "text/plain"))
end
test "signed URL response headers" do

View File

@ -47,11 +47,11 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
end
test "deleting from all services" do
@service.delete FIXTURE_KEY
@service.delete @key
assert_not SERVICE.primary.exist?(FIXTURE_KEY)
assert_not SERVICE.primary.exist?(@key)
SERVICE.mirrors.each do |mirror|
assert_not mirror.exist?(FIXTURE_KEY)
assert_not mirror.exist?(@key)
end
end
@ -59,8 +59,8 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
filename = ActiveStorage::Filename.new("test.txt")
freeze_time do
assert_equal @service.primary.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: filename, content_type: "text/plain"),
@service.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: filename, content_type: "text/plain")
assert_equal @service.primary.url(@key, expires_in: 2.minutes, disposition: :inline, filename: filename, content_type: "text/plain"),
@service.url(@key, expires_in: 2.minutes, disposition: :inline, filename: filename, content_type: "text/plain")
end
end
end

View File

@ -32,7 +32,7 @@ if SERVICE_CONFIGURATIONS[:s3]
end
test "signed URL generation" do
url = @service.url(FIXTURE_KEY, expires_in: 5.minutes,
url = @service.url(@key, expires_in: 5.minutes,
disposition: :inline, filename: ActiveStorage::Filename.new("avatar.png"), content_type: "image/png")
assert_match(/s3(-[-a-z0-9]+)?\.(\S+)?amazonaws.com.*response-content-disposition=inline.*avatar\.png.*response-content-type=image%2Fpng/, url)

View File

@ -6,17 +6,17 @@ require "active_support/core_ext/securerandom"
module ActiveStorage::Service::SharedServiceTests
extend ActiveSupport::Concern
FIXTURE_KEY = SecureRandom.base58(24)
FIXTURE_DATA = "\211PNG\r\n\032\n\000\000\000\rIHDR\000\000\000\020\000\000\000\020\001\003\000\000\000%=m\"\000\000\000\006PLTE\000\000\000\377\377\377\245\331\237\335\000\000\0003IDATx\234c\370\377\237\341\377_\206\377\237\031\016\2603\334?\314p\1772\303\315\315\f7\215\031\356\024\203\320\275\317\f\367\201R\314\f\017\300\350\377\177\000Q\206\027(\316]\233P\000\000\000\000IEND\256B`\202".dup.force_encoding(Encoding::BINARY)
included do
setup do
@key = SecureRandom.base58(24)
@service = self.class.const_get(:SERVICE)
@service.upload FIXTURE_KEY, StringIO.new(FIXTURE_DATA)
@service.upload @key, StringIO.new(FIXTURE_DATA)
end
teardown do
@service.delete FIXTURE_KEY
@service.delete @key
end
test "uploading with integrity" do
@ -47,7 +47,7 @@ module ActiveStorage::Service::SharedServiceTests
end
test "downloading" do
assert_equal FIXTURE_DATA, @service.download(FIXTURE_KEY)
assert_equal FIXTURE_DATA, @service.download(@key)
end
test "downloading in chunks" do
@ -69,18 +69,18 @@ module ActiveStorage::Service::SharedServiceTests
end
test "downloading partially" do
assert_equal "\x10\x00\x00", @service.download_chunk(FIXTURE_KEY, 19..21)
assert_equal "\x10\x00\x00", @service.download_chunk(FIXTURE_KEY, 19...22)
assert_equal "\x10\x00\x00", @service.download_chunk(@key, 19..21)
assert_equal "\x10\x00\x00", @service.download_chunk(@key, 19...22)
end
test "existing" do
assert @service.exist?(FIXTURE_KEY)
assert_not @service.exist?(FIXTURE_KEY + "nonsense")
assert @service.exist?(@key)
assert_not @service.exist?(@key + "nonsense")
end
test "deleting" do
@service.delete FIXTURE_KEY
assert_not @service.exist?(FIXTURE_KEY)
@service.delete @key
assert_not @service.exist?(@key)
end
test "deleting nonexistent key" do