summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/gitlab_ci_yaml_processor.rb7
-rw-r--r--spec/lib/gitlab_ci_yaml_processor_spec.rb15
2 files changed, 17 insertions, 5 deletions
diff --git a/lib/gitlab_ci_yaml_processor.rb b/lib/gitlab_ci_yaml_processor.rb
index e1da311..b685867 100644
--- a/lib/gitlab_ci_yaml_processor.rb
+++ b/lib/gitlab_ci_yaml_processor.rb
@@ -46,8 +46,9 @@ class GitlabCiYamlProcessor
@variables = @config[:variables] || {}
@config.except!(*ALLOWED_YAML_KEYS)
+ # anything that doesn't have script is considered as unknown
@config.each do |name, param|
- raise ValidationError, "Unknown parameter: #{name}" unless param.is_a?(Hash)
+ raise ValidationError, "Unknown parameter: #{name}" unless param.is_a?(Hash) && param.has_key?(:script)
end
unless @config.values.any?{|job| job.is_a?(Hash)}
@@ -148,6 +149,10 @@ class GitlabCiYamlProcessor
end
end
+ if !job[:script].is_a?(String) && !validate_array_of_strings(job[:script])
+ raise ValidationError, "#{name}: script should be a string or an array of a strings"
+ end
+
if job[:stage]
unless job[:stage].is_a?(String) && job[:stage].in?(stages)
raise ValidationError, "#{name}: stage parameter should be #{stages.join(", ")}"
diff --git a/spec/lib/gitlab_ci_yaml_processor_spec.rb b/spec/lib/gitlab_ci_yaml_processor_spec.rb
index 5b9a4f1..ed3d4e8 100644
--- a/spec/lib/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/gitlab_ci_yaml_processor_spec.rb
@@ -176,7 +176,7 @@ describe GitlabCiYamlProcessor do
end
it "returns errors if tags parameter is invalid" do
- config = YAML.dump({rspec: {tags: "mysql"}})
+ config = YAML.dump({rspec: {script: "test", tags: "mysql"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: tags parameter should be an array of strings")
@@ -197,7 +197,7 @@ describe GitlabCiYamlProcessor do
end
it "returns errors if job image parameter is invalid" do
- config = YAML.dump({rspec: {image: ["test"]}})
+ config = YAML.dump({rspec: {script: "test", image: ["test"]}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: image should be a string")
@@ -218,14 +218,14 @@ describe GitlabCiYamlProcessor do
end
it "returns errors if job services parameter is not an array" do
- config = YAML.dump({rspec: {services: "test"}})
+ config = YAML.dump({rspec: {script: "test", services: "test"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
end
it "returns errors if job services parameter is not an array of strings" do
- config = YAML.dump({rspec: {services: [10, "test"]}})
+ config = YAML.dump({rspec: {script: "test", services: [10, "test"]}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
@@ -238,6 +238,13 @@ describe GitlabCiYamlProcessor do
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
end
+ it "returns errors if there are unknown parameters that are hashes, but doesn't have a script" do
+ config = YAML.dump({extra: {services: "test"}})
+ expect do
+ GitlabCiYamlProcessor.new(config)
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
+ end
+
it "returns errors if there is no any jobs defined" do
config = YAML.dump({before_script: ["bundle update"]})
expect do