Commit 0a4f44de authored by Wolphin's avatar Wolphin Committed by Kamil Trzciński

Add environment url validation

parent 1fce09ed
...@@ -36,10 +36,12 @@ module Gitlab ...@@ -36,10 +36,12 @@ module Gitlab
validates :config, allowed_keys: ALLOWED_KEYS validates :config, allowed_keys: ALLOWED_KEYS
validates :url, validates :url,
type: String,
length: { maximum: 255 }, length: { maximum: 255 },
allow_nil: true allow_nil: true
validates :action, validates :action,
type: String,
inclusion: { in: %w[start stop], message: 'should be start or stop' }, inclusion: { in: %w[start stop], message: 'should be start or stop' },
allow_nil: true allow_nil: true
......
...@@ -100,6 +100,26 @@ describe Gitlab::Ci::Config::Entry::Environment do ...@@ -100,6 +100,26 @@ describe Gitlab::Ci::Config::Entry::Environment do
end end
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 context 'when invalid action is used' do
let(:config) do let(:config) do
{ name: 'production', { name: 'production',
...@@ -151,6 +171,26 @@ describe Gitlab::Ci::Config::Entry::Environment do ...@@ -151,6 +171,26 @@ describe Gitlab::Ci::Config::Entry::Environment do
end end
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 context 'when variables are used for environment' do
let(:config) do let(:config) do
{ name: 'review/$CI_COMMIT_REF_NAME', { name: 'review/$CI_COMMIT_REF_NAME',
......
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