diff options
Diffstat (limited to 'spec/uploaders')
-rw-r--r-- | spec/uploaders/ci/pipeline_artifact_uploader_spec.rb | 39 | ||||
-rw-r--r-- | spec/uploaders/file_mover_spec.rb | 1 | ||||
-rw-r--r-- | spec/uploaders/object_storage_spec.rb | 71 | ||||
-rw-r--r-- | spec/uploaders/packages/package_file_uploader_spec.rb | 4 |
4 files changed, 97 insertions, 18 deletions
diff --git a/spec/uploaders/ci/pipeline_artifact_uploader_spec.rb b/spec/uploaders/ci/pipeline_artifact_uploader_spec.rb new file mode 100644 index 00000000000..0630e9f6546 --- /dev/null +++ b/spec/uploaders/ci/pipeline_artifact_uploader_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::PipelineArtifactUploader do + let(:pipeline_artifact) { create(:ci_pipeline_artifact) } + let(:uploader) { described_class.new(pipeline_artifact, :file) } + + subject { uploader } + + it_behaves_like "builds correct paths", + store_dir: %r[\h{2}/\h{2}/\h{64}/pipelines/\d+/artifacts/\d+], + cache_dir: %r[artifacts/tmp/cache], + work_dir: %r[artifacts/tmp/work] + + context 'when object store is REMOTE' do + before do + stub_artifacts_object_storage(described_class) + end + + include_context 'with storage', described_class::Store::REMOTE + + it_behaves_like 'builds correct paths', store_dir: %r[\h{2}/\h{2}/\h{64}/pipelines/\d+/artifacts/\d+] + end + + context 'when file is stored in valid local_path' do + let(:file) do + fixture_file_upload('spec/fixtures/pipeline_artifacts/code_coverage.json', 'application/json') + end + + before do + uploader.store!(file) + end + + subject { uploader.file.path } + + it { is_expected.to match(%r[#{uploader.root}/#{uploader.class.base_dir}\h{2}/\h{2}/\h{64}/pipelines/#{pipeline_artifact.pipeline_id}/artifacts/#{pipeline_artifact.id}/code_coverage.json]) } + end +end diff --git a/spec/uploaders/file_mover_spec.rb b/spec/uploaders/file_mover_spec.rb index 0f7496f17d5..3b8c6f6f881 100644 --- a/spec/uploaders/file_mover_spec.rb +++ b/spec/uploaders/file_mover_spec.rb @@ -14,6 +14,7 @@ RSpec.describe FileMover do "test ![banana_sample](/#{temp_file_path}) "\ "same ![banana_sample](/#{temp_file_path}) " end + let(:file_path) { File.join('uploads/-/system/personal_snippet', snippet.id.to_s, secret, filename) } let(:snippet) { create(:personal_snippet, description: temp_description) } diff --git a/spec/uploaders/object_storage_spec.rb b/spec/uploaders/object_storage_spec.rb index 694aafe5ed5..12c936e154b 100644 --- a/spec/uploaders/object_storage_spec.rb +++ b/spec/uploaders/object_storage_spec.rb @@ -382,6 +382,32 @@ RSpec.describe ObjectStorage do it { is_expected.to eq(nil) } end + describe '#fog_attributes' do + subject { uploader.fog_attributes } + + it { is_expected.to eq({}) } + + context 'with encryption configured' do + let(:raw_options) do + { + "enabled" => true, + "connection" => { "provider" => 'AWS' }, + "storage_options" => { "server_side_encryption" => "AES256" } + } + end + + let(:options) { Settingslogic.new(raw_options) } + + before do + allow(uploader_class).to receive(:options) do + double(object_store: options) + end + end + + it { is_expected.to eq({ "x-amz-server-side-encryption" => "AES256" }) } + end + end + describe '.workhorse_authorize' do let(:has_length) { true } let(:maximum_size) { nil } @@ -459,13 +485,18 @@ RSpec.describe ObjectStorage do context 'uses AWS' do let(:storage_url) { "https://uploads.s3-eu-central-1.amazonaws.com/" } + let(:credentials) do + { + provider: "AWS", + aws_access_key_id: "AWS_ACCESS_KEY_ID", + aws_secret_access_key: "AWS_SECRET_ACCESS_KEY", + region: "eu-central-1" + } + end before do - expect(uploader_class).to receive(:object_store_credentials) do - { provider: "AWS", - aws_access_key_id: "AWS_ACCESS_KEY_ID", - aws_secret_access_key: "AWS_SECRET_ACCESS_KEY", - region: "eu-central-1" } + expect_next_instance_of(ObjectStorage::Config) do |instance| + allow(instance).to receive(:credentials).and_return(credentials) end end @@ -502,12 +533,17 @@ RSpec.describe ObjectStorage do context 'uses Google' do let(:storage_url) { "https://storage.googleapis.com/uploads/" } + let(:credentials) do + { + provider: "Google", + google_storage_access_key_id: 'ACCESS_KEY_ID', + google_storage_secret_access_key: 'SECRET_ACCESS_KEY' + } + end before do - expect(uploader_class).to receive(:object_store_credentials) do - { provider: "Google", - google_storage_access_key_id: 'ACCESS_KEY_ID', - google_storage_secret_access_key: 'SECRET_ACCESS_KEY' } + expect_next_instance_of(ObjectStorage::Config) do |instance| + allow(instance).to receive(:credentials).and_return(credentials) end end @@ -537,15 +573,18 @@ RSpec.describe ObjectStorage do context 'uses GDK/minio' do let(:storage_url) { "http://minio:9000/uploads/" } + let(:credentials) do + { provider: "AWS", + aws_access_key_id: "AWS_ACCESS_KEY_ID", + aws_secret_access_key: "AWS_SECRET_ACCESS_KEY", + endpoint: 'http://minio:9000', + path_style: true, + region: "gdk" } + end before do - expect(uploader_class).to receive(:object_store_credentials) do - { provider: "AWS", - aws_access_key_id: "AWS_ACCESS_KEY_ID", - aws_secret_access_key: "AWS_SECRET_ACCESS_KEY", - endpoint: 'http://minio:9000', - path_style: true, - region: "gdk" } + expect_next_instance_of(ObjectStorage::Config) do |instance| + allow(instance).to receive(:credentials).and_return(credentials) end end diff --git a/spec/uploaders/packages/package_file_uploader_spec.rb b/spec/uploaders/packages/package_file_uploader_spec.rb index 1fe65649d7a..f4e72892c8f 100644 --- a/spec/uploaders/packages/package_file_uploader_spec.rb +++ b/spec/uploaders/packages/package_file_uploader_spec.rb @@ -15,7 +15,7 @@ RSpec.describe Packages::PackageFileUploader do context 'object store is remote' do before do - stub_packages_object_storage + stub_package_file_object_storage end include_context 'with storage', described_class::Store::REMOTE @@ -29,7 +29,7 @@ RSpec.describe Packages::PackageFileUploader do context 'with object storage enabled' do before do - stub_packages_object_storage + stub_package_file_object_storage end it 'can store file remotely' do |