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
380f63bf
Commit
380f63bf
authored
Oct 19, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve remote CI/CD config file extension validation
parent
7977a20b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
2 deletions
+54
-2
lib/gitlab/ci/config/external/file/base.rb
lib/gitlab/ci/config/external/file/base.rb
+2
-2
spec/lib/gitlab/ci/config/external/file/base_spec.rb
spec/lib/gitlab/ci/config/external/file/base_spec.rb
+52
-0
No files found.
lib/gitlab/ci/config/external/file/base.rb
View file @
380f63bf
...
@@ -10,7 +10,7 @@ module Gitlab
...
@@ -10,7 +10,7 @@ module Gitlab
attr_reader
:location
,
:opts
,
:errors
attr_reader
:location
,
:opts
,
:errors
YAML_WHITELIST_EXTENSION
=
/(yml|yaml)$/i
.
freeze
YAML_WHITELIST_EXTENSION
=
/
.+\.
(yml|yaml)$/i
.
freeze
def
initialize
(
location
,
opts
=
{})
def
initialize
(
location
,
opts
=
{})
@location
=
location
@location
=
location
...
@@ -21,7 +21,7 @@ module Gitlab
...
@@ -21,7 +21,7 @@ module Gitlab
end
end
def
invalid_extension?
def
invalid_extension?
!
location
.
match
(
YAML_WHITELIST_EXTENSION
)
!
::
File
.
basename
(
location
)
.
match
(
YAML_WHITELIST_EXTENSION
)
end
end
def
valid?
def
valid?
...
...
spec/lib/gitlab/ci/config/external/file/base_spec.rb
0 → 100644
View file @
380f63bf
# frozen_string_literal: true
require
'fast_spec_helper'
describe
Gitlab
::
Ci
::
Config
::
External
::
File
::
Base
do
subject
{
described_class
.
new
(
location
)
}
before
do
allow_any_instance_of
(
described_class
)
.
to
receive
(
:content
).
and_return
(
'key: value'
)
end
describe
'#valid?'
do
context
'when location is not a YAML file by extension'
do
let
(
:location
)
{
'some/file.txt'
}
it
{
is_expected
.
not_to
be_valid
}
end
context
'when location is not an invalid YAML extension'
do
let
(
:location
)
{
'some/file/.yml'
}
it
{
is_expected
.
not_to
be_valid
}
end
context
'when location is not an valid YAML extension'
do
let
(
:location
)
{
'some/file/config.yml'
}
it
{
is_expected
.
to
be_valid
}
end
context
'when location is not an valid YAML extension'
do
let
(
:location
)
{
'some/file/config.yaml'
}
it
{
is_expected
.
to
be_valid
}
end
context
'when there are YAML syntax errors'
do
let
(
:location
)
{
'some/file/config.yml'
}
before
do
allow_any_instance_of
(
described_class
)
.
to
receive
(
:content
).
and_return
(
'invalid_syntax'
)
end
it
'is not a valid file'
do
expect
(
subject
).
not_to
be_valid
expect
(
subject
.
error_message
).
to
match
/does not have valid YAML syntax/
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