fix(gitlab-ci-config): allow strings in the 'include' keyword

This fix is a followup to !24098 which introduced a validation of the
`include:` keyword of a gitlab-ci configuration file when triggered
from /ci/lint API calls.

However, there was a test case missing: the case of a single string as
value. I have added a test case for that which shows that the code was
not validating it correctly.

This commit fixes that to allow all `include:` valid inputs.
This commit is contained in:
Paul 🐻 2019-04-05 06:44:33 +00:00 committed by Grzegorz Bizon
parent 48022ab3e8
commit 9f36097db2
4 changed files with 22 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
title: Fix single string values for the 'include' keyword validation of gitlab-ci.yml.
merge_request: 26998
author: Paul Bonaud (@paulrbr)
type: fixed

View File

@ -11,7 +11,7 @@ module Gitlab
include ::Gitlab::Config::Entry::Validatable
validations do
validates :config, type: Array
validates :config, array_or_string: true
end
def self.aspects

View File

@ -54,6 +54,14 @@ module Gitlab
end
end
class ArrayOrStringValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value.is_a?(Array) || value.is_a?(String)
record.errors.add(attribute, 'should be an array or a string')
end
end
end
class BooleanValidator < ActiveModel::EachValidator
include LegacyValidationHelpers

View File

@ -615,6 +615,14 @@ module Gitlab
subject { Gitlab::Ci::YamlProcessor.new(YAML.dump(config), opts) }
context "when validating a ci config file with no project context" do
context "when a single string is provided" do
let(:include_content) { "/local.gitlab-ci.yml" }
it "does not return any error" do
expect { subject }.not_to raise_error
end
end
context "when an array is provided" do
let(:include_content) { ["/local.gitlab-ci.yml"] }