Commit 79aef9e9 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'ee-40561-environment-scope-value-is-not-trimmed' into 'master'

[EE] Strip leading & trailing whitespaces in CI/CD secret variable keys, and environment scope

Closes gitlab-ce#40561

See merge request gitlab-org/gitlab-ee!3563
parents df940acb fa1127c6
......@@ -4,7 +4,6 @@ module Ci
include HasVariable
include Presentable
prepend EE::Ci::Variable
include Presentable
belongs_to :project
......
......@@ -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
......
---
title: Strip leading & trailing whitespaces in CI/CD secret variable's environment
scope
merge_request: 3563
author:
type: fixed
---
title: Strip leading & trailing whitespaces in CI/CD secret variable keys
merge_request: 15615
author:
type: fixed
......@@ -11,6 +11,10 @@ module EE
message: ::Gitlab::Regex.environment_scope_regex_message }
)
end
def environment_scope=(new_environment_scope)
super(new_environment_scope.to_s.strip)
end
end
end
end
......@@ -11,4 +11,22 @@ describe Ci::Variable do
is_expected.to validate_uniqueness_of(:key)
.scoped_to(:project_id, :environment_scope)
end
describe '#environment_scope=' do
context 'when the new environment_scope is nil' do
it 'strips leading and trailing whitespaces' do
subject.environment_scope = nil
expect(subject.environment_scope).to eq('')
end
end
context 'when the new environment_scope has leadind and trailing whitespaces' do
it 'strips leading and trailing whitespaces' do
subject.environment_scope = ' * '
expect(subject.environment_scope).to eq('*')
end
end
end
end
......@@ -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'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment