Strip leading & trailing whitespaces in CI/CD secret variable keys

Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
Rémy Coutable 2017-11-27 16:58:12 +01:00
parent 24fadd7c3d
commit fa35ea1387
No known key found for this signature in database
GPG Key ID: 46DF07E5CD9E96AB
3 changed files with 27 additions and 0 deletions

View File

@ -16,6 +16,10 @@ module HasVariable
key: Gitlab::Application.secrets.db_key_base,
algorithm: 'aes-256-cbc'
def key=(new_key)
super(new_key.to_s.strip)
end
def to_runner_variable
{ key: key, value: value, public: false }
end

View File

@ -0,0 +1,5 @@
---
title: Strip leading & trailing whitespaces in CI/CD secret variable keys
merge_request: 15615
author:
type: fixed

View File

@ -9,6 +9,24 @@ describe HasVariable do
it { is_expected.not_to allow_value('foo bar').for(:key) }
it { is_expected.not_to allow_value('foo/bar').for(:key) }
describe '#key=' do
context 'when the new key is nil' do
it 'strips leading and trailing whitespaces' do
subject.key = nil
expect(subject.key).to eq('')
end
end
context 'when the new key has leadind and trailing whitespaces' do
it 'strips leading and trailing whitespaces' do
subject.key = ' my key '
expect(subject.key).to eq('my key')
end
end
end
describe '#value' do
before do
subject.value = 'secret'