summaryrefslogtreecommitdiff
path: root/spec/models/concerns
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-28 00:09:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-28 00:09:24 +0000
commit63895155f203b6af2df0689474059c1c7dfcfac8 (patch)
tree301f7d43471cbb7b19bf92561578e6cef8d28b99 /spec/models/concerns
parent936139e69ce259283d02877bcb23ca77f65e2c60 (diff)
downloadgitlab-ce-63895155f203b6af2df0689474059c1c7dfcfac8.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/concerns')
-rw-r--r--spec/models/concerns/ci/maskable_spec.rb149
1 files changed, 122 insertions, 27 deletions
diff --git a/spec/models/concerns/ci/maskable_spec.rb b/spec/models/concerns/ci/maskable_spec.rb
index 2b13fc21fe8..e2c1e08fe49 100644
--- a/spec/models/concerns/ci/maskable_spec.rb
+++ b/spec/models/concerns/ci/maskable_spec.rb
@@ -2,15 +2,16 @@
require 'spec_helper'
-RSpec.describe Ci::Maskable do
+RSpec.describe Ci::Maskable, feature_category: :pipeline_authoring do
let(:variable) { build(:ci_variable) }
describe 'masked value validations' do
subject { variable }
- context 'when variable is masked' do
+ context 'when variable is masked and expanded' do
before do
subject.masked = true
+ subject.raw = false
end
it { is_expected.not_to allow_value('hello').for(:value) }
@@ -20,6 +21,70 @@ RSpec.describe Ci::Maskable do
it { is_expected.to allow_value('helloworld').for(:value) }
end
+ context 'when method :raw is not defined' do
+ let(:test_var_class) do
+ Struct.new(:masked?) do
+ include ActiveModel::Validations
+ include Ci::Maskable
+ end
+ end
+
+ let(:variable) { test_var_class.new(true) }
+
+ it 'evaluates masked variables as expanded' do
+ expect(subject).not_to be_masked_and_raw
+ expect(subject).to be_masked_and_expanded
+ end
+ end
+
+ context 'when the ci_remove_character_limitation_raw_masked_var FF is disabled' do
+ before do
+ stub_feature_flags(ci_remove_character_limitation_raw_masked_var: false)
+ end
+
+ context 'when variable is masked and raw' do
+ before do
+ subject.masked = true
+ subject.raw = true
+ end
+
+ it { is_expected.not_to allow_value('hello').for(:value) }
+ it { is_expected.not_to allow_value('hello world').for(:value) }
+ it { is_expected.not_to allow_value('hello$VARIABLEworld').for(:value) }
+ it { is_expected.not_to allow_value('hello\rworld').for(:value) }
+ it { is_expected.not_to allow_value('hello&&&world').for(:value) }
+ it { is_expected.not_to allow_value('helloworld!!!!').for(:value) }
+ it { is_expected.to allow_value('helloworld').for(:value) }
+ end
+
+ context 'when variable is not masked' do
+ before do
+ subject.masked = false
+ end
+
+ it { is_expected.to allow_value('hello').for(:value) }
+ it { is_expected.to allow_value('hello world').for(:value) }
+ it { is_expected.to allow_value('hello$VARIABLEworld').for(:value) }
+ it { is_expected.to allow_value('hello\rworld').for(:value) }
+ it { is_expected.to allow_value('helloworld').for(:value) }
+ end
+ end
+
+ context 'when variable is masked and raw' do
+ before do
+ subject.masked = true
+ subject.raw = true
+ end
+
+ it { is_expected.not_to allow_value('hello').for(:value) }
+ it { is_expected.not_to allow_value('hello world').for(:value) }
+ it { is_expected.to allow_value('hello\rworld').for(:value) }
+ it { is_expected.to allow_value('hello$VARIABLEworld').for(:value) }
+ it { is_expected.to allow_value('helloworld!!!').for(:value) }
+ it { is_expected.to allow_value('hell******world').for(:value) }
+ it { is_expected.to allow_value('helloworld123').for(:value) }
+ end
+
context 'when variable is not masked' do
before do
subject.masked = false
@@ -33,40 +98,70 @@ RSpec.describe Ci::Maskable do
end
end
- describe 'REGEX' do
- subject { Ci::Maskable::REGEX }
+ describe 'Regexes' do
+ context 'with MASK_AND_RAW_REGEX' do
+ subject { Ci::Maskable::MASK_AND_RAW_REGEX }
- it 'does not match strings shorter than 8 letters' do
- expect(subject.match?('hello')).to eq(false)
- end
+ it 'does not match strings shorter than 8 letters' do
+ expect(subject.match?('hello')).to eq(false)
+ end
- it 'does not match strings with spaces' do
- expect(subject.match?('hello world')).to eq(false)
- end
+ it 'does not match strings with spaces' do
+ expect(subject.match?('hello world')).to eq(false)
+ end
- it 'does not match strings with shell variables' do
- expect(subject.match?('hello$VARIABLEworld')).to eq(false)
- end
+ it 'does not match strings that span more than one line' do
+ string = <<~EOS
+ hello
+ world
+ EOS
- it 'does not match strings with escape characters' do
- expect(subject.match?('hello\rworld')).to eq(false)
+ expect(subject.match?(string)).to eq(false)
+ end
+
+ it 'matches valid strings' do
+ expect(subject.match?('hello$VARIABLEworld')).to eq(true)
+ expect(subject.match?('Hello+World_123/@:-~.')).to eq(true)
+ expect(subject.match?('hello\rworld')).to eq(true)
+ expect(subject.match?('HelloWorld%#^')).to eq(true)
+ end
end
- it 'does not match strings that span more than one line' do
- string = <<~EOS
- hello
- world
- EOS
+ context 'with REGEX' do
+ subject { Ci::Maskable::REGEX }
- expect(subject.match?(string)).to eq(false)
- end
+ it 'does not match strings shorter than 8 letters' do
+ expect(subject.match?('hello')).to eq(false)
+ end
- it 'does not match strings using unsupported characters' do
- expect(subject.match?('HelloWorld%#^')).to eq(false)
- end
+ it 'does not match strings with spaces' do
+ expect(subject.match?('hello world')).to eq(false)
+ end
+
+ it 'does not match strings with shell variables' do
+ expect(subject.match?('hello$VARIABLEworld')).to eq(false)
+ end
+
+ it 'does not match strings with escape characters' do
+ expect(subject.match?('hello\rworld')).to eq(false)
+ end
+
+ it 'does not match strings that span more than one line' do
+ string = <<~EOS
+ hello
+ world
+ EOS
- it 'matches valid strings' do
- expect(subject.match?('Hello+World_123/@:-~.')).to eq(true)
+ expect(subject.match?(string)).to eq(false)
+ end
+
+ it 'does not match strings using unsupported characters' do
+ expect(subject.match?('HelloWorld%#^')).to eq(false)
+ end
+
+ it 'matches valid strings' do
+ expect(subject.match?('Hello+World_123/@:-~.')).to eq(true)
+ end
end
end