gitlab-org--gitlab-foss/spec/lib/ci/mask_secret_spec.rb

28 lines
603 B
Ruby
Raw Normal View History

2016-09-19 06:38:03 -04:00
require 'spec_helper'
describe Ci::MaskSecret do
2016-09-19 06:38:03 -04:00
subject { described_class }
describe '#mask' do
it 'masks exact number of characters' do
2016-09-20 09:41:41 -04:00
expect(mask('token', 'oke')).to eq('txxxn')
2016-09-19 06:38:03 -04:00
end
it 'masks multiple occurrences' do
2016-09-20 09:41:41 -04:00
expect(mask('token token token', 'oke')).to eq('txxxn txxxn txxxn')
2016-09-19 06:38:03 -04:00
end
it 'does not mask if not found' do
2016-09-20 09:41:41 -04:00
expect(mask('token', 'not')).to eq('token')
end
2016-09-20 11:07:34 -04:00
it 'does support null token' do
expect(mask('token', nil)).to eq('token')
end
2016-09-20 09:41:41 -04:00
def mask(value, token)
2016-09-20 11:07:34 -04:00
subject.mask!(value.dup, token)
2016-09-19 06:38:03 -04:00
end
end
end