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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
4cc80837
Commit
4cc80837
authored
Oct 01, 2021
by
Furkan Ayhan
Committed by
Dylan Griffith
Oct 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix when include has rules with invalid rule
parent
b5247dec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
1 deletion
+47
-1
lib/gitlab/ci/config/external/rules.rb
lib/gitlab/ci/config/external/rules.rb
+16
-0
spec/lib/gitlab/ci/config/external/processor_spec.rb
spec/lib/gitlab/ci/config/external/processor_spec.rb
+12
-0
spec/lib/gitlab/ci/config/external/rules_spec.rb
spec/lib/gitlab/ci/config/external/rules_spec.rb
+19
-1
No files found.
lib/gitlab/ci/config/external/rules.rb
View file @
4cc80837
...
@@ -5,7 +5,13 @@ module Gitlab
...
@@ -5,7 +5,13 @@ module Gitlab
class
Config
class
Config
module
External
module
External
class
Rules
class
Rules
ALLOWED_KEYS
=
Entry
::
Include
::
Rules
::
Rule
::
ALLOWED_KEYS
InvalidIncludeRulesError
=
Class
.
new
(
Mapper
::
Error
)
def
initialize
(
rule_hashes
)
def
initialize
(
rule_hashes
)
validate
(
rule_hashes
)
@rule_list
=
Build
::
Rules
::
Rule
.
fabricate_list
(
rule_hashes
)
@rule_list
=
Build
::
Rules
::
Rule
.
fabricate_list
(
rule_hashes
)
end
end
...
@@ -19,6 +25,16 @@ module Gitlab
...
@@ -19,6 +25,16 @@ module Gitlab
@rule_list
.
find
{
|
rule
|
rule
.
matches?
(
nil
,
context
)
}
@rule_list
.
find
{
|
rule
|
rule
.
matches?
(
nil
,
context
)
}
end
end
def
validate
(
rule_hashes
)
return
unless
rule_hashes
.
is_a?
(
Array
)
rule_hashes
.
each
do
|
rule_hash
|
next
if
(
rule_hash
.
keys
-
ALLOWED_KEYS
).
empty?
raise
InvalidIncludeRulesError
,
"invalid include rule:
#{
rule_hash
}
"
end
end
Result
=
Struct
.
new
(
:result
)
do
Result
=
Struct
.
new
(
:result
)
do
def
pass?
def
pass?
!!
result
!!
result
...
...
spec/lib/gitlab/ci/config/external/processor_spec.rb
View file @
4cc80837
...
@@ -402,5 +402,17 @@ RSpec.describe Gitlab::Ci::Config::External::Processor do
...
@@ -402,5 +402,17 @@ RSpec.describe Gitlab::Ci::Config::External::Processor do
expect
(
output
.
keys
).
to
match_array
([
:image
,
:my_build
,
:my_test
])
expect
(
output
.
keys
).
to
match_array
([
:image
,
:my_build
,
:my_test
])
end
end
end
end
context
'when rules defined'
do
context
'when a rule is invalid'
do
let
(
:values
)
do
{
include:
[{
local:
'builds.yml'
,
rules:
[{
exists:
[
'$MY_VAR'
]
}]
}]
}
end
it
'raises IncludeError'
do
expect
{
subject
}.
to
raise_error
(
described_class
::
IncludeError
,
/invalid include rule/
)
end
end
end
end
end
end
end
spec/lib/gitlab/ci/config/external/rules_spec.rb
View file @
4cc80837
...
@@ -16,7 +16,7 @@ RSpec.describe Gitlab::Ci::Config::External::Rules do
...
@@ -16,7 +16,7 @@ RSpec.describe Gitlab::Ci::Config::External::Rules do
it
{
is_expected
.
to
eq
(
true
)
}
it
{
is_expected
.
to
eq
(
true
)
}
end
end
context
'when there is a rule'
do
context
'when there is a rule
with if
'
do
let
(
:rule_hashes
)
{
[{
if:
'$MY_VAR == "hello"'
}]
}
let
(
:rule_hashes
)
{
[{
if:
'$MY_VAR == "hello"'
}]
}
context
'when the rule matches'
do
context
'when the rule matches'
do
...
@@ -31,5 +31,23 @@ RSpec.describe Gitlab::Ci::Config::External::Rules do
...
@@ -31,5 +31,23 @@ RSpec.describe Gitlab::Ci::Config::External::Rules do
it
{
is_expected
.
to
eq
(
false
)
}
it
{
is_expected
.
to
eq
(
false
)
}
end
end
end
end
context
'when there is a rule with if and when'
do
let
(
:rule_hashes
)
{
[{
if:
'$MY_VAR == "hello"'
,
when:
'on_success'
}]
}
it
'raises an error'
do
expect
{
result
}.
to
raise_error
(
described_class
::
InvalidIncludeRulesError
,
'invalid include rule: {:if=>"$MY_VAR == \"hello\"", :when=>"on_success"}'
)
end
end
context
'when there is a rule with exists'
do
let
(
:rule_hashes
)
{
[{
exists:
[
'$MY_VAR'
]
}]
}
it
'raises an error'
do
expect
{
result
}.
to
raise_error
(
described_class
::
InvalidIncludeRulesError
,
'invalid include rule: {:exists=>["$MY_VAR"]}'
)
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