summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-09-14 22:14:26 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-09-19 10:07:12 +0200
commit08272ec1513cbd565e5db5995a681c25e1f4544f (patch)
treecc0de5a65aeaece6725176ccf2fc128b632a6f1f
parentba5bd3d1d64b1f56c39e4ddd03270de6820b2f7b (diff)
downloadgitlab-ce-08272ec1513cbd565e5db5995a681c25e1f4544f.tar.gz
Add validation of URL and validation of name
-rw-r--r--lib/gitlab/ci/config/node/environment.rb5
-rw-r--r--spec/lib/gitlab/ci/config/node/environment_spec.rb30
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/gitlab/ci/config/node/environment.rb b/lib/gitlab/ci/config/node/environment.rb
index e2fb1ab131e..629c17e6250 100644
--- a/lib/gitlab/ci/config/node/environment.rb
+++ b/lib/gitlab/ci/config/node/environment.rb
@@ -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')
diff --git a/spec/lib/gitlab/ci/config/node/environment_spec.rb b/spec/lib/gitlab/ci/config/node/environment_spec.rb
index 27238f9c887..df453223da7 100644
--- a/spec/lib/gitlab/ci/config/node/environment_spec.rb
+++ b/spec/lib/gitlab/ci/config/node/environment_spec.rb
@@ -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