Skip to content

Commit

Permalink
add dependency groups to flattened vulnerability (#754)
Browse files Browse the repository at this point in the history
Follow up on #655
  • Loading branch information
cuixq authored Jan 19, 2024
1 parent 2f74249 commit 56584f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pkg/models/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (vulns *VulnerabilityResults) Flatten() []VulnerabilityFlattened {
results = append(results, VulnerabilityFlattened{
Source: res.Source,
Package: pkg.Package,
DepGroups: pkg.DepGroups,
Vulnerability: v,
GroupInfo: getGroupInfoForVuln(pkg.Groups, v.ID),
})
Expand All @@ -39,6 +40,7 @@ func (vulns *VulnerabilityResults) Flatten() []VulnerabilityFlattened {
results = append(results, VulnerabilityFlattened{
Source: res.Source,
Package: pkg.Package,
DepGroups: pkg.DepGroups,
Licenses: pkg.Licenses,
LicenseViolations: pkg.LicenseViolations,
})
Expand All @@ -61,6 +63,7 @@ func getGroupInfoForVuln(groups []GroupInfo, vulnID string) GroupInfo {
type VulnerabilityFlattened struct {
Source SourceInfo
Package PackageInfo
DepGroups []string
Vulnerability Vulnerability
GroupInfo GroupInfo
Licenses []License
Expand Down
15 changes: 11 additions & 4 deletions pkg/models/results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func TestFlatten(t *testing.T) {
// Test case 2: When there are vulnerabilities
group := GroupInfo{IDs: []string{"CVE-2021-1234"}}
pkg := PackageVulns{
Package: PackageInfo{Name: "package"},
Groups: []GroupInfo{group},
Package: PackageInfo{Name: "package"},
DepGroups: []string{"dev"},
Groups: []GroupInfo{group},
Vulnerabilities: []Vulnerability{
{
ID: "CVE-2021-1234",
Expand All @@ -40,6 +41,7 @@ func TestFlatten(t *testing.T) {
{
Source: source.Source,
Package: pkg.Package,
DepGroups: []string{"dev"},
Vulnerability: pkg.Vulnerabilities[0],
GroupInfo: group,
},
Expand All @@ -53,6 +55,7 @@ func TestFlatten(t *testing.T) {
group = GroupInfo{IDs: []string{"CVE-2021-1234"}}
pkg = PackageVulns{
Package: PackageInfo{Name: "package"},
DepGroups: []string{"dev"},
Groups: []GroupInfo{group},
Licenses: []License{License("MIT")},
LicenseViolations: []License{License("MIT")},
Expand All @@ -63,6 +66,7 @@ func TestFlatten(t *testing.T) {
{
Source: source.Source,
Package: pkg.Package,
DepGroups: []string{"dev"},
Licenses: []License{License("MIT")},
LicenseViolations: []License{License("MIT")},
},
Expand All @@ -75,8 +79,9 @@ func TestFlatten(t *testing.T) {
// Test case 4: When there are vulnerabilities and license violations
group = GroupInfo{IDs: []string{"CVE-2021-1234"}}
pkg = PackageVulns{
Package: PackageInfo{Name: "package"},
Groups: []GroupInfo{group},
Package: PackageInfo{Name: "package"},
DepGroups: []string{"dev"},
Groups: []GroupInfo{group},
Vulnerabilities: []Vulnerability{
{
ID: "CVE-2021-1234",
Expand All @@ -97,12 +102,14 @@ func TestFlatten(t *testing.T) {
{
Source: source.Source,
Package: pkg.Package,
DepGroups: []string{"dev"},
Vulnerability: pkg.Vulnerabilities[0],
GroupInfo: group,
},
{
Source: source.Source,
Package: pkg.Package,
DepGroups: []string{"dev"},
Licenses: []License{License("MIT")},
LicenseViolations: []License{License("MIT")},
},
Expand Down

0 comments on commit 56584f8

Please sign in to comment.