diff options
author | GitLab Release Tools Bot <delivery-team+release-tools@gitlab.com> | 2023-10-31 17:30:35 +0300 |
---|---|---|
committer | GitLab Release Tools Bot <delivery-team+release-tools@gitlab.com> | 2023-10-31 17:30:35 +0300 |
commit | ec770ec0d801782fb39cf52c01710bf347d70e3a (patch) | |
tree | e3be576199894d84efe9e0598e82633712c19c91 /spec | |
parent | 9de3f08bc2d59576d74162ebfd16543f7b40c696 (diff) | |
parent | abc892a30ec014fc8b13d0280aa2bdb15ac93d9d (diff) |
Merge remote-tracking branch 'dev/16-3-stable' into 16-3-stable
Diffstat (limited to 'spec')
-rw-r--r-- | spec/helpers/version_check_helper_spec.rb | 52 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/components/instance_path_spec.rb | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/jwt_spec.rb | 19 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/command_line_util_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/search/abuse_detection_spec.rb | 28 | ||||
-rw-r--r-- | spec/lib/gitlab/search/params_spec.rb | 18 | ||||
-rw-r--r-- | spec/mailers/emails/service_desk_spec.rb | 22 |
7 files changed, 130 insertions, 39 deletions
diff --git a/spec/helpers/version_check_helper_spec.rb b/spec/helpers/version_check_helper_spec.rb index ce5aade2b1c..9c697dbe21e 100644 --- a/spec/helpers/version_check_helper_spec.rb +++ b/spec/helpers/version_check_helper_spec.rb @@ -38,43 +38,49 @@ RSpec.describe VersionCheckHelper do end describe '#gitlab_version_check' do + let(:show_version_check) { false } + before do - allow_next_instance_of(VersionCheck) do |instance| - allow(instance).to receive(:response).and_return({ "severity" => "success" }) - end + allow(helper).to receive(:show_version_check?).and_return(show_version_check) end - it 'returns an instance of the VersionCheck class' do - expect(helper.gitlab_version_check).to eq({ "severity" => "success" }) + it 'when show_version_check? is false it returns nil' do + expect(helper.gitlab_version_check).to be nil + end + + context 'when show_version_check? is true' do + let(:show_version_check) { true } + + before do + allow_next_instance_of(VersionCheck) do |instance| + allow(instance).to receive(:response).and_return({ "severity" => "success" }) + end + end + + it 'returns an instance of the VersionCheck class if the user has access' do + expect(helper.gitlab_version_check).to eq({ "severity" => "success" }) + end end end describe '#show_security_patch_upgrade_alert?' do describe 'return conditions' do - where(:show_version_check, :gitlab_version_check, :result) do + where(:gitlab_version_check, :result) do [ - [false, nil, false], - [false, { "severity" => "success" }, false], - [false, { "severity" => "danger" }, false], - [false, { "severity" => "danger", "critical_vulnerability" => 'some text' }, false], - [false, { "severity" => "danger", "critical_vulnerability" => 'false' }, false], - [false, { "severity" => "danger", "critical_vulnerability" => false }, false], - [false, { "severity" => "danger", "critical_vulnerability" => 'true' }, false], - [false, { "severity" => "danger", "critical_vulnerability" => true }, false], - [true, nil, false], - [true, { "severity" => "success" }, nil], - [true, { "severity" => "danger" }, nil], - [true, { "severity" => "danger", "critical_vulnerability" => 'some text' }, nil], - [true, { "severity" => "danger", "critical_vulnerability" => 'false' }, false], - [true, { "severity" => "danger", "critical_vulnerability" => false }, false], - [true, { "severity" => "danger", "critical_vulnerability" => 'true' }, true], - [true, { "severity" => "danger", "critical_vulnerability" => true }, true] + [nil, false], + [{}, nil], + [{ "severity" => "success" }, nil], + [{ "severity" => "danger" }, nil], + [{ "severity" => "danger", "critical_vulnerability" => 'some text' }, nil], + [{ "severity" => "danger", "critical_vulnerability" => 'false' }, false], + [{ "severity" => "danger", "critical_vulnerability" => false }, false], + [{ "severity" => "danger", "critical_vulnerability" => 'true' }, true], + [{ "severity" => "danger", "critical_vulnerability" => true }, true] ] end with_them do before do - allow(helper).to receive(:show_version_check?).and_return(show_version_check) allow(helper).to receive(:gitlab_version_check).and_return(gitlab_version_check) end diff --git a/spec/lib/gitlab/ci/components/instance_path_spec.rb b/spec/lib/gitlab/ci/components/instance_path_spec.rb index f4bc706f9b4..751450fa802 100644 --- a/spec/lib/gitlab/ci/components/instance_path_spec.rb +++ b/spec/lib/gitlab/ci/components/instance_path_spec.rb @@ -48,6 +48,20 @@ RSpec.describe Gitlab::Ci::Components::InstancePath, feature_category: :pipeline it 'fetches the content' do expect(path.fetch_content!(current_user: user)).to eq(content) end + + shared_examples 'prevents infinite loop' do |prefix| + context "when the project path starts with '#{prefix}'" do + let(:project_path) { "#{prefix}#{existing_project.full_path}" } + + it 'returns nil' do + result = path.fetch_content!(current_user: user) + expect(result).to be_nil + end + end + end + + it_behaves_like 'prevents infinite loop', '/' + it_behaves_like 'prevents infinite loop', '//' end context 'when user does not have permissions to download code' do diff --git a/spec/lib/gitlab/ci/jwt_spec.rb b/spec/lib/gitlab/ci/jwt_spec.rb index a6de5b9879c..f0b203961b4 100644 --- a/spec/lib/gitlab/ci/jwt_spec.rb +++ b/spec/lib/gitlab/ci/jwt_spec.rb @@ -49,6 +49,7 @@ RSpec.describe Gitlab::Ci::Jwt do expect(payload[:environment]).to be_nil expect(payload[:environment_protected]).to be_nil expect(payload[:deployment_tier]).to be_nil + expect(payload[:environment_action]).to be_nil end end @@ -109,7 +110,10 @@ RSpec.describe Gitlab::Ci::Jwt do project: project, user: user, pipeline: pipeline, - environment: environment.name + environment: { + name: environment.name, + action: 'start' + } ) end @@ -121,6 +125,7 @@ RSpec.describe Gitlab::Ci::Jwt do expect(payload[:environment]).to eq('production') expect(payload[:environment_protected]).to eq('false') expect(payload[:deployment_tier]).to eq('production') + expect(payload[:environment_action]).to eq('start') end describe 'deployment_tier' do @@ -134,6 +139,18 @@ RSpec.describe Gitlab::Ci::Jwt do end end end + + describe 'environment_action' do + context 'when build options specifies a different environment_action' do + before do + build.options[:environment] = { name: environment.name, action: 'prepare' } + end + + it 'uses environment_action from build options' do + expect(payload[:environment_action]).to eq('prepare') + end + end + end end end diff --git a/spec/lib/gitlab/import_export/command_line_util_spec.rb b/spec/lib/gitlab/import_export/command_line_util_spec.rb index 8ed3a60d7fc..b709a2dbedb 100644 --- a/spec/lib/gitlab/import_export/command_line_util_spec.rb +++ b/spec/lib/gitlab/import_export/command_line_util_spec.rb @@ -84,6 +84,20 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil, feature_category: :importe end end + shared_examples 'deletes pipes' do |compression, decompression| + it 'deletes the pipes', :aggregate_failures do + FileUtils.touch("#{source_dir}/file.txt") + File.mkfifo("#{source_dir}/pipe") + + archive_file = File.join(archive_dir, 'file_with_pipes.tar.gz') + subject.public_send(compression, archive: archive_file, dir: source_dir) + subject.public_send(decompression, archive: archive_file, dir: target_dir) + + expect(File).to exist("#{target_dir}/file.txt") + expect(File).not_to exist("#{target_dir}/pipe") + end + end + describe '#download_or_copy_upload' do let(:upload) { instance_double(Upload, local?: local) } let(:uploader) { instance_double(ImportExportUploader, path: :path, url: :url, upload: upload) } @@ -302,6 +316,7 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil, feature_category: :importe it_behaves_like 'deletes symlinks', :tar_czf, :untar_zxf it_behaves_like 'handles shared hard links', :tar_czf, :untar_zxf + it_behaves_like 'deletes pipes', :tar_czf, :untar_zxf it 'has the right mask for project.json' do subject.untar_zxf(archive: tar_archive_fixture, dir: target_dir) @@ -321,6 +336,7 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil, feature_category: :importe it_behaves_like 'deletes symlinks', :tar_cf, :untar_xf it_behaves_like 'handles shared hard links', :tar_cf, :untar_xf + it_behaves_like 'deletes pipes', :tar_czf, :untar_zxf it 'extracts archive without decompression' do filename = 'archive.tar.gz' diff --git a/spec/lib/gitlab/search/abuse_detection_spec.rb b/spec/lib/gitlab/search/abuse_detection_spec.rb index f9a1d0211b9..cbf20614ba5 100644 --- a/spec/lib/gitlab/search/abuse_detection_spec.rb +++ b/spec/lib/gitlab/search/abuse_detection_spec.rb @@ -10,12 +10,12 @@ RSpec.describe Gitlab::Search::AbuseDetection, feature_category: :global_search describe 'abusive scopes validation' do it 'allows only approved scopes' do described_class::ALLOWED_SCOPES.each do |scope| - expect(described_class.new(scope: scope)).to be_valid + expect(described_class.new({ scope: scope })).to be_valid end end it 'disallows anything not approved' do - expect(described_class.new(scope: 'nope')).not_to be_valid + expect(described_class.new({ scope: 'nope' })).not_to be_valid end end @@ -55,14 +55,14 @@ RSpec.describe Gitlab::Search::AbuseDetection, feature_category: :global_search it 'considers non Integers to be invalid' do [:project_id, :group_id].each do |param| [[1, 2, 3], 'xyz', 3.14, { foo: :bar }].each do |dtype| - expect(described_class.new(param => dtype)).not_to be_valid + expect(described_class.new({ param => dtype })).not_to be_valid end end end it 'considers Integers to be valid' do [:project_id, :group_id].each do |param| - expect(described_class.new(param => 123)).to be_valid + expect(described_class.new({ param => 123 })).to be_valid end end end @@ -70,7 +70,7 @@ RSpec.describe Gitlab::Search::AbuseDetection, feature_category: :global_search describe 'query_string validation' do using ::RSpec::Parameterized::TableSyntax - subject { described_class.new(query_string: search) } + subject { described_class.new({ query_string: search }) } let(:validation_errors) do subject.validate @@ -82,11 +82,15 @@ RSpec.describe Gitlab::Search::AbuseDetection, feature_category: :global_search word | { query_string: ['stopword only abusive search detected'] } end - 'x' | { query_string: ['abusive tiny search detected'] } - ('x' * described_class::ABUSIVE_TERM_SIZE) | { query_string: ['abusive term length detected'] } - '' | {} - '*' | {} - 'ruby' | {} + (['apples'] * (described_class::MAX_PIPE_SYNTAX_FILTERS + 1)).join('|') | { query_string: ['too many pipe syntax filters'] } # rubocop:disable Layout/LineLength + (['apples'] * described_class::MAX_PIPE_SYNTAX_FILTERS).join('|') | {} + 'x' | { query_string: ['abusive tiny search detected'] } + 'apples|x' | { query_string: ['abusive tiny search detected'] } + ('x' * described_class::ABUSIVE_TERM_SIZE) | { query_string: ['abusive term length detected'] } + "apples|#{'x' * described_class::ABUSIVE_TERM_SIZE}" | { query_string: ['abusive term length detected'] } + '' | {} + '*' | {} + 'ruby' | {} end with_them do @@ -100,14 +104,14 @@ RSpec.describe Gitlab::Search::AbuseDetection, feature_category: :global_search it 'considers anything not a String invalid' do [:query_string, :scope, :repository_ref, :project_ref].each do |param| [[1, 2, 3], 123, 3.14, { foo: :bar }].each do |dtype| - expect(described_class.new(param => dtype)).not_to be_valid + expect(described_class.new({ param => dtype })).not_to be_valid end end end it 'considers Strings to be valid' do [:query_string, :repository_ref, :project_ref].each do |param| - expect(described_class.new(param => "foo")).to be_valid + expect(described_class.new({ param => "foo" })).to be_valid end end end diff --git a/spec/lib/gitlab/search/params_spec.rb b/spec/lib/gitlab/search/params_spec.rb index 3235a0b2126..3c64082aeeb 100644 --- a/spec/lib/gitlab/search/params_spec.rb +++ b/spec/lib/gitlab/search/params_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Gitlab::Search::Params, feature_category: :global_search do end it 'uses AbuseDetection by default' do - expect(Gitlab::Search::AbuseDetection).to receive(:new).and_call_original + expect(Gitlab::Search::AbuseDetection).to receive(:new).at_least(:once).and_call_original described_class.new(params) end end @@ -73,9 +73,21 @@ RSpec.describe Gitlab::Search::Params, feature_category: :global_search do end it 'validates AbuseDetector on validation' do - expect(Gitlab::Search::AbuseDetection).to receive(:new).and_call_original + expect(Gitlab::Search::AbuseDetection).to receive(:new).at_least(:once).and_call_original subject.validate end + + context 'when query has too many terms' do + let(:search) { Array.new((::Gitlab::Search::Params::SEARCH_TERM_LIMIT + 1), 'a').join(' ') } + + it { is_expected.not_to be_valid } + end + + context 'when query is too long' do + let(:search) { 'a' * (::Gitlab::Search::Params::SEARCH_CHAR_LIMIT + 1) } + + it { is_expected.not_to be_valid } + end end describe '#valid?' do @@ -89,7 +101,7 @@ RSpec.describe Gitlab::Search::Params, feature_category: :global_search do end it 'validates AbuseDetector on validation' do - expect(Gitlab::Search::AbuseDetection).to receive(:new).and_call_original + expect(Gitlab::Search::AbuseDetection).to receive(:new).at_least(:once).and_call_original subject.valid? end end diff --git a/spec/mailers/emails/service_desk_spec.rb b/spec/mailers/emails/service_desk_spec.rb index 8c0efe3f480..068ca08150a 100644 --- a/spec/mailers/emails/service_desk_spec.rb +++ b/spec/mailers/emails/service_desk_spec.rb @@ -210,6 +210,28 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do let(:expected_template_html) { "<p dir=\"auto\">thank you, your new issue has been created. </p>#{issue.description_html}" } it_behaves_like 'a service desk notification email with template content', 'thank_you' + + context 'when GitLab-specific-reference is in description' do + let(:full_issue_reference) { "#{issue.project.full_path}#{issue.to_reference}" } + let(:other_issue) { create(:issue, project: project, description: full_issue_reference) } + + let(:template_content) { '%{ISSUE_DESCRIPTION}' } + let(:expected_template_html) { "<p data-sourcepos=\"1:1-1:22\" dir=\"auto\">#{full_issue_reference}</p>" } + + subject { ServiceEmailClass.service_desk_thank_you_email(other_issue.id) } + + before do + expect(Gitlab::Template::ServiceDeskTemplate).to receive(:find) + .with('thank_you', other_issue.project) + .and_return(template) + + other_issue.issue_email_participants.create!(email: email) + end + + it 'does not render GitLab-specific-reference links with title attribute' do + is_expected.to have_body_text(expected_template_html) + end + end end context 'when issue url placeholder is used' do |