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
fd8678ff
Commit
fd8678ff
authored
Feb 03, 2020
by
Tetiana Chupryna
Committed by
Shinya Maeda
Feb 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add license_scanning factory
Add tests for license_scanning
parent
bd3f5d88
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
126 additions
and
18 deletions
+126
-18
ee/app/models/ee/ci/job_artifact.rb
ee/app/models/ee/ci/job_artifact.rb
+7
-0
ee/app/models/ee/ci/pipeline.rb
ee/app/models/ee/ci/pipeline.rb
+9
-6
ee/app/models/ee/merge_request.rb
ee/app/models/ee/merge_request.rb
+1
-1
ee/spec/factories/ci/builds.rb
ee/spec/factories/ci/builds.rb
+1
-1
ee/spec/factories/ci/pipelines.rb
ee/spec/factories/ci/pipelines.rb
+1
-1
ee/spec/factories/merge_requests.rb
ee/spec/factories/merge_requests.rb
+12
-0
ee/spec/models/ci/pipeline_spec.rb
ee/spec/models/ci/pipeline_spec.rb
+71
-2
ee/spec/models/ee/ci/job_artifact_spec.rb
ee/spec/models/ee/ci/job_artifact_spec.rb
+16
-0
ee/spec/models/merge_request_spec.rb
ee/spec/models/merge_request_spec.rb
+8
-7
No files found.
ee/app/models/ee/ci/job_artifact.rb
View file @
fd8678ff
...
...
@@ -50,6 +50,13 @@ module EE
scope
:metrics_reports
,
->
do
with_file_types
(
METRICS_REPORT_FILE_TYPES
)
end
def
self
.
associated_file_types_for
(
file_type
)
return
unless
file_types
.
include?
(
file_type
)
return
LICENSE_SCANNING_REPORT_FILE_TYPES
if
LICENSE_SCANNING_REPORT_FILE_TYPES
.
include?
(
file_type
)
[
file_type
]
end
end
def
log_geo_deleted_event
...
...
ee/app/models/ee/ci/pipeline.rb
View file @
fd8678ff
...
...
@@ -46,6 +46,7 @@ module EE
dast:
%i[dast]
,
performance:
%i[merge_request_performance_metrics]
,
license_management:
%i[license_management]
,
license_scanning:
%i[license_management]
,
metrics:
%i[metrics_reports]
}.
freeze
...
...
@@ -107,21 +108,23 @@ module EE
def
batch_lookup_report_artifact_for_file_type
(
file_type
)
return
unless
available_licensed_report_type?
(
file_type
)
latest_report_artifacts
[
file_type
.
to_s
]
&
.
last
latest_report_artifacts
.
values_at
(
*::
Ci
::
JobArtifact
.
associated_file_types_for
(
file_type
.
to_s
))
.
flatten
.
compact
.
last
end
def
any_report_artifact_for_type
(
file_type
)
report_artifact_for_file_type
(
file_type
)
end
def
report_artifact_for_file_type
(
file_type
)
return
unless
available_licensed_report_type?
(
file_type
)
job_artifacts
.
where
(
file_type:
::
Ci
::
JobArtifact
.
file_types
[
file_type
]).
last
end
def
expose_license_scanning_data?
any_report_artifact_for_type
(
:license_management
)
return
unless
available_licensed_report_type?
(
:license_management
)
batch_lookup_report_artifact_for_file_type
(
:license_scanning
).
present?
end
def
security_reports
...
...
ee/app/models/ee/merge_request.rb
View file @
fd8678ff
...
...
@@ -185,7 +185,7 @@ module EE
container_scanning:
report_type_enabled?
(
:container_scanning
),
dast:
report_type_enabled?
(
:dast
),
dependency_scanning:
report_type_enabled?
(
:dependency_scanning
),
license_management:
report_type_enabled?
(
:license_
management
)
license_management:
report_type_enabled?
(
:license_
scanning
)
}
end
...
...
ee/spec/factories/ci/builds.rb
View file @
fd8678ff
...
...
@@ -6,7 +6,7 @@ FactoryBot.define do
failure_reason
{
Ci
::
Build
.
failure_reasons
[
:protected_environment_failure
]
}
end
%i[
sast codequality dependency_scanning container_scanning dast performance license_managemen
t]
.
each
do
|
report_type
|
%i[
codequality container_scanning dast dependency_scanning license_management license_scanning performance sas
t]
.
each
do
|
report_type
|
trait
"legacy_
#{
report_type
}
"
.
to_sym
do
success
artifacts
...
...
ee/spec/factories/ci/pipelines.rb
View file @
fd8678ff
...
...
@@ -7,7 +7,7 @@ FactoryBot.define do
config_source
{
:webide_source
}
end
%i[
license_management dependency_list dependency_scanning sast dast container_scanning
]
.
each
do
|
report_type
|
%i[
container_scanning dast dependency_list dependency_scanning license_management license_scanning sast
]
.
each
do
|
report_type
|
trait
"with_
#{
report_type
}
_report"
.
to_sym
do
status
{
:success
}
...
...
ee/spec/factories/merge_requests.rb
View file @
fd8678ff
...
...
@@ -85,6 +85,18 @@ FactoryBot.define do
end
end
trait
:with_license_scanning_reports
do
after
(
:build
)
do
|
merge_request
|
merge_request
.
head_pipeline
=
build
(
:ee_ci_pipeline
,
:success
,
:with_license_scanning_report
,
project:
merge_request
.
source_project
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
)
end
end
trait
:with_container_scanning_reports
do
after
(
:build
)
do
|
merge_request
|
merge_request
.
head_pipeline
=
build
(
...
...
ee/spec/models/ci/pipeline_spec.rb
View file @
fd8678ff
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
describe
Ci
::
Pipeline
do
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
...
...
@@ -117,7 +119,60 @@ describe Ci::Pipeline do
end
end
describe
'#report_artifact_for_file_type'
do
describe
'#batch_lookup_report_artifact_for_file_type'
do
subject
(
:artifact
)
{
pipeline
.
batch_lookup_report_artifact_for_file_type
(
file_type
)
}
let!
(
:build
)
{
create
(
:ee_ci_build
,
artifact_type
,
:success
,
pipeline:
pipeline
)
}
context
'with security report artifact'
do
let!
(
:build
)
{
create
(
:ee_ci_build
,
:dependency_scanning
,
:success
,
pipeline:
pipeline
)
}
let
(
:file_type
)
{
:dependency_scanning
}
before
do
stub_licensed_features
(
dependency_scanning:
true
)
end
it
'returns right kind of artifacts'
do
expect
(
artifact
.
file_type
).
to
eq
file_type
.
to_s
end
context
'when looking for other type of artifact'
do
let
(
:file_type
)
{
:codequality
}
it
'returns nothing'
do
is_expected
.
to
be_nil
end
end
end
context
'with license compliance artifact'
do
before
do
stub_licensed_features
(
license_management:
true
)
end
[
:license_management
,
:license_scanning
].
each
do
|
artifact_type
|
let!
(
:build
)
{
create
(
:ee_ci_build
,
artifact_type
,
:success
,
pipeline:
pipeline
)
}
context
'when looking for license_scanning'
do
let
(
:file_type
)
{
:license_scanning
}
it
'returns artifact'
do
is_expected
.
to
be_kind_of
Ci
::
JobArtifact
end
end
context
'when looking for license_management'
do
let
(
:file_type
)
{
:license_management
}
it
'returns artifact'
do
is_expected
.
to
be_kind_of
Ci
::
JobArtifact
end
end
end
end
end
describe
'#any_report_artifact_for_type'
do
let!
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
let!
(
:artifact
)
do
...
...
@@ -127,7 +182,7 @@ describe Ci::Pipeline do
file_format:
::
Ci
::
JobArtifact
::
TYPE_AND_FORMAT_PAIRS
[
file_type
])
end
subject
{
pipeline
.
report_artifact_for_file
_type
(
file_type
)
}
subject
{
pipeline
.
any_report_artifact_for
_type
(
file_type
)
}
described_class
::
REPORT_LICENSED_FEATURES
.
each
do
|
file_type
,
licensed_features
|
context
"for file_type:
#{
file_type
}
"
do
...
...
@@ -145,6 +200,20 @@ describe Ci::Pipeline do
end
end
describe
'#expose_license_scanning_data?'
do
subject
{
pipeline
.
expose_license_scanning_data?
}
before
do
stub_licensed_features
(
license_management:
true
)
end
[
:license_scanning
,
:license_management
].
each
do
|
artifact_type
|
let!
(
:build
)
{
create
(
:ee_ci_build
,
artifact_type
,
pipeline:
pipeline
)
}
it
{
is_expected
.
to
be_truthy
}
end
end
describe
'#security_reports'
do
subject
{
pipeline
.
security_reports
}
...
...
ee/spec/models/ee/ci/job_artifact_spec.rb
View file @
fd8678ff
...
...
@@ -34,4 +34,20 @@ describe EE::Ci::JobArtifact do
it
{
is_expected
.
to
be_empty
}
end
end
describe
'.associated_file_types_for'
do
using
RSpec
::
Parameterized
::
TableSyntax
subject
{
Ci
::
JobArtifact
.
associated_file_types_for
(
file_type
)
}
where
(
:file_type
,
:result
)
do
'license_scanning'
|
%w(license_management license_scanning)
'codequality'
|
%w(codequality)
'quality'
|
nil
end
with_them
do
it
{
is_expected
.
to
eq
result
}
end
end
end
ee/spec/models/merge_request_spec.rb
View file @
fd8678ff
...
...
@@ -121,19 +121,20 @@ describe MergeRequest do
describe
'#enabled_reports'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
where
(
:report_type
,
:with_reports
)
do
:sast
|
:with_sast_reports
:container_scanning
|
:with_container_scanning_reports
:dast
|
:with_dast_reports
:dependency_scanning
|
:with_dependency_scanning_reports
:license_management
|
:with_license_management_reports
where
(
:report_type
,
:with_reports
,
:feature
)
do
:sast
|
:with_sast_reports
|
:sast
:container_scanning
|
:with_container_scanning_reports
|
:container_scanning
:dast
|
:with_dast_reports
|
:dast
:dependency_scanning
|
:with_dependency_scanning_reports
|
:dependency_scanning
:license_management
|
:with_license_management_reports
|
:license_management
:license_management
|
:with_license_scanning_reports
|
:license_management
end
with_them
do
subject
{
merge_request
.
enabled_reports
[
report_type
]
}
before
do
stub_licensed_features
({
report_typ
e
=>
true
})
stub_licensed_features
({
featur
e
=>
true
})
end
context
"when head pipeline has reports"
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