diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-04-09 09:28:56 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-04-09 09:28:56 +0000 |
commit | a677db78078affdb9bb9da1fe0b6c0b43368ae5d (patch) | |
tree | 33c08ba08bbd2f50bad523622b309d9ef313b185 | |
parent | 1fce09ed0dc775d706d61e37268b6f39c3fe3de6 (diff) | |
parent | 0a4f44de83fac88f39d9f4507c2fa4d935703e1b (diff) | |
download | gitlab-ce-a677db78078affdb9bb9da1fe0b6c0b43368ae5d.tar.gz |
Merge branch '46326-environment-url-validation' into 'master'
Add environment url validation
Closes #46326
See merge request gitlab-org/gitlab-ce!26805
-rw-r--r-- | lib/gitlab/ci/config/entry/environment.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/environment_spec.rb | 40 |
2 files changed, 42 insertions, 0 deletions
diff --git a/lib/gitlab/ci/config/entry/environment.rb b/lib/gitlab/ci/config/entry/environment.rb index 69a3a1aedef..5a13fd18504 100644 --- a/lib/gitlab/ci/config/entry/environment.rb +++ b/lib/gitlab/ci/config/entry/environment.rb @@ -36,10 +36,12 @@ module Gitlab validates :config, allowed_keys: ALLOWED_KEYS validates :url, + type: String, length: { maximum: 255 }, allow_nil: true validates :action, + type: String, inclusion: { in: %w[start stop], message: 'should be start or stop' }, allow_nil: true diff --git a/spec/lib/gitlab/ci/config/entry/environment_spec.rb b/spec/lib/gitlab/ci/config/entry/environment_spec.rb index 3c0007f4d57..0bc9e8bd3cd 100644 --- a/spec/lib/gitlab/ci/config/entry/environment_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/environment_spec.rb @@ -100,6 +100,26 @@ describe Gitlab::Ci::Config::Entry::Environment do end end + context 'when wrong action type is used' do + let(:config) do + { name: 'production', + action: ['stop'] } + end + + describe '#valid?' do + it 'is not valid' do + expect(entry).not_to be_valid + end + end + + describe '#errors' do + it 'contains error about wrong action type' do + expect(entry.errors) + .to include 'environment action should be a string' + end + end + end + context 'when invalid action is used' do let(:config) do { name: 'production', @@ -151,6 +171,26 @@ describe Gitlab::Ci::Config::Entry::Environment do end end + context 'when wrong url type is used' do + let(:config) do + { name: 'production', + url: ['https://meow.meow'] } + end + + describe '#valid?' do + it 'is not valid' do + expect(entry).not_to be_valid + end + end + + describe '#errors' do + it 'contains error about wrong url type' do + expect(entry.errors) + .to include 'environment url should be a string' + end + end + end + context 'when variables are used for environment' do let(:config) do { name: 'review/$CI_COMMIT_REF_NAME', |