diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 15:11:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 15:11:03 +0300 |
commit | 027f19b39c73b3b98e7cf305fead871626e8b717 (patch) | |
tree | d97ff241c76a5655f8f58444ccf76695b1b89bcf /spec/lib/api | |
parent | a7b422860c90eecd1b98845d234a8347686fbdcf (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/api')
-rw-r--r-- | spec/lib/api/helpers/packages_helpers_spec.rb | 20 | ||||
-rw-r--r-- | spec/lib/api/helpers_spec.rb | 52 |
2 files changed, 52 insertions, 20 deletions
diff --git a/spec/lib/api/helpers/packages_helpers_spec.rb b/spec/lib/api/helpers/packages_helpers_spec.rb index cd6e718ce98..d764ed4afff 100644 --- a/spec/lib/api/helpers/packages_helpers_spec.rb +++ b/spec/lib/api/helpers/packages_helpers_spec.rb @@ -35,26 +35,6 @@ RSpec.describe API::Helpers::PackagesHelpers do expect(helper.send('authorize_read_package!', subject)).to eq nil end end - - context 'with feature flag disabled' do - before do - stub_feature_flags(read_package_policy_rule: false) - end - - where(:subject, :expected_class) do - ref(:project) | ::Project - ref(:group) | ::Group - ref(:package) | ::Packages::Package - end - - with_them do - it 'calls authorize! with correct subject' do - expect(helper).to receive(:authorize!).with(:read_package, have_attributes(id: subject.id, class: expected_class)) - - expect(helper.send('authorize_read_package!', subject)).to eq nil - end - end - end end %i[create_package destroy_package].each do |action| diff --git a/spec/lib/api/helpers_spec.rb b/spec/lib/api/helpers_spec.rb index f25c75ef93c..3ea42c29ce2 100644 --- a/spec/lib/api/helpers_spec.rb +++ b/spec/lib/api/helpers_spec.rb @@ -773,6 +773,58 @@ RSpec.describe API::Helpers do end end + describe '#present_artifacts_file!' do + context 'with object storage' do + let(:artifact) { create(:ci_job_artifact, :zip, :remote_store) } + + subject { helper.present_artifacts_file!(artifact.file, project: artifact.job.project) } + + before do + allow(helper).to receive(:env).and_return({}) + + stub_artifacts_object_storage(enabled: true) + end + + it 'redirects to a CDN-fronted URL' do + expect(helper).to receive(:redirect) + expect(helper).to receive(:cdn_fronted_url).and_call_original + expect(Gitlab::ApplicationContext).to receive(:push).with(artifact: artifact.file.model).and_call_original + expect(Gitlab::ApplicationContext).to receive(:push).with(artifact_used_cdn: false).and_call_original + + subject + end + end + end + + describe '#cdn_frontend_url' do + before do + allow(helper).to receive(:env).and_return({}) + + stub_artifacts_object_storage(enabled: true) + end + + context 'with a CI artifact' do + let(:artifact) { create(:ci_job_artifact, :zip, :remote_store) } + + it 'retrieves a CDN-fronted URL' do + expect(artifact.file).to receive(:cdn_enabled_url).and_call_original + expect(Gitlab::ApplicationContext).to receive(:push).with(artifact_used_cdn: false).and_call_original + expect(helper.cdn_fronted_url(artifact.file, artifact.job.project)).to be_a(String) + end + end + + context 'with a file upload' do + let(:url) { 'https://example.com/path/to/upload' } + + it 'retrieves the file URL' do + file = double(url: url) + + expect(Gitlab::ApplicationContext).not_to receive(:push) + expect(helper.cdn_fronted_url(file, nil)).to eq(url) + end + end + end + describe '#order_by_similarity?' do where(:params, :allow_unauthorized, :current_user_set, :expected) do {} | false | false | false |