Commit f9b475c7 authored by Avielle Wolfe's avatar Avielle Wolfe Committed by Furkan Ayhan

Avoid exceptions from un-symbolizable job names

If `true` or `false` is used as a job name, it is interpreted by the
YAML parser as a boolean, which does not have the `to_sym` method. This
caused 500s when linting

Changelog: fixed
parent 90fa4293
...@@ -95,6 +95,9 @@ You can't use these keywords as job names: ...@@ -95,6 +95,9 @@ You can't use these keywords as job names:
- `variables` - `variables`
- `cache` - `cache`
- `include` - `include`
- `true`
- `false`
- `nil`
Job names must be 255 characters or less. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/342800) Job names must be 255 characters or less. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/342800)
in GitLab 14.5, [with a feature flag](../../administration/feature_flags.md) named `ci_validate_job_length`. in GitLab 14.5, [with a feature flag](../../administration/feature_flags.md) named `ci_validate_job_length`.
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
validate do validate do
each_unmatched_job do |name| each_unmatched_job do |name|
errors.add(name, 'config should implement a script: or a trigger: keyword') errors.add(name.to_s, 'config should implement a script: or a trigger: keyword')
end end
unless has_visible_job? unless has_visible_job?
......
...@@ -70,6 +70,14 @@ RSpec.describe Gitlab::Ci::Config::Entry::Jobs do ...@@ -70,6 +70,14 @@ RSpec.describe Gitlab::Ci::Config::Entry::Jobs do
it 'reports error' do it 'reports error' do
expect(entry.errors).to include 'jobs rspec config should implement a script: or a trigger: keyword' expect(entry.errors).to include 'jobs rspec config should implement a script: or a trigger: keyword'
end end
context 'when the job name cannot be cast directly to a symbol' do
let(:config) { { true => nil } }
it 'properly parses the job name without raising a NoMethodError' do
expect(entry.errors).to include 'jobs true config should implement a script: or a trigger: keyword'
end
end
end end
context 'when no visible jobs present' do context 'when no visible jobs present' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment