2020-08-05 05:10:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-02-22 22:10:56 -05:00
|
|
|
require 'fast_spec_helper'
|
2020-08-19 23:10:04 -04:00
|
|
|
require 'rspec-parameterized'
|
2021-02-22 22:10:56 -05:00
|
|
|
require 'fog/core'
|
2020-08-05 05:10:01 -04:00
|
|
|
|
|
|
|
RSpec.describe ObjectStorage::Config do
|
2020-08-19 23:10:04 -04:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
let(:region) { 'us-east-1' }
|
|
|
|
let(:bucket_name) { 'test-bucket' }
|
|
|
|
let(:credentials) do
|
|
|
|
{
|
|
|
|
provider: 'AWS',
|
|
|
|
aws_access_key_id: 'AWS_ACCESS_KEY_ID',
|
|
|
|
aws_secret_access_key: 'AWS_SECRET_ACCESS_KEY',
|
2020-08-19 23:10:04 -04:00
|
|
|
region: region
|
2020-08-05 05:10:01 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:storage_options) do
|
|
|
|
{
|
|
|
|
server_side_encryption: 'AES256',
|
|
|
|
server_side_encryption_kms_key_id: 'arn:aws:12345'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:raw_config) do
|
|
|
|
{
|
|
|
|
enabled: true,
|
|
|
|
connection: credentials,
|
|
|
|
remote_directory: bucket_name,
|
|
|
|
storage_options: storage_options
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-02-22 22:10:56 -05:00
|
|
|
subject { described_class.new(raw_config.as_json) }
|
2020-08-05 05:10:01 -04:00
|
|
|
|
|
|
|
describe '#credentials' do
|
|
|
|
it { expect(subject.credentials).to eq(credentials) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#storage_options' do
|
|
|
|
it { expect(subject.storage_options).to eq(storage_options) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#enabled?' do
|
|
|
|
it { expect(subject.enabled?).to eq(true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#bucket' do
|
|
|
|
it { expect(subject.bucket).to eq(bucket_name) }
|
|
|
|
end
|
|
|
|
|
2020-08-19 23:10:04 -04:00
|
|
|
describe '#use_iam_profile' do
|
|
|
|
it { expect(subject.use_iam_profile?).to be false }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#use_path_style' do
|
|
|
|
it { expect(subject.use_path_style?).to be false }
|
|
|
|
end
|
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'with unconsolidated settings' do
|
|
|
|
describe 'consolidated_settings? returns false' do
|
|
|
|
it { expect(subject.consolidated_settings?).to be false }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with consolidated settings' do
|
|
|
|
before do
|
|
|
|
raw_config[:consolidated_settings] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'consolidated_settings? returns true' do
|
|
|
|
it { expect(subject.consolidated_settings?).to be true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-19 23:10:04 -04:00
|
|
|
context 'with IAM profile configured' do
|
|
|
|
where(:value, :expected) do
|
|
|
|
true | true
|
|
|
|
"true" | true
|
|
|
|
"yes" | true
|
|
|
|
false | false
|
|
|
|
"false" | false
|
|
|
|
"no" | false
|
|
|
|
nil | false
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
credentials[:use_iam_profile] = value
|
|
|
|
end
|
2020-08-05 05:10:01 -04:00
|
|
|
|
2020-08-19 23:10:04 -04:00
|
|
|
it 'coerces the value to a boolean' do
|
|
|
|
expect(subject.use_iam_profile?).to be expected
|
|
|
|
end
|
2020-08-05 05:10:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-19 23:10:04 -04:00
|
|
|
context 'with path style configured' do
|
|
|
|
where(:value, :expected) do
|
|
|
|
true | true
|
|
|
|
"true" | true
|
|
|
|
"yes" | true
|
|
|
|
false | false
|
|
|
|
"false" | false
|
|
|
|
"no" | false
|
|
|
|
nil | false
|
2020-08-05 05:10:01 -04:00
|
|
|
end
|
|
|
|
|
2020-08-19 23:10:04 -04:00
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
credentials[:path_style] = value
|
|
|
|
end
|
2020-08-05 05:10:01 -04:00
|
|
|
|
2020-08-19 23:10:04 -04:00
|
|
|
it 'coerces the value to a boolean' do
|
|
|
|
expect(subject.use_path_style?).to be expected
|
|
|
|
end
|
2020-08-05 05:10:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with hostname style access' do
|
|
|
|
it '#use_path_style? returns false' do
|
|
|
|
expect(subject.use_path_style?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with AWS credentials' do
|
|
|
|
it { expect(subject.provider).to eq('AWS') }
|
|
|
|
it { expect(subject.aws?).to be true }
|
|
|
|
it { expect(subject.google?).to be false }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with Google credentials' do
|
|
|
|
let(:credentials) do
|
|
|
|
{
|
|
|
|
provider: 'Google',
|
|
|
|
google_client_email: 'foo@gcp-project.example.com',
|
|
|
|
google_json_key_location: '/path/to/gcp.json'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.provider).to eq('Google') }
|
|
|
|
it { expect(subject.aws?).to be false }
|
|
|
|
it { expect(subject.google?).to be true }
|
|
|
|
it { expect(subject.fog_attributes).to eq({}) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with SSE-KMS enabled' do
|
2021-08-31 17:10:43 -04:00
|
|
|
it { expect(subject.aws_server_side_encryption_enabled?).to be true }
|
2020-08-05 05:10:01 -04:00
|
|
|
it { expect(subject.server_side_encryption).to eq('AES256') }
|
|
|
|
it { expect(subject.server_side_encryption_kms_key_id).to eq('arn:aws:12345') }
|
|
|
|
it { expect(subject.fog_attributes.keys).to match_array(%w(x-amz-server-side-encryption x-amz-server-side-encryption-aws-kms-key-id)) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with only server side encryption enabled' do
|
|
|
|
let(:storage_options) { { server_side_encryption: 'AES256' } }
|
|
|
|
|
2021-08-31 17:10:43 -04:00
|
|
|
it { expect(subject.aws_server_side_encryption_enabled?).to be true }
|
2020-08-05 05:10:01 -04:00
|
|
|
it { expect(subject.server_side_encryption).to eq('AES256') }
|
|
|
|
it { expect(subject.server_side_encryption_kms_key_id).to be_nil }
|
|
|
|
it { expect(subject.fog_attributes).to eq({ 'x-amz-server-side-encryption' => 'AES256' }) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without encryption enabled' do
|
|
|
|
let(:storage_options) { {} }
|
|
|
|
|
2021-08-31 17:10:43 -04:00
|
|
|
it { expect(subject.aws_server_side_encryption_enabled?).to be false }
|
2020-08-05 05:10:01 -04:00
|
|
|
it { expect(subject.server_side_encryption).to be_nil }
|
|
|
|
it { expect(subject.server_side_encryption_kms_key_id).to be_nil }
|
|
|
|
it { expect(subject.fog_attributes).to eq({}) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with object storage disabled' do
|
|
|
|
before do
|
|
|
|
raw_config['enabled'] = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.enabled?).to be false }
|
|
|
|
end
|
|
|
|
end
|