2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-23 10:33:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('config', 'object_store_settings.rb')
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe ObjectStoreSettings do
|
2020-06-17 11:08:36 -04:00
|
|
|
describe '#parse!' do
|
|
|
|
let(:settings) { Settingslogic.new(config) }
|
|
|
|
|
|
|
|
subject { described_class.new(settings).parse! }
|
|
|
|
|
|
|
|
context 'with valid config' do
|
|
|
|
let(:connection) do
|
|
|
|
{
|
|
|
|
'provider' => 'AWS',
|
|
|
|
'aws_access_key_id' => 'AWS_ACCESS_KEY_ID',
|
|
|
|
'aws_secret_access_key' => 'AWS_SECRET_ACCESS_KEY',
|
|
|
|
'region' => 'us-east-1'
|
|
|
|
}
|
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-06-17 11:08:36 -04:00
|
|
|
let(:config) do
|
|
|
|
{
|
|
|
|
'lfs' => { 'enabled' => true },
|
|
|
|
'artifacts' => { 'enabled' => true },
|
|
|
|
'external_diffs' => { 'enabled' => false },
|
2020-10-06 14:08:49 -04:00
|
|
|
'pages' => { 'enabled' => true },
|
2020-06-17 11:08:36 -04:00
|
|
|
'object_store' => {
|
|
|
|
'enabled' => true,
|
|
|
|
'connection' => connection,
|
|
|
|
'proxy_download' => true,
|
|
|
|
'objects' => {
|
|
|
|
'artifacts' => {
|
|
|
|
'bucket' => 'artifacts',
|
|
|
|
'proxy_download' => false
|
|
|
|
},
|
|
|
|
'lfs' => {
|
|
|
|
'bucket' => 'lfs-objects'
|
|
|
|
},
|
|
|
|
'external_diffs' => {
|
|
|
|
'bucket' => 'external_diffs',
|
|
|
|
'enabled' => false
|
2020-10-06 14:08:49 -04:00
|
|
|
},
|
|
|
|
'pages' => {
|
|
|
|
'bucket' => 'pages'
|
2020-06-17 11:08:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-01-29 13:09:17 -05:00
|
|
|
shared_examples 'consolidated settings for objects accelerated by Workhorse' do
|
|
|
|
it 'consolidates active object storage settings' do
|
|
|
|
described_class::WORKHORSE_ACCELERATED_TYPES.each do |object_type|
|
|
|
|
# Use to_h to avoid https://gitlab.com/gitlab-org/gitlab/-/issues/286873
|
|
|
|
section = subject.try(object_type).to_h
|
|
|
|
|
|
|
|
next unless section.dig('object_store', 'enabled')
|
|
|
|
|
|
|
|
expect(section['object_store']['connection']).to eq(connection)
|
|
|
|
expect(section['object_store']['consolidated_settings']).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-17 11:08:36 -04:00
|
|
|
it 'sets correct default values' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(settings.artifacts['enabled']).to be true
|
|
|
|
expect(settings.artifacts['object_store']['enabled']).to be true
|
|
|
|
expect(settings.artifacts['object_store']['connection']).to eq(connection)
|
|
|
|
expect(settings.artifacts['object_store']['direct_upload']).to be true
|
|
|
|
expect(settings.artifacts['object_store']['background_upload']).to be false
|
|
|
|
expect(settings.artifacts['object_store']['proxy_download']).to be false
|
|
|
|
expect(settings.artifacts['object_store']['remote_directory']).to eq('artifacts')
|
2022-07-01 08:08:08 -04:00
|
|
|
expect(settings.artifacts['object_store']['bucket_prefix']).to eq(nil)
|
2020-11-19 19:09:06 -05:00
|
|
|
expect(settings.artifacts['object_store']['consolidated_settings']).to be true
|
2021-04-29 11:10:07 -04:00
|
|
|
expect(settings.artifacts).to eq(settings['artifacts'])
|
2020-06-17 11:08:36 -04:00
|
|
|
|
|
|
|
expect(settings.lfs['enabled']).to be true
|
|
|
|
expect(settings.lfs['object_store']['enabled']).to be true
|
|
|
|
expect(settings.lfs['object_store']['connection']).to eq(connection)
|
|
|
|
expect(settings.lfs['object_store']['direct_upload']).to be true
|
|
|
|
expect(settings.lfs['object_store']['background_upload']).to be false
|
|
|
|
expect(settings.lfs['object_store']['proxy_download']).to be true
|
|
|
|
expect(settings.lfs['object_store']['remote_directory']).to eq('lfs-objects')
|
2022-07-01 08:08:08 -04:00
|
|
|
expect(settings.lfs['object_store']['bucket_prefix']).to eq(nil)
|
2020-11-19 19:09:06 -05:00
|
|
|
expect(settings.lfs['object_store']['consolidated_settings']).to be true
|
2021-04-29 11:10:07 -04:00
|
|
|
expect(settings.lfs).to eq(settings['lfs'])
|
2020-06-17 11:08:36 -04:00
|
|
|
|
2020-10-06 14:08:49 -04:00
|
|
|
expect(settings.pages['enabled']).to be true
|
|
|
|
expect(settings.pages['object_store']['enabled']).to be true
|
|
|
|
expect(settings.pages['object_store']['connection']).to eq(connection)
|
|
|
|
expect(settings.pages['object_store']['remote_directory']).to eq('pages')
|
2022-07-01 08:08:08 -04:00
|
|
|
expect(settings.pages['object_store']['bucket_prefix']).to eq(nil)
|
2020-11-19 19:09:06 -05:00
|
|
|
expect(settings.pages['object_store']['consolidated_settings']).to be true
|
2021-04-29 11:10:07 -04:00
|
|
|
expect(settings.pages).to eq(settings['pages'])
|
2020-10-06 14:08:49 -04:00
|
|
|
|
2020-06-17 11:08:36 -04:00
|
|
|
expect(settings.external_diffs['enabled']).to be false
|
2021-01-29 13:09:17 -05:00
|
|
|
expect(settings.external_diffs['object_store']).to be_nil
|
2021-04-29 11:10:07 -04:00
|
|
|
expect(settings.external_diffs).to eq(settings['external_diffs'])
|
2020-06-17 11:08:36 -04:00
|
|
|
end
|
|
|
|
|
2022-07-01 08:08:08 -04:00
|
|
|
it 'supports bucket prefixes' do
|
|
|
|
config['object_store']['objects']['artifacts']['bucket'] = 'gitlab/artifacts'
|
|
|
|
config['object_store']['objects']['lfs']['bucket'] = 'gitlab/lfs'
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(settings.artifacts['object_store']['remote_directory']).to eq('gitlab')
|
|
|
|
expect(settings.artifacts['object_store']['bucket_prefix']).to eq('artifacts')
|
|
|
|
expect(settings.lfs['object_store']['remote_directory']).to eq('gitlab')
|
|
|
|
expect(settings.lfs['object_store']['bucket_prefix']).to eq('lfs')
|
|
|
|
end
|
|
|
|
|
2020-06-17 11:08:36 -04:00
|
|
|
it 'raises an error when a bucket is missing' do
|
|
|
|
config['object_store']['objects']['lfs'].delete('bucket')
|
|
|
|
|
|
|
|
expect { subject }.to raise_error(/Object storage for lfs must have a bucket specified/)
|
|
|
|
end
|
|
|
|
|
2020-10-06 14:08:49 -04:00
|
|
|
it 'does not raise error if pages bucket is missing' do
|
|
|
|
config['object_store']['objects']['pages'].delete('bucket')
|
|
|
|
|
|
|
|
expect { subject }.not_to raise_error
|
2020-12-04 16:09:29 -05:00
|
|
|
expect(settings.pages['object_store']).to eq(nil)
|
2020-10-06 14:08:49 -04:00
|
|
|
end
|
|
|
|
|
2021-01-29 13:09:17 -05:00
|
|
|
context 'GitLab Pages' do
|
|
|
|
let(:pages_connection) { { 'provider' => 'Google', 'google_application_default' => true } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
config['pages'] = {
|
2020-11-19 19:09:06 -05:00
|
|
|
'enabled' => true,
|
2021-01-29 13:09:17 -05:00
|
|
|
'object_store' => {
|
|
|
|
'enabled' => true,
|
|
|
|
'connection' => pages_connection
|
|
|
|
}
|
2020-11-19 19:09:06 -05:00
|
|
|
}
|
2021-01-29 13:09:17 -05:00
|
|
|
end
|
2020-11-19 19:09:06 -05:00
|
|
|
|
2021-01-29 13:09:17 -05:00
|
|
|
it_behaves_like 'consolidated settings for objects accelerated by Workhorse'
|
2020-11-19 19:09:06 -05:00
|
|
|
|
2021-01-29 13:09:17 -05:00
|
|
|
it 'allows pages to define its own connection' do
|
|
|
|
expect { subject }.not_to raise_error
|
2020-11-19 19:09:06 -05:00
|
|
|
|
2021-01-29 13:09:17 -05:00
|
|
|
expect(settings.pages['object_store']['connection']).to eq(pages_connection)
|
|
|
|
expect(settings.pages['object_store']['consolidated_settings']).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
2020-11-19 19:09:06 -05:00
|
|
|
|
2021-02-03 13:09:25 -05:00
|
|
|
context 'when object storage is disabled for artifacts with no bucket' do
|
2021-01-29 13:09:17 -05:00
|
|
|
before do
|
|
|
|
config['artifacts'] = {
|
|
|
|
'enabled' => true,
|
2021-02-03 13:09:25 -05:00
|
|
|
'object_store' => {}
|
|
|
|
}
|
|
|
|
config['object_store']['objects']['artifacts'] = {
|
|
|
|
'enabled' => false
|
2021-01-29 13:09:17 -05:00
|
|
|
}
|
2020-11-19 19:09:06 -05:00
|
|
|
end
|
|
|
|
|
2021-01-29 13:09:17 -05:00
|
|
|
it_behaves_like 'consolidated settings for objects accelerated by Workhorse'
|
|
|
|
|
|
|
|
it 'does not enable consolidated settings for artifacts' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(settings.artifacts['enabled']).to be true
|
|
|
|
expect(settings.artifacts['object_store']['remote_directory']).to be_nil
|
2022-07-01 08:08:08 -04:00
|
|
|
expect(settings.artifacts['object_store']['bucket_prefix']).to be_nil
|
2021-01-29 13:09:17 -05:00
|
|
|
expect(settings.artifacts['object_store']['enabled']).to be_falsey
|
|
|
|
expect(settings.artifacts['object_store']['consolidated_settings']).to be_falsey
|
|
|
|
end
|
2020-11-19 19:09:06 -05:00
|
|
|
end
|
|
|
|
|
2020-06-17 11:08:36 -04:00
|
|
|
context 'with legacy config' do
|
|
|
|
let(:legacy_settings) do
|
|
|
|
{
|
|
|
|
'enabled' => true,
|
|
|
|
'remote_directory' => 'some-bucket',
|
2022-05-09 17:07:53 -04:00
|
|
|
'direct_upload' => false,
|
|
|
|
'background_upload' => true,
|
2020-06-17 11:08:36 -04:00
|
|
|
'proxy_download' => false
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2022-05-09 17:07:53 -04:00
|
|
|
settings.lfs['object_store'] = described_class.legacy_parse(legacy_settings, 'lfs')
|
2020-06-17 11:08:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not alter config if legacy settings are specified' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(settings.artifacts['object_store']).to be_nil
|
|
|
|
expect(settings.lfs['object_store']['remote_directory']).to eq('some-bucket')
|
2022-07-01 08:08:08 -04:00
|
|
|
expect(settings.lfs['object_store']['bucket_prefix']).to eq(nil)
|
2022-05-09 17:07:53 -04:00
|
|
|
# Disable background_upload, regardless of the input config
|
|
|
|
expect(settings.lfs['object_store']['direct_upload']).to eq(true)
|
|
|
|
expect(settings.lfs['object_store']['background_upload']).to eq(false)
|
|
|
|
expect(settings.external_diffs['object_store']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with legacy config and legacy background upload is enabled' do
|
|
|
|
let(:legacy_settings) do
|
|
|
|
{
|
|
|
|
'enabled' => true,
|
|
|
|
'remote_directory' => 'some-bucket',
|
|
|
|
'proxy_download' => false
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_env(ObjectStoreSettings::LEGACY_BACKGROUND_UPLOADS_ENV, 'lfs')
|
|
|
|
settings.lfs['object_store'] = described_class.legacy_parse(legacy_settings, 'lfs')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'enables background_upload and disables direct_upload' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(settings.artifacts['object_store']).to be_nil
|
|
|
|
expect(settings.lfs['object_store']['remote_directory']).to eq('some-bucket')
|
2022-07-01 08:08:08 -04:00
|
|
|
expect(settings.lfs['object_store']['bucket_prefix']).to eq(nil)
|
2022-05-09 17:07:53 -04:00
|
|
|
# Enable background_upload if the environment variable is available
|
|
|
|
expect(settings.lfs['object_store']['direct_upload']).to eq(false)
|
|
|
|
expect(settings.lfs['object_store']['background_upload']).to eq(true)
|
2020-06-17 11:08:36 -04:00
|
|
|
expect(settings.external_diffs['object_store']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.legacy_parse' do
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'sets correct default values' do
|
2022-05-09 17:07:53 -04:00
|
|
|
settings = described_class.legacy_parse(nil, 'artifacts')
|
2018-07-23 10:33:06 -04:00
|
|
|
|
|
|
|
expect(settings['enabled']).to be false
|
2022-05-09 17:07:53 -04:00
|
|
|
expect(settings['direct_upload']).to be true
|
|
|
|
expect(settings['background_upload']).to be false
|
2018-07-23 10:33:06 -04:00
|
|
|
expect(settings['remote_directory']).to be nil
|
2022-07-01 08:08:08 -04:00
|
|
|
expect(settings['bucket_prefix']).to be nil
|
2018-07-23 10:33:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'respects original values' do
|
|
|
|
original_settings = Settingslogic.new({
|
|
|
|
'enabled' => true,
|
|
|
|
'remote_directory' => 'artifacts'
|
|
|
|
})
|
|
|
|
|
2022-05-09 17:07:53 -04:00
|
|
|
settings = described_class.legacy_parse(original_settings, 'artifacts')
|
2018-07-23 10:33:06 -04:00
|
|
|
|
|
|
|
expect(settings['enabled']).to be true
|
2022-05-09 17:07:53 -04:00
|
|
|
expect(settings['direct_upload']).to be true
|
|
|
|
expect(settings['background_upload']).to be false
|
2018-07-23 10:33:06 -04:00
|
|
|
expect(settings['remote_directory']).to eq 'artifacts'
|
2022-07-01 08:08:08 -04:00
|
|
|
expect(settings['bucket_prefix']).to be nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'supports bucket prefixes' do
|
|
|
|
original_settings = Settingslogic.new({
|
|
|
|
'enabled' => true,
|
|
|
|
'remote_directory' => 'gitlab/artifacts'
|
|
|
|
})
|
|
|
|
|
|
|
|
settings = described_class.legacy_parse(original_settings, 'artifacts')
|
|
|
|
expect(settings['remote_directory']).to eq 'gitlab'
|
|
|
|
expect(settings['bucket_prefix']).to eq 'artifacts'
|
2018-07-23 10:33:06 -04:00
|
|
|
end
|
2022-05-09 17:07:53 -04:00
|
|
|
|
|
|
|
context 'legacy background upload environment variable is enabled' do
|
|
|
|
before do
|
|
|
|
stub_env(ObjectStoreSettings::LEGACY_BACKGROUND_UPLOADS_ENV, 'artifacts,lfs')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'enables background_upload and disables direct_upload' do
|
|
|
|
original_settings = Settingslogic.new({
|
|
|
|
'enabled' => true,
|
|
|
|
'remote_directory' => 'artifacts'
|
|
|
|
})
|
|
|
|
|
|
|
|
settings = described_class.legacy_parse(original_settings, 'artifacts')
|
|
|
|
|
|
|
|
expect(settings['enabled']).to be true
|
|
|
|
expect(settings['direct_upload']).to be false
|
|
|
|
expect(settings['background_upload']).to be true
|
|
|
|
expect(settings['remote_directory']).to eq 'artifacts'
|
2022-07-01 08:08:08 -04:00
|
|
|
expect(settings['bucket_prefix']).to eq nil
|
2022-05-09 17:07:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'legacy background upload environment variable is enabled for other types' do
|
|
|
|
before do
|
|
|
|
stub_env(ObjectStoreSettings::LEGACY_BACKGROUND_UPLOADS_ENV, 'uploads,lfs')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'enables direct_upload and disables background_upload' do
|
|
|
|
original_settings = Settingslogic.new({
|
|
|
|
'enabled' => true,
|
|
|
|
'remote_directory' => 'artifacts'
|
|
|
|
})
|
|
|
|
|
|
|
|
settings = described_class.legacy_parse(original_settings, 'artifacts')
|
|
|
|
|
|
|
|
expect(settings['enabled']).to be true
|
|
|
|
expect(settings['direct_upload']).to be true
|
|
|
|
expect(settings['background_upload']).to be false
|
|
|
|
expect(settings['remote_directory']).to eq 'artifacts'
|
2022-07-01 08:08:08 -04:00
|
|
|
expect(settings['bucket_prefix']).to eq nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.split_bucket_prefix' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
subject { described_class.split_bucket_prefix(input) }
|
|
|
|
|
|
|
|
context 'valid inputs' do
|
|
|
|
where(:input, :bucket, :prefix) do
|
|
|
|
nil | nil | nil
|
|
|
|
'' | nil | nil
|
|
|
|
'bucket' | 'bucket' | nil
|
|
|
|
'bucket/prefix' | 'bucket' | 'prefix'
|
|
|
|
'bucket/pre/fix' | 'bucket' | 'pre/fix'
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it { expect(subject).to eq([bucket, prefix]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'invalid inputs' do
|
|
|
|
where(:input) do
|
|
|
|
[
|
|
|
|
['bucket/'],
|
|
|
|
['bucket/.'],
|
|
|
|
['bucket/..'],
|
|
|
|
['bucket/prefix/'],
|
|
|
|
['bucket/prefix/.'],
|
|
|
|
['bucket/prefix/..'],
|
|
|
|
['/bucket/prefix'],
|
|
|
|
['./bucket/prefix'],
|
|
|
|
['../bucket/prefix'],
|
|
|
|
['bucket//prefix'],
|
|
|
|
['bucket/./prefix'],
|
|
|
|
['bucket/../prefix']
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it { expect { subject }.to raise_error(/invalid bucket/) }
|
2022-05-09 17:07:53 -04:00
|
|
|
end
|
|
|
|
end
|
2018-07-23 10:33:06 -04:00
|
|
|
end
|
|
|
|
end
|