Skip to content

Commit e7af2ad

Browse files
tatianabTatiana Bradley
authored andcommitted
internal/report: fallback to package in GHSAToReport
If no module name is provided to GHSAToReport, use the name of the package instead of adding a TODO. Change-Id: I77c72391e4045de3e7f940bdc138351b562db4a3 Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/459841 Run-TryBot: Tatiana Bradley <tatiana@golang.org> Reviewed-by: Tim King <taking@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Tatiana Bradley <tatiana@golang.org>
1 parent e08ca34 commit e7af2ad

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

internal/report/ghsa.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func GHSAToReport(sa *ghsa.SecurityAdvisory, modulePath string) *Report {
2727
}
2828
r.CVEs = cves
2929
r.GHSAs = ghsas
30-
if modulePath == "" {
31-
modulePath = "TODO"
32-
}
3330
for _, v := range sa.Vulns {
31+
if modulePath == "" {
32+
modulePath = v.Package
33+
}
3434
m := &Module{
3535
Module: modulePath,
3636
Versions: versions(v.EarliestFixedVersion, v.VulnerableVersionRange),

internal/report/ghsa_test.go

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,55 @@ func TestGHSAToReport(t *testing.T) {
2626
VulnerableVersionRange: "< 1.2.3",
2727
}},
2828
}
29-
got := GHSAToReport(sa, "aModule")
30-
want := &Report{
31-
Modules: []*Module{{
32-
Module: "aModule",
33-
Versions: []VersionRange{
34-
{Fixed: "1.2.3"},
29+
for _, test := range []struct {
30+
name string
31+
module string
32+
want *Report
33+
}{
34+
{
35+
name: "module provided",
36+
module: "aModule",
37+
want: &Report{
38+
Modules: []*Module{{
39+
Module: "aModule",
40+
Versions: []VersionRange{
41+
{Fixed: "1.2.3"},
42+
},
43+
Packages: []*Package{{
44+
Package: "aPackage",
45+
}},
46+
}},
47+
Description: "a description",
48+
GHSAs: []string{"G1"},
49+
CVEs: []string{"C1"},
3550
},
36-
Packages: []*Package{{
37-
Package: "aPackage",
38-
}},
39-
}},
40-
Description: "a description",
41-
GHSAs: []string{"G1"},
42-
CVEs: []string{"C1"},
43-
}
44-
45-
if diff := cmp.Diff(*got, *want); diff != "" {
46-
t.Errorf("mismatch (-want, +got):\n%s", diff)
51+
},
52+
{
53+
name: "empty module uses package",
54+
module: "",
55+
want: &Report{
56+
Modules: []*Module{{
57+
Module: "aPackage",
58+
Versions: []VersionRange{
59+
{Fixed: "1.2.3"},
60+
},
61+
Packages: []*Package{{
62+
Package: "aPackage",
63+
}},
64+
}},
65+
Description: "a description",
66+
GHSAs: []string{"G1"},
67+
CVEs: []string{"C1"},
68+
},
69+
},
70+
} {
71+
test := test
72+
t.Run(test.name, func(t *testing.T) {
73+
got := GHSAToReport(sa, test.module)
74+
if diff := cmp.Diff(*got, *test.want); diff != "" {
75+
t.Errorf("mismatch (-want, +got):\n%s", diff)
76+
}
77+
})
4778
}
4879
}
4980
func TestParseVulnRange(t *testing.T) {

internal/worker/worker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ See [doc/triage.md](https://github.com/golang/vulndb/blob/master/doc/triage.md)
310310
311311
` + "```" + `
312312
modules:
313-
- module: TODO
313+
- module: aPackage
314314
versions:
315315
- fixed: 1.2.3
316316
packages:

0 commit comments

Comments
 (0)