diff options
-rw-r--r-- | lib/ci/gitlab_ci_yaml_processor.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/artifacts.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/cache.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/validator.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/validators.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/artifacts_spec.rb | 21 |
6 files changed, 28 insertions, 29 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index ec85cf1bd3d..6901dfbd15d 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -106,7 +106,6 @@ module Ci validate_job_types!(name, job) validate_job_stage!(name, job) if job[:stage] - validate_job_artifacts!(name, job) if job[:artifacts] validate_job_dependencies!(name, job) if job[:dependencies] end @@ -142,14 +141,6 @@ module Ci end end - def validate_job_artifacts!(name, job) - job[:artifacts].keys.each do |key| - unless ALLOWED_ARTIFACTS_KEYS.include? key - raise ValidationError, "#{name} job: artifacts unknown parameter #{key}" - end - end - end - def validate_job_dependencies!(name, job) unless validate_array_of_strings(job[:dependencies]) raise ValidationError, "#{name} job: dependencies parameter should be an array of strings" diff --git a/lib/gitlab/ci/config/node/artifacts.rb b/lib/gitlab/ci/config/node/artifacts.rb index 7b3eb7e1992..2c301cf2917 100644 --- a/lib/gitlab/ci/config/node/artifacts.rb +++ b/lib/gitlab/ci/config/node/artifacts.rb @@ -13,6 +13,8 @@ module Gitlab validations do validates :config, type: Hash + validates :config, + allowed_keys: %i[name untracked paths when expire_in] with_options allow_nil: true do validates :name, type: String diff --git a/lib/gitlab/ci/config/node/cache.rb b/lib/gitlab/ci/config/node/cache.rb index cdf8ba2e35d..21d96b220b8 100644 --- a/lib/gitlab/ci/config/node/cache.rb +++ b/lib/gitlab/ci/config/node/cache.rb @@ -8,6 +8,10 @@ module Gitlab class Cache < Entry include Configurable + validations do + validates :config, allowed_keys: %i[key untracked paths] + end + node :key, Node::Key, description: 'Cache key used to define a cache affinity.' @@ -16,10 +20,6 @@ module Gitlab node :paths, Node::Paths, description: 'Specify which paths should be cached across builds.' - - validations do - validates :config, allowed_keys: true - end end end end diff --git a/lib/gitlab/ci/config/node/validator.rb b/lib/gitlab/ci/config/node/validator.rb index ca000f245aa..43c7e102b50 100644 --- a/lib/gitlab/ci/config/node/validator.rb +++ b/lib/gitlab/ci/config/node/validator.rb @@ -21,12 +21,6 @@ module Gitlab 'Validator' end - def unknown_keys - return [] unless config.is_a?(Hash) - - config.keys - @node.class.nodes.keys - end - private def location @@ -35,7 +29,7 @@ module Gitlab end def key_name - if key.blank? || key.nil? + if key.blank? @node.class.name.demodulize.underscore.humanize else key diff --git a/lib/gitlab/ci/config/node/validators.rb b/lib/gitlab/ci/config/node/validators.rb index 5568be80166..b43a0bc0bab 100644 --- a/lib/gitlab/ci/config/node/validators.rb +++ b/lib/gitlab/ci/config/node/validators.rb @@ -5,10 +5,11 @@ module Gitlab module Validators class AllowedKeysValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - if record.unknown_keys.any? - unknown_list = record.unknown_keys.join(', ') - record.errors.add(:config, - "contains unknown keys: #{unknown_list}") + unknown_keys = record.config.try(:keys).to_a - options[:in] + + if unknown_keys.any? + record.errors.add(:config, 'contains unknown keys: ' + + unknown_keys.join(', ')) end end end diff --git a/spec/lib/gitlab/ci/config/node/artifacts_spec.rb b/spec/lib/gitlab/ci/config/node/artifacts_spec.rb index 4973f7d599a..418a88cabac 100644 --- a/spec/lib/gitlab/ci/config/node/artifacts_spec.rb +++ b/spec/lib/gitlab/ci/config/node/artifacts_spec.rb @@ -21,12 +21,23 @@ describe Gitlab::Ci::Config::Node::Artifacts do end context 'when entry value is not correct' do - let(:config) { { name: 10 } } - describe '#errors' do - it 'saves errors' do - expect(entry.errors) - .to include 'artifacts name should be a string' + context 'when value of attribute is invalid' do + let(:config) { { name: 10 } } + + it 'reports error' do + expect(entry.errors) + .to include 'artifacts name should be a string' + end + end + + context 'when there is uknown key' do + let(:config) { { test: 100 } } + + it 'reports error' do + expect(entry.errors) + .to include 'artifacts config contains unknown keys: test' + end end end end |