2019-02-26 19:22:51 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Ci::Maskable do
|
2019-02-26 19:22:51 -05:00
|
|
|
let(:variable) { build(:ci_variable) }
|
|
|
|
|
|
|
|
describe 'masked value validations' do
|
|
|
|
subject { variable }
|
|
|
|
|
|
|
|
context 'when variable is masked' do
|
|
|
|
before do
|
|
|
|
subject.masked = 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.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
|
|
|
|
|
|
|
|
describe 'REGEX' do
|
2020-03-18 08:09:13 -04:00
|
|
|
subject { Ci::Maskable::REGEX }
|
2019-02-26 19:22:51 -05:00
|
|
|
|
|
|
|
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 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
|
|
|
|
|
|
|
|
expect(subject.match?(string)).to eq(false)
|
|
|
|
end
|
|
|
|
|
2020-04-08 08:09:42 -04:00
|
|
|
it 'does not match strings using unsupported characters' do
|
|
|
|
expect(subject.match?('HelloWorld%#^')).to eq(false)
|
|
|
|
end
|
|
|
|
|
2019-02-26 19:22:51 -05:00
|
|
|
it 'matches valid strings' do
|
2021-05-13 20:11:05 -04:00
|
|
|
expect(subject.match?('Hello+World_123/@:-~.')).to eq(true)
|
2019-02-26 19:22:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#to_runner_variable' do
|
|
|
|
subject { variable.to_runner_variable }
|
|
|
|
|
|
|
|
it 'exposes the masked attribute' do
|
|
|
|
expect(subject).to include(:masked)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|