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
27691c6c
Commit
27691c6c
authored
Feb 17, 2022
by
Michał Zając
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify specs and constants
parent
bc090b98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
22 deletions
+15
-22
lib/gitlab/ci/parsers/security/validators/schema_validator.rb
...gitlab/ci/parsers/security/validators/schema_validator.rb
+10
-8
spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb
...b/ci/parsers/security/validators/schema_validator_spec.rb
+5
-14
No files found.
lib/gitlab/ci/parsers/security/validators/schema_validator.rb
View file @
27691c6c
...
...
@@ -28,15 +28,17 @@ module Gitlab
# These come from https://app.periscopedata.com/app/gitlab/895813/Secure-Scan-metrics?widget=12248944&udv=1385516
KNOWN_VERSIONS_TO_DEPRECATE
=
%w[0.1 1.0 1.0.0 1.2 1.3 10.0.0 12.1.0 13.1.0 2.0 2.1 2.1.0 2.3 2.3.0 2.4 3.0 3.0.0 3.0.6 3.13.2 V2.7.0]
.
freeze
VERSIONS_TO_DEPRECATE_IN_15_0
=
(
PREVIOUS_RELEASES
+
KNOWN_VERSIONS_TO_DEPRECATE
).
freeze
DEPRECATED_VERSIONS
=
{
cluster_image_scanning:
PREVIOUS_RELEASES
+
KNOWN_VERSIONS_TO_DEPRECATE
+
%w[]
,
container_scanning:
PREVIOUS_RELEASES
+
KNOWN_VERSIONS_TO_DEPRECATE
+
%w[]
,
coverage_fuzzing:
PREVIOUS_RELEASES
+
KNOWN_VERSIONS_TO_DEPRECATE
+
%w[]
,
dast:
PREVIOUS_RELEASES
+
KNOWN_VERSIONS_TO_DEPRECATE
+
%w[]
,
api_fuzzing:
PREVIOUS_RELEASES
+
KNOWN_VERSIONS_TO_DEPRECATE
+
%w[]
,
dependency_scanning:
PREVIOUS_RELEASES
+
KNOWN_VERSIONS_TO_DEPRECATE
+
%w[]
,
sast:
PREVIOUS_RELEASES
+
KNOWN_VERSIONS_TO_DEPRECATE
+
%w[]
,
secret_detection:
PREVIOUS_RELEASES
+
KNOWN_VERSIONS_TO_DEPRECATE
+
%w[]
cluster_image_scanning:
VERSIONS_TO_DEPRECATE_IN_15_0
,
container_scanning:
VERSIONS_TO_DEPRECATE_IN_15_0
,
coverage_fuzzing:
VERSIONS_TO_DEPRECATE_IN_15_0
,
dast:
VERSIONS_TO_DEPRECATE_IN_15_0
,
api_fuzzing:
VERSIONS_TO_DEPRECATE_IN_15_0
,
dependency_scanning:
VERSIONS_TO_DEPRECATE_IN_15_0
,
sast:
VERSIONS_TO_DEPRECATE_IN_15_0
,
secret_detection:
VERSIONS_TO_DEPRECATE_IN_15_0
}.
freeze
class
Schema
...
...
spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb
View file @
27691c6c
...
...
@@ -4,24 +4,21 @@ require 'spec_helper'
RSpec
.
describe
Gitlab
::
Ci
::
Parsers
::
Security
::
Validators
::
SchemaValidator
do
describe
'SUPPORTED_VERSIONS'
do
# 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
schema_path
=
Rails
.
root
.
join
(
"lib"
,
"gitlab"
,
"ci"
,
"parsers"
,
"security"
,
"validators"
,
"schemas"
)
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
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
=
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
=
Dir
[
schema_path
.
join
(
version
,
"*.json"
)]
files
.
each
do
|
file
|
matches
=
filename_regex
.
match
(
file
)
...
...
@@ -42,7 +39,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
described_class
::
SUPPORTED_VERSIONS
[
report_type
].
each
do
|
version
|
it
"
#{
report_type
}
#{
version
}
schema file is present"
do
filename
=
"
#{
report_type
.
to_s
.
tr
(
"_"
,
"-"
)
}
-report-format.json"
full_path
=
SCHEMA_PATH
.
join
(
version
,
filename
)
full_path
=
schema_path
.
join
(
version
,
filename
)
expect
(
File
.
file?
(
full_path
)).
to
be
true
end
end
...
...
@@ -50,12 +47,6 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
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
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:report_type
,
:expected_errors
,
:valid_data
)
do
...
...
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