Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-03-10 18:08:10 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-03-10 18:08:10 +0300
commit6ebe886c82111e1ab9e71d4c02a888d2312898bc (patch)
tree93775be141eb34e24c37c880e6d96b242267d3bc /spec/lib/gitlab
parente3624c5be1696597bc6b351f56f1a84c2b13211b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/ci/build/policy/refs_spec.rb23
-rw-r--r--spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/config/entry/policy_spec.rb48
-rw-r--r--spec/lib/gitlab/ci/config/entry/reports/coverage_report_spec.rb57
-rw-r--r--spec/lib/gitlab/ci/config/entry/reports_spec.rb47
-rw-r--r--spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb8
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb4
-rw-r--r--spec/lib/gitlab/config/entry/validators_spec.rb43
-rw-r--r--spec/lib/gitlab/json_cache_spec.rb2
-rw-r--r--spec/lib/gitlab/metrics/dashboard/cache_spec.rb2
-rw-r--r--spec/lib/gitlab/null_request_store_spec.rb2
-rw-r--r--spec/lib/gitlab/safe_request_store_spec.rb4
-rw-r--r--spec/lib/gitlab/untrusted_regexp/ruby_syntax_spec.rb40
13 files changed, 161 insertions, 123 deletions
diff --git a/spec/lib/gitlab/ci/build/policy/refs_spec.rb b/spec/lib/gitlab/ci/build/policy/refs_spec.rb
index 7fd51102d71..2924b175fef 100644
--- a/spec/lib/gitlab/ci/build/policy/refs_spec.rb
+++ b/spec/lib/gitlab/ci/build/policy/refs_spec.rb
@@ -149,26 +149,9 @@ RSpec.describe Gitlab::Ci::Build::Policy::Refs do
context 'when unsafe regexp is used' do
let(:subject) { described_class.new(['/^(?!master).+/']) }
- context 'when allow_unsafe_ruby_regexp is disabled' do
- before do
- stub_feature_flags(allow_unsafe_ruby_regexp: false)
- end
-
- it 'ignores invalid regexp' do
- expect(subject)
- .not_to be_satisfied_by(pipeline)
- end
- end
-
- context 'when allow_unsafe_ruby_regexp is enabled' do
- before do
- stub_feature_flags(allow_unsafe_ruby_regexp: true)
- end
-
- it 'is satisfied by regexp' do
- expect(subject)
- .to be_satisfied_by(pipeline)
- end
+ it 'ignores invalid regexp' do
+ expect(subject)
+ .not_to be_satisfied_by(pipeline)
end
end
end
diff --git a/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb b/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb
index e83d4974bb7..6116fbced2b 100644
--- a/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb
@@ -59,9 +59,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules::Rule do
context 'when using an if: clause with lookahead regex character "?"' do
let(:config) { { if: '$CI_COMMIT_REF =~ /^(?!master).+/' } }
- context 'when allow_unsafe_ruby_regexp is disabled' do
- it_behaves_like 'an invalid config', /invalid expression syntax/
- end
+ it_behaves_like 'an invalid config', /invalid expression syntax/
end
context 'when specifying unknown policy' do
diff --git a/spec/lib/gitlab/ci/config/entry/policy_spec.rb b/spec/lib/gitlab/ci/config/entry/policy_spec.rb
index e5de0fb38e3..378c0947e8a 100644
--- a/spec/lib/gitlab/ci/config/entry/policy_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/policy_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require 'fast_spec_helper'
RSpec.describe Gitlab::Ci::Config::Entry::Policy do
let(:entry) { described_class.new(config) }
@@ -45,29 +45,10 @@ RSpec.describe Gitlab::Ci::Config::Entry::Policy do
end
context 'when using unsafe regexp' do
- # When removed we could use `require 'fast_spec_helper'` again.
- include StubFeatureFlags
-
let(:config) { ['/^(?!master).+/'] }
- context 'when allow_unsafe_ruby_regexp is disabled' do
- before do
- stub_feature_flags(allow_unsafe_ruby_regexp: false)
- end
-
- it 'is not valid' do
- expect(entry).not_to be_valid
- end
- end
-
- context 'when allow_unsafe_ruby_regexp is enabled' do
- before do
- stub_feature_flags(allow_unsafe_ruby_regexp: true)
- end
-
- it 'is valid' do
- expect(entry).to be_valid
- end
+ it 'is not valid' do
+ expect(entry).not_to be_valid
end
end
@@ -106,29 +87,10 @@ RSpec.describe Gitlab::Ci::Config::Entry::Policy do
end
context 'when using unsafe regexp' do
- # When removed we could use `require 'fast_spec_helper'` again.
- include StubFeatureFlags
-
let(:config) { { refs: ['/^(?!master).+/'] } }
- context 'when allow_unsafe_ruby_regexp is disabled' do
- before do
- stub_feature_flags(allow_unsafe_ruby_regexp: false)
- end
-
- it 'is not valid' do
- expect(entry).not_to be_valid
- end
- end
-
- context 'when allow_unsafe_ruby_regexp is enabled' do
- before do
- stub_feature_flags(allow_unsafe_ruby_regexp: true)
- end
-
- it 'is valid' do
- expect(entry).to be_valid
- end
+ it 'is not valid' do
+ expect(entry).not_to be_valid
end
end
diff --git a/spec/lib/gitlab/ci/config/entry/reports/coverage_report_spec.rb b/spec/lib/gitlab/ci/config/entry/reports/coverage_report_spec.rb
new file mode 100644
index 00000000000..588f53150ff
--- /dev/null
+++ b/spec/lib/gitlab/ci/config/entry/reports/coverage_report_spec.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+
+RSpec.describe Gitlab::Ci::Config::Entry::Reports::CoverageReport do
+ let(:entry) { described_class.new(config) }
+
+ describe 'validations' do
+ context 'when it is valid' do
+ let(:config) { { coverage_format: 'cobertura', path: 'cobertura-coverage.xml' } }
+
+ it { expect(entry).to be_valid }
+
+ it { expect(entry.value).to eq(config) }
+ end
+
+ context 'with unsupported coverage format' do
+ let(:config) { { coverage_format: 'jacoco', path: 'jacoco.xml' } }
+
+ it { expect(entry).not_to be_valid }
+
+ it { expect(entry.errors).to include /format must be one of supported formats/ }
+ end
+
+ context 'without coverage format' do
+ let(:config) { { path: 'cobertura-coverage.xml' } }
+
+ it { expect(entry).not_to be_valid }
+
+ it { expect(entry.errors).to include /format can't be blank/ }
+ end
+
+ context 'without path' do
+ let(:config) { { coverage_format: 'cobertura' } }
+
+ it { expect(entry).not_to be_valid }
+
+ it { expect(entry.errors).to include /path can't be blank/ }
+ end
+
+ context 'with invalid path' do
+ let(:config) { { coverage_format: 'cobertura', path: 123 } }
+
+ it { expect(entry).not_to be_valid }
+
+ it { expect(entry.errors).to include /path should be a string/ }
+ end
+
+ context 'with unknown keys' do
+ let(:config) { { coverage_format: 'cobertura', path: 'cobertura-coverage.xml', foo: :bar } }
+
+ it { expect(entry).not_to be_valid }
+
+ it { expect(entry.errors).to include /contains unknown keys/ }
+ end
+ end
+end
diff --git a/spec/lib/gitlab/ci/config/entry/reports_spec.rb b/spec/lib/gitlab/ci/config/entry/reports_spec.rb
index 12b8960eb32..061d8f34c8d 100644
--- a/spec/lib/gitlab/ci/config/entry/reports_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/reports_spec.rb
@@ -6,12 +6,8 @@ RSpec.describe Gitlab::Ci::Config::Entry::Reports do
let(:entry) { described_class.new(config) }
describe 'validates ALLOWED_KEYS' do
- let(:artifact_file_types) { Ci::JobArtifact.file_types }
-
- described_class::ALLOWED_KEYS.each do |keyword, _|
- it "expects #{keyword} to be an artifact file_type" do
- expect(artifact_file_types).to include(keyword)
- end
+ it "expects ALLOWED_KEYS to be an artifact file_type or coverage_report" do
+ expect(Ci::JobArtifact.file_types.keys.map(&:to_sym) + [:coverage_report]).to include(*described_class::ALLOWED_KEYS)
end
end
@@ -68,6 +64,45 @@ RSpec.describe Gitlab::Ci::Config::Entry::Reports do
it_behaves_like 'a valid entry', params[:keyword], params[:file]
end
end
+
+ context 'when coverage_report is specified' do
+ let(:coverage_format) { :cobertura }
+ let(:filename) { 'cobertura-coverage.xml' }
+ let(:coverage_report) { { path: filename, coverage_format: coverage_format } }
+ let(:config) { { coverage_report: coverage_report } }
+
+ it 'is valid' do
+ expect(entry).to be_valid
+ end
+
+ it 'returns artifacts configuration' do
+ expect(entry.value).to eq(config)
+ end
+
+ context 'and another report is specified' do
+ let(:config) { { coverage_report: coverage_report, dast: 'gl-dast-report.json' } }
+
+ it 'is valid' do
+ expect(entry).to be_valid
+ end
+
+ it 'returns artifacts configuration' do
+ expect(entry.value).to eq({ coverage_report: coverage_report, dast: ['gl-dast-report.json'] })
+ end
+ end
+
+ context 'and a direct coverage report format is specified' do
+ let(:config) { { coverage_report: coverage_report, cobertura: 'cobertura-coverage.xml' } }
+
+ it 'is not valid' do
+ expect(entry).not_to be_valid
+ end
+
+ it 'reports error' do
+ expect(entry.errors).to include /please use only one the following keys: coverage_report, cobertura/
+ end
+ end
+ end
end
context 'when entry value is not correct' do
diff --git a/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb b/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb
index 9fe0be29fa8..86270788431 100644
--- a/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb
@@ -92,12 +92,10 @@ RSpec.describe Gitlab::Ci::Config::Entry::Rules::Rule do
context 'when using an if: clause with lookahead regex character "?"' do
let(:config) { { if: '$CI_COMMIT_REF =~ /^(?!master).+/' } }
- context 'when allow_unsafe_ruby_regexp is disabled' do
- it { is_expected.not_to be_valid }
+ it { is_expected.not_to be_valid }
- it 'reports an error about invalid expression syntax' do
- expect(subject.errors).to include(/invalid expression syntax/)
- end
+ it 'reports an error about invalid expression syntax' do
+ expect(subject.errors).to include(/invalid expression syntax/)
end
end
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index 5f46607b042..a6d8657d85f 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -9,10 +9,6 @@ module Gitlab
subject { described_class.new(config, user: nil).execute }
- before do
- stub_feature_flags(allow_unsafe_ruby_regexp: false)
- end
-
shared_examples 'returns errors' do |error_message|
it 'adds a message when an error is encountered' do
expect(subject.errors).to include(error_message)
diff --git a/spec/lib/gitlab/config/entry/validators_spec.rb b/spec/lib/gitlab/config/entry/validators_spec.rb
new file mode 100644
index 00000000000..cbc09aac586
--- /dev/null
+++ b/spec/lib/gitlab/config/entry/validators_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Config::Entry::Validators do
+ let(:klass) do
+ Class.new do
+ include ActiveModel::Validations
+ include Gitlab::Config::Entry::Validators
+ end
+ end
+
+ let(:instance) { klass.new }
+
+ describe described_class::MutuallyExclusiveKeysValidator do
+ using RSpec::Parameterized::TableSyntax
+
+ before do
+ klass.instance_eval do
+ validates :config, mutually_exclusive_keys: [:foo, :bar]
+ end
+
+ allow(instance).to receive(:config).and_return(config)
+ end
+
+ where(:context, :config, :valid_result) do
+ 'with mutually exclusive keys' | { foo: 1, bar: 2 } | false
+ 'without mutually exclusive keys' | { foo: 1 } | true
+ 'without mutually exclusive keys' | { bar: 1 } | true
+ 'with other keys' | { foo: 1, baz: 2 } | true
+ end
+
+ with_them do
+ it 'validates the instance' do
+ expect(instance.valid?).to be(valid_result)
+
+ unless valid_result
+ expect(instance.errors.messages_for(:config)).to include /please use only one the following keys: foo, bar/
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/json_cache_spec.rb b/spec/lib/gitlab/json_cache_spec.rb
index 01c2120d9a6..d7d28a94cfe 100644
--- a/spec/lib/gitlab/json_cache_spec.rb
+++ b/spec/lib/gitlab/json_cache_spec.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+# rubocop:disable Style/RedundantFetchBlock
require 'spec_helper'
@@ -547,3 +548,4 @@ RSpec.describe Gitlab::JsonCache do
end
end
end
+# rubocop:enable Style/RedundantFetchBlock
diff --git a/spec/lib/gitlab/metrics/dashboard/cache_spec.rb b/spec/lib/gitlab/metrics/dashboard/cache_spec.rb
index 9467d441ae1..8c2edc85c35 100644
--- a/spec/lib/gitlab/metrics/dashboard/cache_spec.rb
+++ b/spec/lib/gitlab/metrics/dashboard/cache_spec.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+# rubocop:disable Style/RedundantFetchBlock
require 'spec_helper'
@@ -84,3 +85,4 @@ RSpec.describe Gitlab::Metrics::Dashboard::Cache, :use_clean_rails_memory_store_
end
end
end
+# rubocop:enable Style/RedundantFetchBlock
diff --git a/spec/lib/gitlab/null_request_store_spec.rb b/spec/lib/gitlab/null_request_store_spec.rb
index f600af2e31f..66700313c9a 100644
--- a/spec/lib/gitlab/null_request_store_spec.rb
+++ b/spec/lib/gitlab/null_request_store_spec.rb
@@ -49,7 +49,7 @@ RSpec.describe Gitlab::NullRequestStore do
describe '#fetch' do
it 'returns the block result' do
- expect(null_store.fetch('key') { 'block result' }).to eq('block result')
+ expect(null_store.fetch('key') { 'block result' }).to eq('block result') # rubocop:disable Style/RedundantFetchBlock
end
end
diff --git a/spec/lib/gitlab/safe_request_store_spec.rb b/spec/lib/gitlab/safe_request_store_spec.rb
index 704102ccaee..accc491fbb7 100644
--- a/spec/lib/gitlab/safe_request_store_spec.rb
+++ b/spec/lib/gitlab/safe_request_store_spec.rb
@@ -183,7 +183,7 @@ RSpec.describe Gitlab::SafeRequestStore do
context 'when RequestStore is active', :request_store do
it 'uses RequestStore' do
expect do
- described_class.fetch('foo') { 'block result' }
+ described_class.fetch('foo') { 'block result' } # rubocop:disable Style/RedundantFetchBlock
end.to change { described_class.read('foo') }.from(nil).to('block result')
end
end
@@ -193,7 +193,7 @@ RSpec.describe Gitlab::SafeRequestStore do
RequestStore.clear! # Ensure clean
expect do
- described_class.fetch('foo') { 'block result' }
+ described_class.fetch('foo') { 'block result' } # rubocop:disable Style/RedundantFetchBlock
end.not_to change { described_class.read('foo') }.from(nil)
RequestStore.clear! # Clean up
diff --git a/spec/lib/gitlab/untrusted_regexp/ruby_syntax_spec.rb b/spec/lib/gitlab/untrusted_regexp/ruby_syntax_spec.rb
index b021abc9f25..43f155091ad 100644
--- a/spec/lib/gitlab/untrusted_regexp/ruby_syntax_spec.rb
+++ b/spec/lib/gitlab/untrusted_regexp/ruby_syntax_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require 'fast_spec_helper'
RSpec.describe Gitlab::UntrustedRegexp::RubySyntax do
describe '.matches_syntax?' do
@@ -71,44 +71,6 @@ RSpec.describe Gitlab::UntrustedRegexp::RubySyntax do
end
end
- context 'when unsafe regexp is used' do
- include StubFeatureFlags
-
- before do
- # When removed we could use `require 'fast_spec_helper'` again.
- stub_feature_flags(allow_unsafe_ruby_regexp: true)
-
- allow(Gitlab::UntrustedRegexp).to receive(:new).and_raise(RegexpError)
- end
-
- context 'when no fallback is enabled' do
- it 'raises an exception' do
- expect { described_class.fabricate!('/something/') }
- .to raise_error(RegexpError)
- end
- end
-
- context 'when fallback is used' do
- it 'fabricates regexp with a single flag' do
- regexp = described_class.fabricate!('/something/i', fallback: true)
-
- expect(regexp).to eq Regexp.new('something', Regexp::IGNORECASE)
- end
-
- it 'fabricates regexp with multiple flags' do
- regexp = described_class.fabricate!('/something/im', fallback: true)
-
- expect(regexp).to eq Regexp.new('something', Regexp::IGNORECASE | Regexp::MULTILINE)
- end
-
- it 'fabricates regexp without flags' do
- regexp = described_class.fabricate!('/something/', fallback: true)
-
- expect(regexp).to eq Regexp.new('something')
- end
- end
- end
-
context 'when regexp is a raw pattern' do
it 'raises an error' do
expect { described_class.fabricate!('some .* thing') }