Drop CleverCloud Service for ActiveStorage

This commit is contained in:
Frederic Merizen 2018-12-11 09:55:45 +01:00
parent 5a30467594
commit 832b4a61bc
9 changed files with 1 additions and 549 deletions

View file

@ -1,87 +0,0 @@
require 'active_storage/service/cellar_service'
require 'cgi'
require 'net/http'
require 'uri'
describe 'CellarService' do
let(:cellar_service) do
# These are actual keys, but theyre safe to put here because
# - they never had any rights attached, and
# - the keys were revoked before copying them here
ActiveStorage::Service::CellarService.new(
access_key_id: 'AKIAJFTRSGRH3RXX6D5Q',
secret_access_key: '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',
bucket: 'rogets'
)
end
before { Timecop.freeze(Time.gm(2016, 10, 2)) }
after { Timecop.return }
describe 'presigned url for download' do
subject do
URI.parse(
cellar_service.url(
'fichier',
expires_in: 5.minutes,
filename: ActiveStorage::Filename.new("toto.png"),
disposition: 'attachment',
content_type: 'image/png'
)
)
end
it do
is_expected.to have_attributes(
scheme: 'https',
host: 'rogets.cellar.services.clever-cloud.com',
path: '/fichier'
)
end
it do
expect(CGI::parse(subject.query)).to eq(
{
'AWSAccessKeyId' => ['AKIAJFTRSGRH3RXX6D5Q'],
'Expires' => ['1475366700'],
'Signature' => ['nzCsB6cip8oofkuOdvvJs6FafkA='],
'response-content-disposition' => ["attachment; filename=\"toto.png\"; filename*=UTF-8''toto.png"],
'response-content-type' => ['image/png']
}
)
end
end
describe 'presigned url for direct upload' do
subject do
URI.parse(
cellar_service.url_for_direct_upload(
'fichier',
expires_in: 5.minutes,
content_type: 'image/png',
content_length: 2713,
checksum: 'DEADBEEF'
)
)
end
it do
is_expected.to have_attributes(
scheme: 'https',
host: 'rogets.cellar.services.clever-cloud.com',
path: '/fichier'
)
end
it do
expect(CGI::parse(subject.query)).to eq(
{
'AWSAccessKeyId' => ['AKIAJFTRSGRH3RXX6D5Q'],
'Expires' => ['1475366700'],
'Signature' => ['VwsX5nxGfTC3dxXjS6wSeU64r5o=']
}
)
end
end
end

View file

@ -1,43 +0,0 @@
require 'net/http'
describe 'AmazonV2RequestSigner' do
let(:request_signer) do
# These are actual keys, but theyre safe to put here because
# - they never had any rights attached, and
# - the keys were revoked before copying them here
Cellar::AmazonV2RequestSigner.new(
'AKIAJFTRSGRH3RXX6D5Q',
'3/y/3Tf5zkfcrTaLFxyKB/oU2/7ay7/Dz8UdEHC7',
'rogets'
)
end
before { Timecop.freeze(Time.gm(2016, 10, 2)) }
after { Timecop.return }
describe 'signature generation' do
context 'for presigned URLs' do
subject do
request_signer.signature(
method: 'GET',
key: 'fichier',
expires: 5.minutes.from_now.to_i
)
end
it { is_expected.to eq('nzCsB6cip8oofkuOdvvJs6FafkA=') }
end
context 'for server-side requests' do
subject do
Net::HTTP::Delete.new('https://rogets.cellar.services.clever-cloud.com/fichier')
end
before { request_signer.sign(subject, 'fichier') }
it { expect(subject['date']).to eq(Time.zone.now.httpdate) }
it { expect(subject['authorization']).to eq('AWS AKIAJFTRSGRH3RXX6D5Q:nkvviwZYb1V9HDrKyJZmY3Z8sSA=') }
end
end
end

View file

@ -1,89 +0,0 @@
describe 'CellarAdapter' do
let(:session) { Cellar::CellarAdapter::Session.new(nil, nil) }
before { Timecop.freeze(Time.gm(2016, 10, 2)) }
after { Timecop.return }
describe 'add_range_header' do
let(:request) { Net::HTTP::Get.new('/whatever') }
before { session.send(:add_range_header, request, range) }
subject { request['range'] }
context 'with end included' do
let(:range) { 100..500 }
it { is_expected.to eq('bytes=100-500') }
end
context 'with end excluded' do
let(:range) { 10...50 }
it { is_expected.to eq('bytes=10-49') }
end
end
describe 'parse_bucket_listing' do
let(:response) do
<<~EOS
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>example-bucket</Name>
<Prefix></Prefix>
<KeyCount>2</KeyCount>
<MaxKeys>1000</MaxKeys>
<Delimiter>/</Delimiter>
<IsTruncated>false</IsTruncated>
<Contents>
<Key>sample1.jpg</Key>
<LastModified>2011-02-26T01:56:20.000Z</LastModified>
<ETag>&quot;bf1d737a4d46a19f3bced6905cc8b902&quot;</ETag>
<Size>142863</Size>
<StorageClass>STANDARD</StorageClass>
</Contents>
<Contents>
<Key>sample2.jpg</Key>
<LastModified>2014-03-21T17:44:07.000Z</LastModified>
<ETag>&quot;bf1d737a4d46a19f3bced6905cc8b902&quot;</ETag>
<Size>142863</Size>
<StorageClass>STANDARD</StorageClass>
</Contents>
</ListBucketResult>'
EOS
end
subject { session.send(:parse_bucket_listing, response) }
it do
is_expected.to eq(
[
[
["sample1.jpg", DateTime.new(2011, 2, 26, 1, 56, 20, 0)],
["sample2.jpg", DateTime.new(2014, 3, 21, 17, 44, 7, 0)]
],
false
]
)
end
end
describe 'bulk_deletion_request_body' do
let(:expected_response) do
<<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<Delete>
<Object>
<Key>chapi</Key>
</Object>
<Object>
<Key>chapo</Key>
</Object>
</Delete>
EOS
end
subject { session.send(:bulk_deletion_request_body, ['chapi', 'chapo']) }
it { is_expected.to eq(expected_response) }
end
end