From 6bd67f5212de739b3016b0941853ce42f523a0f1 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon <grzesiek.bizon@gmail.com> Date: Tue, 7 Jun 2016 12:48:26 +0200 Subject: [PATCH] Do not process new Ci config entry when invalid --- lib/gitlab/ci/config/node/entry.rb | 8 ++++++-- spec/lib/gitlab/ci/config/node/global_spec.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/ci/config/node/entry.rb b/lib/gitlab/ci/config/node/entry.rb index e2afeb1b3cf..c07e7cf652e 100644 --- a/lib/gitlab/ci/config/node/entry.rb +++ b/lib/gitlab/ci/config/node/entry.rb @@ -16,10 +16,14 @@ module Gitlab keys.each_key do |key| instance_variable_set("@#{key}", Null.new(nil, root, self)) end + + unless leaf? || value.is_a?(Hash) + @errors << 'should be a configuration entry with hash value' + end end def process! - return if leaf? + return if leaf? || !valid? keys.each do |key, entry_class| next unless @value.has_key?(key) @@ -42,7 +46,7 @@ module Gitlab end def leaf? - keys.none? # TODO || !@value.is_a?(Hash) + keys.none? end def keys diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index c920dd3584c..f277c457a3b 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -58,4 +58,16 @@ describe Gitlab::Ci::Config::Node::Global do end end end + + context 'when value is not a hash' do + let(:hash) { [] } + + before { global.process! } + + describe '#valid?' do + it 'is not valid' do + expect(global).not_to be_valid + end + end + end end -- GitLab