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
f5297df3
Commit
f5297df3
authored
Apr 06, 2022
by
Michał Zając
Committed by
Thiago Figueiró
Apr 13, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log scanner id and version
parent
7308d22c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
10 deletions
+87
-10
lib/gitlab/ci/parsers/security/common.rb
lib/gitlab/ci/parsers/security/common.rb
+7
-1
lib/gitlab/ci/parsers/security/validators/schema_validator.rb
...gitlab/ci/parsers/security/validators/schema_validator.rb
+5
-2
spec/lib/gitlab/ci/parsers/security/common_spec.rb
spec/lib/gitlab/ci/parsers/security/common_spec.rb
+29
-3
spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb
...b/ci/parsers/security/validators/schema_validator_spec.rb
+46
-4
No files found.
lib/gitlab/ci/parsers/security/common.rb
View file @
f5297df3
...
@@ -72,7 +72,13 @@ module Gitlab
...
@@ -72,7 +72,13 @@ module Gitlab
end
end
def
schema_validator
def
schema_validator
@schema_validator
||=
::
Gitlab
::
Ci
::
Parsers
::
Security
::
Validators
::
SchemaValidator
.
new
(
report
.
type
,
report_data
,
report
.
version
,
project:
@project
)
@schema_validator
||=
::
Gitlab
::
Ci
::
Parsers
::
Security
::
Validators
::
SchemaValidator
.
new
(
report
.
type
,
report_data
,
report
.
version
,
project:
@project
,
scanner:
top_level_scanner
)
end
end
def
report_data
def
report_data
...
...
lib/gitlab/ci/parsers/security/validators/schema_validator.rb
View file @
f5297df3
...
@@ -86,11 +86,12 @@ module Gitlab
...
@@ -86,11 +86,12 @@ module Gitlab
end
end
end
end
def
initialize
(
report_type
,
report_data
,
report_version
=
nil
,
project:
nil
)
def
initialize
(
report_type
,
report_data
,
report_version
=
nil
,
project:
nil
,
scanner:
nil
)
@report_type
=
report_type
&
.
to_sym
@report_type
=
report_type
&
.
to_sym
@report_data
=
report_data
@report_data
=
report_data
@report_version
=
report_version
@report_version
=
report_version
@project
=
project
@project
=
project
@scanner
=
scanner
@errors
=
[]
@errors
=
[]
@warnings
=
[]
@warnings
=
[]
@deprecation_warnings
=
[]
@deprecation_warnings
=
[]
...
@@ -137,7 +138,9 @@ module Gitlab
...
@@ -137,7 +138,9 @@ module Gitlab
security_report_type:
report_type
,
security_report_type:
report_type
,
security_report_version:
report_version
,
security_report_version:
report_version
,
project_id:
@project
.
id
,
project_id:
@project
.
id
,
security_report_failure:
problem_type
security_report_failure:
problem_type
,
security_report_scanner_id:
@scanner
&
.
dig
(
'id'
),
security_report_scanner_version:
@scanner
&
.
dig
(
'version'
)
)
)
end
end
...
...
spec/lib/gitlab/ci/parsers/security/common_spec.rb
View file @
f5297df3
...
@@ -4,6 +4,18 @@ require 'spec_helper'
...
@@ -4,6 +4,18 @@ require 'spec_helper'
RSpec
.
describe
Gitlab
::
Ci
::
Parsers
::
Security
::
Common
do
RSpec
.
describe
Gitlab
::
Ci
::
Parsers
::
Security
::
Common
do
describe
'#parse!'
do
describe
'#parse!'
do
let_it_be
(
:scanner_data
)
do
{
scan:
{
scanner:
{
id:
"gemnasium"
,
name:
"Gemnasium"
,
version:
"2.1.0"
}
}
}
end
where
(
vulnerability_finding_signatures_enabled:
[
true
,
false
])
where
(
vulnerability_finding_signatures_enabled:
[
true
,
false
])
with_them
do
with_them
do
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
...
@@ -30,7 +42,9 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do
...
@@ -30,7 +42,9 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do
describe
'schema validation'
do
describe
'schema validation'
do
let
(
:validator_class
)
{
Gitlab
::
Ci
::
Parsers
::
Security
::
Validators
::
SchemaValidator
}
let
(
:validator_class
)
{
Gitlab
::
Ci
::
Parsers
::
Security
::
Validators
::
SchemaValidator
}
let
(
:parser
)
{
described_class
.
new
(
'{}'
,
report
,
vulnerability_finding_signatures_enabled
,
validate:
validate
)
}
let
(
:data
)
{
{}.
merge
(
scanner_data
)
}
let
(
:json_data
)
{
data
.
to_json
}
let
(
:parser
)
{
described_class
.
new
(
json_data
,
report
,
vulnerability_finding_signatures_enabled
,
validate:
validate
)
}
subject
(
:parse_report
)
{
parser
.
parse!
}
subject
(
:parse_report
)
{
parser
.
parse!
}
...
@@ -57,7 +71,13 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do
...
@@ -57,7 +71,13 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do
it
'instantiates the validator with correct params'
do
it
'instantiates the validator with correct params'
do
parse_report
parse_report
expect
(
validator_class
).
to
have_received
(
:new
).
with
(
report
.
type
,
{},
report
.
version
,
project:
pipeline
.
project
)
expect
(
validator_class
).
to
have_received
(
:new
).
with
(
report
.
type
,
data
.
deep_stringify_keys
,
report
.
version
,
project:
pipeline
.
project
,
scanner:
data
.
dig
(
:scan
,
:scanner
).
deep_stringify_keys
)
end
end
context
'when the report data is not valid according to the schema'
do
context
'when the report data is not valid according to the schema'
do
...
@@ -119,7 +139,13 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do
...
@@ -119,7 +139,13 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do
it
'instantiates the validator with correct params'
do
it
'instantiates the validator with correct params'
do
parse_report
parse_report
expect
(
validator_class
).
to
have_received
(
:new
).
with
(
report
.
type
,
{},
report
.
version
,
project:
pipeline
.
project
)
expect
(
validator_class
).
to
have_received
(
:new
).
with
(
report
.
type
,
data
.
deep_stringify_keys
,
report
.
version
,
project:
pipeline
.
project
,
scanner:
data
.
dig
(
:scan
,
:scanner
).
deep_stringify_keys
)
end
end
context
'when the report data is not valid according to the schema'
do
context
'when the report data is not valid according to the schema'
do
...
...
spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb
View file @
f5297df3
...
@@ -5,7 +5,15 @@ require 'spec_helper'
...
@@ -5,7 +5,15 @@ require 'spec_helper'
RSpec
.
describe
Gitlab
::
Ci
::
Parsers
::
Security
::
Validators
::
SchemaValidator
do
RSpec
.
describe
Gitlab
::
Ci
::
Parsers
::
Security
::
Validators
::
SchemaValidator
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let
(
:validator
)
{
described_class
.
new
(
report_type
,
report_data
,
report_version
,
project:
project
)
}
let
(
:scanner
)
do
{
'id'
=>
'gemnasium'
,
'name'
=>
'Gemnasium'
,
'version'
=>
'2.1.0'
}
end
let
(
:validator
)
{
described_class
.
new
(
report_type
,
report_data
,
report_version
,
project:
project
,
scanner:
scanner
)
}
describe
'SUPPORTED_VERSIONS'
do
describe
'SUPPORTED_VERSIONS'
do
schema_path
=
Rails
.
root
.
join
(
"lib"
,
"gitlab"
,
"ci"
,
"parsers"
,
"security"
,
"validators"
,
"schemas"
)
schema_path
=
Rails
.
root
.
join
(
"lib"
,
"gitlab"
,
"ci"
,
"parsers"
,
"security"
,
"validators"
,
"schemas"
)
...
@@ -84,7 +92,9 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
...
@@ -84,7 +92,9 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
security_report_type:
report_type
,
security_report_type:
report_type
,
security_report_version:
report_version
,
security_report_version:
report_version
,
project_id:
project
.
id
,
project_id:
project
.
id
,
security_report_failure:
'schema_validation_fails'
security_report_failure:
'schema_validation_fails'
,
security_report_scanner_id:
'gemnasium'
,
security_report_scanner_version:
'2.1.0'
)
)
subject
subject
...
@@ -112,7 +122,9 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
...
@@ -112,7 +122,9 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
security_report_type:
report_type
,
security_report_type:
report_type
,
security_report_version:
report_version
,
security_report_version:
report_version
,
project_id:
project
.
id
,
project_id:
project
.
id
,
security_report_failure:
'using_deprecated_schema_version'
security_report_failure:
'using_deprecated_schema_version'
,
security_report_scanner_id:
'gemnasium'
,
security_report_scanner_version:
'2.1.0'
)
)
subject
subject
...
@@ -175,7 +187,9 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
...
@@ -175,7 +187,9 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
security_report_type:
report_type
,
security_report_type:
report_type
,
security_report_version:
report_version
,
security_report_version:
report_version
,
project_id:
project
.
id
,
project_id:
project
.
id
,
security_report_failure:
'using_unsupported_schema_version'
security_report_failure:
'using_unsupported_schema_version'
,
security_report_scanner_id:
'gemnasium'
,
security_report_scanner_version:
'2.1.0'
)
)
subject
subject
...
@@ -189,6 +203,34 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
...
@@ -189,6 +203,34 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
}
}
end
end
context
'and scanner information is empty'
do
let
(
:scanner
)
{
{}
}
it
'logs related information'
do
expect
(
Gitlab
::
AppLogger
).
to
receive
(
:info
).
with
(
message:
"security report schema validation problem"
,
security_report_type:
report_type
,
security_report_version:
report_version
,
project_id:
project
.
id
,
security_report_failure:
'schema_validation_fails'
,
security_report_scanner_id:
nil
,
security_report_scanner_version:
nil
)
expect
(
Gitlab
::
AppLogger
).
to
receive
(
:info
).
with
(
message:
"security report schema validation problem"
,
security_report_type:
report_type
,
security_report_version:
report_version
,
project_id:
project
.
id
,
security_report_failure:
'using_unsupported_schema_version'
,
security_report_scanner_id:
nil
,
security_report_scanner_version:
nil
)
subject
end
end
it
{
is_expected
.
to
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
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