Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dependency groups to flattened vulnerability #754

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading