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
c5b67bc4
Commit
c5b67bc4
authored
Feb 14, 2022
by
Michał Zając
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve specs
parent
6ecfb5db
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
8 deletions
+42
-8
lib/gitlab/ci/parsers/security/validators/schema_validator.rb
...gitlab/ci/parsers/security/validators/schema_validator.rb
+2
-0
spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb
...b/ci/parsers/security/validators/schema_validator_spec.rb
+40
-8
No files found.
lib/gitlab/ci/parsers/security/validators/schema_validator.rb
View file @
c5b67bc4
...
@@ -7,6 +7,7 @@ module Gitlab
...
@@ -7,6 +7,7 @@ module Gitlab
module
Validators
module
Validators
class
SchemaValidator
class
SchemaValidator
SUPPORTED_VERSIONS
=
{
SUPPORTED_VERSIONS
=
{
cluster_image_scanning:
%w[14.0.4 14.0.5 14.0.6 14.1.0]
,
container_scanning:
%w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0]
,
container_scanning:
%w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0]
,
coverage_fuzzing:
%w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0]
,
coverage_fuzzing:
%w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0]
,
dast:
%w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0]
,
dast:
%w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0]
,
...
@@ -16,6 +17,7 @@ module Gitlab
...
@@ -16,6 +17,7 @@ module Gitlab
}.
freeze
}.
freeze
DEPRECATED_VERSIONS
=
{
DEPRECATED_VERSIONS
=
{
cluster_image_scanning:
%w[]
,
container_scanning:
%w[]
,
container_scanning:
%w[]
,
coverage_fuzzing:
%w[]
,
coverage_fuzzing:
%w[]
,
dast:
%w[]
,
dast:
%w[]
,
...
...
spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb
View file @
c5b67bc4
...
@@ -4,22 +4,54 @@ require 'spec_helper'
...
@@ -4,22 +4,54 @@ require 'spec_helper'
RSpec
.
describe
Gitlab
::
Ci
::
Parsers
::
Security
::
Validators
::
SchemaValidator
do
RSpec
.
describe
Gitlab
::
Ci
::
Parsers
::
Security
::
Validators
::
SchemaValidator
do
describe
'SUPPORTED_VERSIONS'
do
describe
'SUPPORTED_VERSIONS'
do
let
(
:schema_path
)
{
Rails
.
root
.
join
(
"lib"
,
"gitlab"
,
"ci"
,
"parsers"
,
"security"
,
"validators"
,
"schemas"
)
}
# This is not a stub, let is not accessible within context blocks
# rubocop:disable RSpec/LeakyConstantDeclaration
SCHEMA_PATH
=
Rails
.
root
.
join
(
"lib"
,
"gitlab"
,
"ci"
,
"parsers"
,
"security"
,
"validators"
,
"schemas"
)
# rubocop:enable RSpec/LeakyConstantDeclaration
it
'matches DEPRECATED_VERSIONS keys'
do
expect
(
described_class
::
SUPPORTED_VERSIONS
.
keys
).
to
eq
(
described_class
::
DEPRECATED_VERSIONS
.
keys
)
end
context
'files under SCHEMA_PATH are explicitly listed'
do
# We only care about the part that comes before report-format.json
# https://rubular.com/r/N8Juz7r8hYDYgD
filename_regex
=
/(?<report_type>[-\w]*)\-report-format.json/
versions
=
Dir
.
glob
(
File
.
join
(
SCHEMA_PATH
,
"*"
,
File
::
SEPARATOR
)).
map
{
|
path
|
path
.
split
(
"/"
).
last
}
versions
.
each
do
|
version
|
files
=
Dir
[
SCHEMA_PATH
.
join
(
version
,
"*.json"
)]
files
.
each
do
|
file
|
matches
=
filename_regex
.
match
(
file
)
report_type
=
matches
[
:report_type
].
tr
(
"-"
,
"_"
).
to_sym
it
"
#{
report_type
}
#{
version
}
"
do
expect
(
described_class
::
SUPPORTED_VERSIONS
[
report_type
]).
to
include
(
version
)
end
end
end
end
context
'every SUPPORTED_VERSION has a corresponding JSON file'
do
described_class
::
SUPPORTED_VERSIONS
.
each_key
do
|
report_type
|
described_class
::
SUPPORTED_VERSIONS
.
each_key
do
|
report_type
|
context
"
#{
report_type
}
"
do
let
(
:filename
)
{
"
#{
report_type
.
to_s
.
tr
(
"_"
,
"-"
)
}
-report-format.json"
}
let
(
:filename
)
{
"
#{
report_type
.
to_s
.
tr
(
"_"
,
"-"
)
}
-report-format.json"
}
described_class
::
SUPPORTED_VERSIONS
[
report_type
].
each
do
|
version
|
described_class
::
SUPPORTED_VERSIONS
[
report_type
].
each
do
|
version
|
context
"
#{
version
}
"
do
it
"
#{
report_type
}
#{
version
}
schema file is present"
do
it
"has a corresponding schema file present"
do
full_path
=
SCHEMA_PATH
.
join
(
version
,
filename
)
full_path
=
schema_path
.
join
(
version
,
filename
)
expect
(
File
.
file?
(
full_path
)).
to
be
true
expect
(
File
.
file?
(
full_path
)).
to
be
true
end
end
end
end
end
end
end
end
end
end
describe
'DEPRECATED_VERSIONS'
do
it
'matches SUPPORTED_VERSIONS keys'
do
expect
(
described_class
::
DEPRECATED_VERSIONS
.
keys
).
to
eq
(
described_class
::
SUPPORTED_VERSIONS
.
keys
)
end
end
end
using
RSpec
::
Parameterized
::
TableSyntax
using
RSpec
::
Parameterized
::
TableSyntax
...
...
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