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
1be6dd33
Commit
1be6dd33
authored
Jun 01, 2020
by
Maxime Orefice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate filename for json schema validator
parent
f89905ce
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
app/validators/json_schema_validator.rb
app/validators/json_schema_validator.rb
+4
-0
spec/validators/json_schema_validator_spec.rb
spec/validators/json_schema_validator_spec.rb
+10
-2
No files found.
app/validators/json_schema_validator.rb
View file @
1be6dd33
...
...
@@ -10,8 +10,12 @@
# end
#
class
JsonSchemaValidator
<
ActiveModel
::
EachValidator
FILENAME_ALLOWED
=
/\A[a-z0-9_-]*\Z/
.
freeze
FilenameError
=
Class
.
new
(
StandardError
)
def
initialize
(
options
)
raise
ArgumentError
,
"Expected 'filename' as an argument"
unless
options
[
:filename
]
raise
FilenameError
,
"Must be a valid 'filename'"
unless
options
[
:filename
].
match?
(
FILENAME_ALLOWED
)
super
(
options
)
end
...
...
spec/validators/json_schema_validator_spec.rb
View file @
1be6dd33
...
...
@@ -8,7 +8,7 @@ describe JsonSchemaValidator do
subject
{
validator
.
validate
(
build_report_result
)
}
context
'when file
_path
is set'
do
context
'when file
name
is set'
do
let
(
:validator
)
{
described_class
.
new
(
attributes:
[
:data
],
filename:
"build_report_result_data"
)
}
context
'when data is valid'
do
...
...
@@ -31,12 +31,20 @@ describe JsonSchemaValidator do
end
end
context
'when file
_path
is not set'
do
context
'when file
name
is not set'
do
let
(
:validator
)
{
described_class
.
new
(
attributes:
[
:data
])
}
it
'raises an ArgumentError'
do
expect
{
subject
}.
to
raise_error
(
ArgumentError
)
end
end
context
'when filename is invalid'
do
let
(
:validator
)
{
described_class
.
new
(
attributes:
[
:data
],
filename:
"invalid$filename"
)
}
it
'raises a FilenameError'
do
expect
{
subject
}.
to
raise_error
(
described_class
::
FilenameError
)
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