Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
6d466733
Commit
6d466733
authored
Jul 18, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate allowed keys only in new CI config
parent
7cef4f19
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
19 deletions
+15
-19
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+0
-19
lib/gitlab/ci/config/node/job.rb
lib/gitlab/ci/config/node/job.rb
+5
-0
spec/lib/gitlab/ci/config/node/job_spec.rb
spec/lib/gitlab/ci/config/node/job_spec.rb
+10
-0
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
6d466733
...
@@ -4,15 +4,6 @@ module Ci
...
@@ -4,15 +4,6 @@ module Ci
include
Gitlab
::
Ci
::
Config
::
Node
::
LegacyValidationHelpers
include
Gitlab
::
Ci
::
Config
::
Node
::
LegacyValidationHelpers
DEFAULT_STAGE
=
'test'
ALLOWED_YAML_KEYS
=
[
:before_script
,
:after_script
,
:image
,
:services
,
:types
,
:stages
,
:variables
,
:cache
]
ALLOWED_JOB_KEYS
=
[
:tags
,
:script
,
:only
,
:except
,
:type
,
:image
,
:services
,
:allow_failure
,
:type
,
:stage
,
:when
,
:artifacts
,
:cache
,
:dependencies
,
:before_script
,
:after_script
,
:variables
,
:environment
]
ALLOWED_CACHE_KEYS
=
[
:key
,
:untracked
,
:paths
]
ALLOWED_ARTIFACTS_KEYS
=
[
:name
,
:untracked
,
:paths
,
:when
,
:expire_in
]
attr_reader
:path
,
:cache
,
:stages
attr_reader
:path
,
:cache
,
:stages
def
initialize
(
config
,
path
=
nil
)
def
initialize
(
config
,
path
=
nil
)
...
@@ -102,21 +93,11 @@ module Ci
...
@@ -102,21 +93,11 @@ module Ci
def
validate_job!
(
name
,
job
)
def
validate_job!
(
name
,
job
)
raise
ValidationError
,
"Unknown parameter:
#{
name
}
"
unless
job
.
is_a?
(
Hash
)
&&
job
.
has_key?
(
:script
)
raise
ValidationError
,
"Unknown parameter:
#{
name
}
"
unless
job
.
is_a?
(
Hash
)
&&
job
.
has_key?
(
:script
)
validate_job_keys!
(
name
,
job
)
validate_job_types!
(
name
,
job
)
validate_job_types!
(
name
,
job
)
validate_job_stage!
(
name
,
job
)
if
job
[
:stage
]
validate_job_stage!
(
name
,
job
)
if
job
[
:stage
]
validate_job_dependencies!
(
name
,
job
)
if
job
[
:dependencies
]
validate_job_dependencies!
(
name
,
job
)
if
job
[
:dependencies
]
end
end
def
validate_job_keys!
(
name
,
job
)
job
.
keys
.
each
do
|
key
|
unless
(
ALLOWED_JOB_KEYS
+
%i[name]
).
include?
key
raise
ValidationError
,
"
#{
name
}
job: unknown parameter
#{
key
}
"
end
end
end
def
validate_job_types!
(
name
,
job
)
def
validate_job_types!
(
name
,
job
)
if
job
[
:tags
]
&&
!
validate_array_of_strings
(
job
[
:tags
])
if
job
[
:tags
]
&&
!
validate_array_of_strings
(
job
[
:tags
])
raise
ValidationError
,
"
#{
name
}
job: tags parameter should be an array of strings"
raise
ValidationError
,
"
#{
name
}
job: tags parameter should be an array of strings"
...
...
lib/gitlab/ci/config/node/job.rb
View file @
6d466733
...
@@ -9,6 +9,11 @@ module Gitlab
...
@@ -9,6 +9,11 @@ module Gitlab
include
Configurable
include
Configurable
validations
do
validations
do
validates
:config
,
allowed_keys:
%i[tags script only except type image services allow_failure
type stage when artifacts cache dependencies before_script
after_script variables environment]
validates
:config
,
presence:
true
validates
:config
,
presence:
true
validates
:name
,
presence:
true
validates
:name
,
presence:
true
validates
:name
,
type:
Symbol
validates
:name
,
type:
Symbol
...
...
spec/lib/gitlab/ci/config/node/job_spec.rb
View file @
6d466733
...
@@ -46,6 +46,16 @@ describe Gitlab::Ci::Config::Node::Job do
...
@@ -46,6 +46,16 @@ describe Gitlab::Ci::Config::Node::Job do
end
end
end
end
end
end
context
'when unknown keys detected'
do
let
(
:config
)
{
{
unknown:
true
}
}
describe
'#valid'
do
it
'is not valid'
do
expect
(
entry
).
not_to
be_valid
end
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment