From a5549176e1fb5780fa68778571f0eda563dcf090 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 23 Aug 2021 06:09:01 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/lib/gitlab/ci/config/entry/job_spec.rb | 80 ++++++++++++++++++++++ spec/lib/gitlab/ci/config/entry/rules_spec.rb | 8 +-- spec/models/instance_configuration_spec.rb | 44 +++++++++--- .../help/instance_configuration.html.haml_spec.rb | 9 ++- 4 files changed, 124 insertions(+), 17 deletions(-) (limited to 'spec') diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb index 4a90e765d4b..0bb26babfc0 100644 --- a/spec/lib/gitlab/ci/config/entry/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -169,6 +169,22 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job do it { expect(entry).to be_valid } end end + + context 'when rules are used' do + let(:config) { { script: 'ls', cache: { key: 'test' }, rules: rules } } + + let(:rules) do + [ + { if: '$CI_PIPELINE_SOURCE == "schedule"', when: 'never' }, + [ + { if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' }, + { if: '$CI_PIPELINE_SOURCE == "merge_request_event"' } + ] + ] + end + + it { expect(entry).to be_valid } + end end context 'when entry value is not correct' do @@ -485,6 +501,70 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job do end end end + + context 'when invalid rules are used' do + let(:config) { { script: 'ls', cache: { key: 'test' }, rules: rules } } + + context 'with rules nested more than max allowed levels' do + let(:sample_rule) { { if: '$THIS == "other"', when: 'always' } } + + let(:rules) do + [ + { if: '$THIS == "that"', when: 'always' }, + [ + { if: '$SKIP', when: 'never' }, + [ + sample_rule, + [ + sample_rule, + [ + sample_rule, + [ + sample_rule, + [ + sample_rule, + [ + sample_rule, + [ + sample_rule, + [ + sample_rule, + [ + sample_rule, + [ + sample_rule, + [sample_rule] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + end + + it { expect(entry).not_to be_valid } + end + + context 'with rules with invalid keys' do + let(:rules) do + [ + { invalid_key: 'invalid' }, + [ + { if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' }, + { if: '$CI_PIPELINE_SOURCE == "merge_request_event"' } + ] + ] + end + + it { expect(entry).not_to be_valid } + end + end end end diff --git a/spec/lib/gitlab/ci/config/entry/rules_spec.rb b/spec/lib/gitlab/ci/config/entry/rules_spec.rb index 91252378541..cfec33003e4 100644 --- a/spec/lib/gitlab/ci/config/entry/rules_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/rules_spec.rb @@ -53,7 +53,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Rules do let(:config) do [ { if: '$THIS == "that"', when: 'always' }, - [{ if: '$SKIP', when: 'never' }] + [{ if: '$SKIP', when: 'never' }, { if: '$THIS == "other"', when: 'always' }] ] end @@ -64,11 +64,11 @@ RSpec.describe Gitlab::Ci::Config::Entry::Rules do let(:config) do [ { if: '$THIS == "that"', when: 'always' }, - [{ if: '$SKIP', when: 'never' }, [{ if: '$THIS == "other"', when: 'aways' }]] + [{ if: '$SKIP', when: 'never' }, [{ if: '$THIS == "other"', when: 'always' }]] ] end - it { is_expected.not_to be_valid } + it { is_expected.to be_valid } end end @@ -119,7 +119,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Rules do context 'with rules nested more than one level' do let(:first_rule) { { if: '$THIS == "that"', when: 'always' } } let(:second_rule) { { if: '$SKIP', when: 'never' } } - let(:third_rule) { { if: '$THIS == "other"', when: 'aways' } } + let(:third_rule) { { if: '$THIS == "other"', when: 'always' } } let(:config) do [ diff --git a/spec/models/instance_configuration_spec.rb b/spec/models/instance_configuration_spec.rb index 9544f0fe6ec..551e6e7572c 100644 --- a/spec/models/instance_configuration_spec.rb +++ b/spec/models/instance_configuration_spec.rb @@ -76,24 +76,46 @@ RSpec.describe InstanceConfiguration do end end - describe '#gitlab_ci' do - let(:gitlab_ci) { subject.settings[:gitlab_ci] } + describe '#size_limits' do + before do + Gitlab::CurrentSettings.current_application_settings.update!( + max_attachment_size: 10, + receive_max_input_size: 20, + max_import_size: 30, + diff_max_patch_bytes: 409600, + max_artifacts_size: 50, + max_pages_size: 60, + snippet_size_limit: 70 + ) + end - it 'returns Settings.gitalb_ci' do - gitlab_ci.delete(:artifacts_max_size) + it 'returns size limits from application settings' do + size_limits = subject.settings[:size_limits] - expect(gitlab_ci).to eq(Settings.gitlab_ci.symbolize_keys) + expect(size_limits[:max_attachment_size]).to eq(10.megabytes) + expect(size_limits[:receive_max_input_size]).to eq(20.megabytes) + expect(size_limits[:max_import_size]).to eq(30.megabytes) + expect(size_limits[:diff_max_patch_bytes]).to eq(400.kilobytes) + expect(size_limits[:max_artifacts_size]).to eq(50.megabytes) + expect(size_limits[:max_pages_size]).to eq(60.megabytes) + expect(size_limits[:snippet_size_limit]).to eq(70.bytes) end - it 'returns the key artifacts_max_size' do - expect(gitlab_ci.keys).to include(:artifacts_max_size) + it 'returns nil if receive_max_input_size not set' do + Gitlab::CurrentSettings.current_application_settings.update!(receive_max_input_size: nil) + + size_limits = subject.settings[:size_limits] + + expect(size_limits[:receive_max_input_size]).to be_nil end - it 'returns the key artifacts_max_size with values' do - stub_application_setting(max_artifacts_size: 200) + it 'returns nil if set to 0 (unlimited)' do + Gitlab::CurrentSettings.current_application_settings.update!(max_import_size: 0, max_pages_size: 0) + + size_limits = subject.settings[:size_limits] - expect(gitlab_ci[:artifacts_max_size][:default]).to eq(100.megabytes) - expect(gitlab_ci[:artifacts_max_size][:value]).to eq(200.megabytes) + expect(size_limits[:max_import_size]).to be_nil + expect(size_limits[:max_pages_size]).to be_nil end end diff --git a/spec/views/help/instance_configuration.html.haml_spec.rb b/spec/views/help/instance_configuration.html.haml_spec.rb index 7b431bb4180..c4542046a9d 100644 --- a/spec/views/help/instance_configuration.html.haml_spec.rb +++ b/spec/views/help/instance_configuration.html.haml_spec.rb @@ -9,6 +9,7 @@ RSpec.describe 'help/instance_configuration' do let(:ssh_settings) { settings[:ssh_algorithms_hashes] } before do + create(:plan, name: 'plan1', title: 'Plan 1') assign(:instance_configuration, instance_configuration) end @@ -17,7 +18,9 @@ RSpec.describe 'help/instance_configuration' do expect(rendered).to have_link(nil, href: '#ssh-host-keys-fingerprints') if ssh_settings.any? expect(rendered).to have_link(nil, href: '#gitlab-pages') - expect(rendered).to have_link(nil, href: '#gitlab-ci') + expect(rendered).to have_link(nil, href: '#size-limits') + expect(rendered).to have_link(nil, href: '#package-registry') + expect(rendered).to have_link(nil, href: '#rate-limits') end it 'has several sections' do @@ -25,7 +28,9 @@ RSpec.describe 'help/instance_configuration' do expect(rendered).to have_css('h2#ssh-host-keys-fingerprints') if ssh_settings.any? expect(rendered).to have_css('h2#gitlab-pages') - expect(rendered).to have_css('h2#gitlab-ci') + expect(rendered).to have_css('h2#size-limits') + expect(rendered).to have_css('h2#package-registry') + expect(rendered).to have_css('h2#rate-limits') end end end -- cgit v1.2.3