diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/controllers/projects/artifacts_controller_spec.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/controllers/projects/artifacts_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/artifacts_controller_spec.rb | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/spec/controllers/projects/artifacts_controller_spec.rb b/spec/controllers/projects/artifacts_controller_spec.rb index c59983d5138..be616b566dd 100644 --- a/spec/controllers/projects/artifacts_controller_spec.rb +++ b/spec/controllers/projects/artifacts_controller_spec.rb @@ -308,10 +308,13 @@ describe Projects::ArtifactsController do end describe 'GET raw' do - subject { get(:raw, params: { namespace_id: project.namespace, project_id: project, job_id: job, path: path }) } + let(:query_params) { { namespace_id: project.namespace, project_id: project, job_id: job, path: path } } + + subject { get(:raw, params: query_params) } context 'when the file exists' do let(:path) { 'ci_artifacts.txt' } + let(:archive_matcher) { /build_artifacts.zip(\?[^?]+)?$/ } shared_examples 'a valid file' do it 'serves the file using workhorse' do @@ -323,8 +326,8 @@ describe Projects::ArtifactsController do expect(params.keys).to eq(%w(Archive Entry)) expect(params['Archive']).to start_with(archive_path) # On object storage, the URL can end with a query string - expect(params['Archive']).to match(/build_artifacts.zip(\?[^?]+)?$/) - expect(params['Entry']).to eq(Base64.encode64('ci_artifacts.txt')) + expect(params['Archive']).to match(archive_matcher) + expect(params['Entry']).to eq(Base64.encode64(path)) end def send_data @@ -334,7 +337,7 @@ describe Projects::ArtifactsController do def params @params ||= begin base64_params = send_data.sub(/\Aartifacts\-entry:/, '') - JSON.parse(Base64.urlsafe_decode64(base64_params)) + Gitlab::Json.parse(Base64.urlsafe_decode64(base64_params)) end end end @@ -359,6 +362,37 @@ describe Projects::ArtifactsController do let(:archive_path) { 'https://' } end end + + context 'fetching an artifact of different type' do + before do + job.job_artifacts.each(&:destroy) + end + + context 'when the artifact is zip' do + let!(:artifact) { create(:ci_job_artifact, :lsif, job: job, file_path: Rails.root.join("spec/fixtures/#{file_name}")) } + let(:path) { 'lsif/main.go.json' } + let(:file_name) { 'lsif.json.zip' } + let(:archive_matcher) { file_name } + let(:query_params) { super().merge(file_type: :lsif, path: path) } + + it_behaves_like 'a valid file' do + let(:store) { ObjectStorage::Store::LOCAL } + let(:archive_path) { JobArtifactUploader.root } + end + end + + context 'when the artifact is not zip' do + let(:query_params) { super().merge(file_type: :junit, path: '') } + + it 'responds with not found' do + create(:ci_job_artifact, :junit, job: job) + + subject + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end end end |