Commit 08272ec1 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Add validation of URL and validation of name

parent ba5bd3d1
......@@ -11,6 +11,11 @@ module Gitlab
validations do
validates :name, presence: true
validates :url,
length: { maximum: 255 },
allow_nil: true,
addressable_url: true
validate do
unless hash? || string?
errors.add(:config, 'should be a hash or a string')
......
......@@ -87,6 +87,19 @@ describe Gitlab::Ci::Config::Node::Environment do
end
end
context 'when variables are used for environment' do
let(:config) do
{ name: 'review/$CI_BUILD_REF_NAME',
url: 'https://$CI_BUILD_REF_NAME.review.gitlab.com' }
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
context 'when configuration is invalid' do
context 'when configuration is an array' do
let(:config) { ['env'] }
......@@ -121,5 +134,22 @@ describe Gitlab::Ci::Config::Node::Environment do
end
end
end
context 'when invalid URL is used' do
let(:config) { { name: 'test', url: 'invalid-example.gitlab.com' } }
describe '#valid?' do
it 'is not valid' do
expect(entry).not_to be_valid
end
end
describe '#errors?' do
it 'contains error about invalid URL' do
expect(entry.errors)
.to include "environment url must be a valid url"
end
end
end
end
end
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