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
38f666fa
Commit
38f666fa
authored
Oct 13, 2021
by
Tetiana Chupryna
Committed by
Aleksei Lipniagov
Oct 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix classification of custom licenses in License Compliance
parent
e755595e
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
228 additions
and
131 deletions
+228
-131
ee/app/models/sca/license_compliance.rb
ee/app/models/sca/license_compliance.rb
+15
-8
ee/lib/gitlab/ci/reports/license_scanning/report.rb
ee/lib/gitlab/ci/reports/license_scanning/report.rb
+1
-1
ee/spec/factories/ci/builds.rb
ee/spec/factories/ci/builds.rb
+6
-0
ee/spec/factories/ci/job_artifacts.rb
ee/spec/factories/ci/job_artifacts.rb
+11
-1
ee/spec/features/projects/licenses/maintainer_views_policies_spec.rb
...tures/projects/licenses/maintainer_views_policies_spec.rb
+1
-1
ee/spec/fixtures/security_reports/license_compliance/gl-license-scanning-report-custom-license.json
...compliance/gl-license-scanning-report-custom-license.json
+50
-0
ee/spec/fixtures/security_reports/license_compliance/gl-license-scanning-report-v1.1.json
...s/license_compliance/gl-license-scanning-report-v1.1.json
+0
-0
ee/spec/fixtures/security_reports/license_compliance/gl-license-scanning-report-v2.1.json
...s/license_compliance/gl-license-scanning-report-v2.1.json
+0
-0
ee/spec/fixtures/security_reports/license_compliance/gl-license-scanning-report-v2.json
...rts/license_compliance/gl-license-scanning-report-v2.json
+0
-0
ee/spec/lib/gitlab/ci/parsers/license_compliance/license_scanning_spec.rb
...ab/ci/parsers/license_compliance/license_scanning_spec.rb
+3
-3
ee/spec/lib/gitlab/ci/reports/license_scanning/report_spec.rb
...pec/lib/gitlab/ci/reports/license_scanning/report_spec.rb
+2
-2
ee/spec/models/sca/license_compliance_spec.rb
ee/spec/models/sca/license_compliance_spec.rb
+139
-115
No files found.
ee/app/models/sca/license_compliance.rb
View file @
38f666fa
...
...
@@ -38,24 +38,24 @@ module SCA
end
def
report_for
(
policy
)
build_policy
(
license_scan_report
[
policy
.
software_license
.
canonical_id
]
,
policy
)
build_policy
(
reported_license_by_license_model
(
policy
.
software_license
)
,
policy
)
end
def
diff_with
(
other
)
license_scan_report
.
diff_with
(
other
.
license_scan_report
)
license_scan
ning
_report
.
diff_with
(
other
.
license_scan
ning
_report
)
.
transform_values
do
|
reported_licenses
|
reported_licenses
.
map
do
|
reported_license
|
matching_license_policy
=
known_policies
[
reported_license
.
canonical_
id
]
||
known_policies
[
reported_license
.
id
]
||
known_policies
[
reported_license
&
.
name
&
.
downcase
]
build_policy
(
reported_license
,
matching_license_policy
)
end
end
end
def
license_scan_report
strong_memoize
(
:license_scan_report
)
do
def
license_scan
ning
_report
strong_memoize
(
:license_scan
ning
_report
)
do
pipeline
.
blank?
?
empty_report
:
pipeline
.
license_scanning_report
end
end
...
...
@@ -74,9 +74,16 @@ module SCA
end
end
# When the license found in the report doesn't match any license
# of the SPDX License List, we need to find it by name explicitly.
def
reported_license_by_license_model
(
software_license
)
license_scanning_report
[
software_license
.
canonical_id
]
||
license_scanning_report
.
by_license_name
(
software_license
.
name
&
.
downcase
)
end
def
unclassified_policies
license_scan_report
.
licenses
.
map
do
|
reported_license
|
next
if
known_policies
[
reported_license
.
canonical_id
]
license_scan
ning
_report
.
licenses
.
map
do
|
reported_license
|
next
if
known_policies
[
reported_license
.
id
]
||
known_policies
[
reported_license
&
.
name
&
.
downcase
]
[
reported_license
.
canonical_id
,
build_policy
(
reported_license
,
nil
)]
end
.
compact
.
to_h
...
...
ee/lib/gitlab/ci/reports/license_scanning/report.rb
View file @
38f666fa
...
...
@@ -34,7 +34,7 @@ module Gitlab
end
def
by_license_name
(
name
)
licenses
.
find
{
|
license
|
license
.
name
==
name
}
licenses
.
find
{
|
license
|
license
.
name
.
casecmp?
(
name
)
}
end
def
apply_details_from!
(
dependency_list_report
)
...
...
ee/spec/factories/ci/builds.rb
View file @
38f666fa
...
...
@@ -140,6 +140,12 @@ FactoryBot.define do
end
end
trait
:license_scanning_custom_license
do
after
:build
do
|
build
|
build
.
job_artifacts
<<
build
(
:ee_ci_job_artifact
,
:license_scanning_custom_license
,
job:
build
)
end
end
trait
:requirements_report
do
after
(
:build
)
do
|
build
|
build
.
job_artifacts
<<
create
(
:ee_ci_job_artifact
,
:all_passing_requirements
,
job:
build
)
...
...
ee/spec/factories/ci/job_artifacts.rb
View file @
38f666fa
...
...
@@ -159,6 +159,16 @@ FactoryBot.define do
end
end
trait
:license_scanning_custom_license
do
file_type
{
:license_scanning
}
file_format
{
:raw
}
after
(
:build
)
do
|
artifact
,
_
|
artifact
.
file
=
fixture_file_upload
(
Rails
.
root
.
join
(
'ee/spec/fixtures/security_reports/license_compliance/gl-license-scanning-report-custom-license.json'
),
'application/json'
)
end
end
trait
:performance
do
file_format
{
:raw
}
file_type
{
:performance
}
...
...
@@ -338,7 +348,7 @@ FactoryBot.define do
trait
:"v
#{
version
}
"
do
after
(
:build
)
do
|
artifact
,
_
|
filename
=
"gl-
#{
artifact
.
file_type
.
dasherize
}
-report-v
#{
version
.
sub
(
/_/
,
'.'
)
}
.json"
path
=
Rails
.
root
.
join
(
"ee/spec/fixtures/security_reports/
#{
filename
}
"
)
path
=
Rails
.
root
.
join
(
"ee/spec/fixtures/security_reports/
license_compliance/
#{
filename
}
"
)
artifact
.
file
=
fixture_file_upload
(
path
,
"application/json"
)
end
end
...
...
ee/spec/features/projects/licenses/maintainer_views_policies_spec.rb
View file @
38f666fa
...
...
@@ -30,7 +30,7 @@ RSpec.describe 'EE > Projects > Licenses > Maintainer views policies', :js do
let_it_be
(
:mit_policy
)
{
create
(
:software_license_policy
,
:denied
,
software_license:
mit
,
project:
project
)
}
let_it_be
(
:pipeline
)
{
create
(
:ee_ci_pipeline
,
project:
project
,
builds:
[
create
(
:ee_ci_build
,
:license_scan_v2
,
:success
)],
status: :success
)
}
let
(
:report
)
{
Gitlab
::
Json
.
parse
(
fixture_file
(
'security_reports/gl-license-scanning-report-v2.json'
,
dir:
'ee'
))
}
let
(
:report
)
{
Gitlab
::
Json
.
parse
(
fixture_file
(
'security_reports/
license_compliance/
gl-license-scanning-report-v2.json'
,
dir:
'ee'
))
}
let
(
:known_licenses
)
{
report
[
'licenses'
].
find_all
{
|
license
|
license
[
'url'
].
present?
}
}
it
'displays licenses detected in the most recent scan report'
do
...
...
ee/spec/fixtures/security_reports/license_compliance/gl-license-scanning-report-custom-license.json
0 → 100644
View file @
38f666fa
{
"version"
:
"2.1"
,
"licenses"
:
[
{
"id"
:
"BSD-3-Clause"
,
"name"
:
"BSD 3-Clause
\"
New
\"
or
\"
Revised
\"
License"
,
"url"
:
"https://opensource.org/licenses/BSD-3-Clause"
},
{
"id"
:
"MIT"
,
"name"
:
"MIT License"
,
"url"
:
"https://opensource.org/licenses/MIT"
},
{
"id"
:
"foo"
,
"name"
:
"Foo License"
,
"url"
:
""
}
],
"dependencies"
:
[
{
"name"
:
"a"
,
"version"
:
"1.0.0"
,
"package_manager"
:
"bundler"
,
"path"
:
"Gemfile.lock"
,
"licenses"
:
[
"MIT"
]
},
{
"name"
:
"b"
,
"version"
:
"0.1.0"
,
"package_manager"
:
"yarn"
,
"path"
:
"yarn.lock"
,
"licenses"
:
[
"BSD-3-Clause"
]
},
{
"name"
:
"c"
,
"version"
:
"1.1.0"
,
"package_manager"
:
"bundler"
,
"path"
:
"Gemfile.lock"
,
"licenses"
:
[
"MIT"
,
"BSD-3-Clause"
]
},
{
"name"
:
"d"
,
"version"
:
"1.1.1"
,
"package_manager"
:
"bundler"
,
"path"
:
"Gemfile.lock"
,
"licenses"
:
[
"foo"
]
}
]
}
ee/spec/fixtures/security_reports/gl-license-scanning-report-v1.1.json
→
ee/spec/fixtures/security_reports/
license_compliance/
gl-license-scanning-report-v1.1.json
View file @
38f666fa
File moved
ee/spec/fixtures/security_reports/gl-license-scanning-report-v2.1.json
→
ee/spec/fixtures/security_reports/
license_compliance/
gl-license-scanning-report-v2.1.json
View file @
38f666fa
File moved
ee/spec/fixtures/security_reports/gl-license-scanning-report-v2.json
→
ee/spec/fixtures/security_reports/
license_compliance/
gl-license-scanning-report-v2.json
View file @
38f666fa
File moved
ee/spec/lib/gitlab/ci/parsers/license_compliance/license_scanning_spec.rb
View file @
38f666fa
...
...
@@ -42,7 +42,7 @@ RSpec.describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do
end
context
'when parsing a valid v1.1 report'
do
let
(
:v1_1_data
)
{
fixture_file
(
'security_reports/gl-license-scanning-report-v1.1.json'
,
dir:
'ee'
)
}
let
(
:v1_1_data
)
{
fixture_file
(
'security_reports/
license_compliance/
gl-license-scanning-report-v1.1.json'
,
dir:
'ee'
)
}
before
do
subject
.
parse!
(
v1_1_data
,
report
)
...
...
@@ -74,7 +74,7 @@ RSpec.describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do
end
context
'when parsing a valid v2 report'
do
let
(
:v2_0_data
)
{
fixture_file
(
'security_reports/gl-license-scanning-report-v2.json'
,
dir:
'ee'
)
}
let
(
:v2_0_data
)
{
fixture_file
(
'security_reports/
license_compliance/
gl-license-scanning-report-v2.json'
,
dir:
'ee'
)
}
before
do
subject
.
parse!
(
v2_0_data
,
report
)
...
...
@@ -106,7 +106,7 @@ RSpec.describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do
end
context
'when parsing a valid v2.1 report'
do
let
(
:v2_1_data
)
{
fixture_file
(
'security_reports/gl-license-scanning-report-v2.1.json'
,
dir:
'ee'
)
}
let
(
:v2_1_data
)
{
fixture_file
(
'security_reports/
license_compliance/
gl-license-scanning-report-v2.1.json'
,
dir:
'ee'
)
}
before
do
subject
.
parse!
(
v2_1_data
,
report
)
...
...
ee/spec/lib/gitlab/ci/reports/license_scanning/report_spec.rb
View file @
38f666fa
...
...
@@ -11,7 +11,7 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do
let
(
:report
)
{
build
(
:ci_reports_license_scanning_report
,
:report_2
)
}
context
'with existing license'
do
let
(
:name
)
{
'MI
T
'
}
let
(
:name
)
{
'MI
t
'
}
it
'finds right name'
do
is_expected
.
to
be_a
(
Gitlab
::
Ci
::
Reports
::
LicenseScanning
::
License
)
...
...
@@ -290,7 +290,7 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do
context
'when parsing a v2 report'
do
subject
{
described_class
.
parse_from
(
v2_json
)
}
let
(
:v2_json
)
{
fixture_file
(
'security_reports/gl-license-scanning-report-v2.json'
,
dir:
'ee'
)
}
let
(
:v2_json
)
{
fixture_file
(
'security_reports/
license_compliance/
gl-license-scanning-report-v2.json'
,
dir:
'ee'
)
}
it
{
expect
(
subject
.
version
).
to
eql
(
'2.0'
)
}
it
{
expect
(
subject
.
licenses
.
count
).
to
eq
(
3
)
}
...
...
ee/spec/models/sca/license_compliance_spec.rb
View file @
38f666fa
This diff is collapsed.
Click to expand it.
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