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
27b25fe8
Commit
27b25fe8
authored
Mar 22, 2022
by
Michał Zając
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enforce schema validation for security reports
Changelog: changed EE: true
parent
e02fa0fd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
15 deletions
+112
-15
config/feature_flags/development/enforce_security_report_validation.yml
..._flags/development/enforce_security_report_validation.yml
+8
-0
ee/app/models/ee/ci/build.rb
ee/app/models/ee/ci/build.rb
+5
-1
ee/spec/models/ci/build_spec.rb
ee/spec/models/ci/build_spec.rb
+41
-9
ee/spec/services/security/store_grouped_scans_service_spec.rb
...pec/services/security/store_grouped_scans_service_spec.rb
+58
-5
No files found.
config/feature_flags/development/enforce_security_report_validation.yml
0 → 100644
View file @
27b25fe8
---
name
:
enforce_security_report_validation
introduced_by_url
:
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/351000
milestone
:
'
14.9'
type
:
development
group
:
group::threat insights
default_enabled
:
false
ee/app/models/ee/ci/build.rb
View file @
27b25fe8
...
...
@@ -183,7 +183,11 @@ module EE
end
def
validate_schema?
variables
[
VALIDATE_SCHEMA_VARIABLE_NAME
]
&
.
value
&
.
casecmp?
(
'true'
)
if
::
Feature
.
enabled?
(
:enforce_security_report_validation
,
project
)
true
else
variables
[
VALIDATE_SCHEMA_VARIABLE_NAME
]
&
.
value
&
.
casecmp?
(
'true'
)
end
end
private
...
...
ee/spec/models/ci/build_spec.rb
View file @
27b25fe8
...
...
@@ -738,23 +738,55 @@ RSpec.describe Ci::Build, :saas do
ci_build
.
yaml_variables
=
variables
end
context
'when the yaml variables does not have the configuration'
do
let
(
:variables
)
{
[]
}
context
'when enforce_security_report_validation is enabled'
do
before
do
stub_feature_flags
(
enforce_security_report_validation:
true
)
end
it
{
is_expected
.
to
be_falsey
}
context
'when the yaml variables does not have the configuration'
do
let
(
:variables
)
{
[]
}
it
{
is_expected
.
to
be_truthy
}
end
context
'when the yaml variables has the configuration'
do
context
'when the configuration is set as `false`'
do
let
(
:variables
)
{
[{
key:
'VALIDATE_SCHEMA'
,
value:
'false'
}]
}
it
{
is_expected
.
to
be_truthy
}
end
context
'when the configuration is set as `true`'
do
let
(
:variables
)
{
[{
key:
'VALIDATE_SCHEMA'
,
value:
'true'
}]
}
it
{
is_expected
.
to
be_truthy
}
end
end
end
context
'when the yaml variables has the configuration'
do
context
'when the configuration is set as `false`'
do
let
(
:variables
)
{
[{
key:
'VALIDATE_SCHEMA'
,
value:
'false'
}]
}
context
'when enforce_security_report_validation is disabled'
do
before
do
stub_feature_flags
(
enforce_security_report_validation:
false
)
end
context
'when the yaml variables does not have the configuration'
do
let
(
:variables
)
{
[]
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when the configuration is set as `true`'
do
let
(
:variables
)
{
[{
key:
'VALIDATE_SCHEMA'
,
value:
'true'
}]
}
context
'when the yaml variables has the configuration'
do
context
'when the configuration is set as `false`'
do
let
(
:variables
)
{
[{
key:
'VALIDATE_SCHEMA'
,
value:
'false'
}]
}
it
{
is_expected
.
to
be_truthy
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when the configuration is set as `true`'
do
let
(
:variables
)
{
[{
key:
'VALIDATE_SCHEMA'
,
value:
'true'
}]
}
it
{
is_expected
.
to
be_truthy
}
end
end
end
end
...
...
ee/spec/services/security/store_grouped_scans_service_spec.rb
View file @
27b25fe8
...
...
@@ -91,12 +91,65 @@ RSpec.describe Security::StoreGroupedScansService do
end
context
'when the artifacts are not dependency_scanning'
do
it
'calls the Security::StoreScanService with ordered artifacts'
do
store_scan_group
context
'when enforce_security_report_validation is enabled'
do
before
do
stub_feature_flags
(
enforce_security_report_validation:
true
)
end
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
artifact_1
,
empty_set
,
false
).
ordered
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
artifact_2
,
empty_set
,
true
).
ordered
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
artifact_3
,
empty_set
,
true
).
ordered
context
"and reports doesn't pass schema validation"
do
it
'calls the Security::StoreScanService with ordered artifacts'
do
store_scan_group
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
artifact_3
,
empty_set
,
false
).
ordered
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
artifact_2
,
empty_set
,
true
).
ordered
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
artifact_1
,
empty_set
,
true
).
ordered
end
end
context
"some of the reports don't pass schema validation"
do
let_it_be
(
:valid_artifact_1
)
{
create
(
:ee_ci_job_artifact
,
:dast_14_0_2
,
job:
create
(
:ee_ci_build
))
}
let_it_be
(
:valid_artifact_2
)
{
create
(
:ee_ci_job_artifact
,
:dast_14_0_2
,
job:
create
(
:ee_ci_build
))
}
let
(
:artifacts
)
{
[
valid_artifact_1
,
valid_artifact_2
,
artifact_1
]
}
it
'calls the Security::StoreScanService with correctly ordered artifacts'
do
store_scan_group
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
valid_artifact_1
,
empty_set
,
false
).
ordered
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
valid_artifact_2
,
empty_set
,
true
).
ordered
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
artifact_1
,
empty_set
,
true
).
ordered
end
end
context
'and report does pass schema validation'
do
let_it_be
(
:valid_artifact_1
)
{
create
(
:ee_ci_job_artifact
,
:dast_14_0_2
,
job:
create
(
:ee_ci_build
))
}
let_it_be
(
:valid_artifact_2
)
{
create
(
:ee_ci_job_artifact
,
:dast_14_0_2
,
job:
create
(
:ee_ci_build
))
}
let_it_be
(
:valid_artifact_3
)
{
create
(
:ee_ci_job_artifact
,
:dast_14_0_2
,
job:
create
(
:ee_ci_build
))
}
let
(
:artifacts
)
{
[
valid_artifact_1
,
valid_artifact_2
,
valid_artifact_3
]
}
it
'calls the Security::StoreScanService with ordered artifacts'
do
store_scan_group
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
valid_artifact_1
,
empty_set
,
false
).
ordered
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
valid_artifact_2
,
empty_set
,
true
).
ordered
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
valid_artifact_3
,
empty_set
,
true
).
ordered
end
end
end
context
'when enforce_security_report_validation is disabled'
do
before
do
stub_feature_flags
(
enforce_security_report_validation:
false
)
end
it
'calls the Security::StoreScanService with ordered artifacts'
do
store_scan_group
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
artifact_1
,
empty_set
,
false
).
ordered
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
artifact_2
,
empty_set
,
true
).
ordered
expect
(
Security
::
StoreScanService
).
to
have_received
(
:execute
).
with
(
artifact_3
,
empty_set
,
true
).
ordered
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