mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
fix(osv): take the fixed version from the queried package range
An advisory can cover several packages. The fixed version came from the first range, so x/net findings showed the stdlib fix 1.26.9 instead of the x/net fix 0.60.0.
This commit is contained in:
@@ -44,3 +44,22 @@ func TestScan_FullQueryURLIsKept(t *testing.T) {
|
||||
t.Errorf("request path = %q, want /v1/query", gotPath)
|
||||
}
|
||||
}
|
||||
|
||||
// An advisory that covers the stdlib and x/net lists the stdlib range first; the fixed version
|
||||
// shown for x/net must come from the x/net range.
|
||||
func TestScan_FixedVersionComesFromTheQueriedPackage(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
_, _ = w.Write([]byte(`{"vulns":[{"id":"GO-2026-6612","summary":"s","affected":[
|
||||
{"package":{"name":"stdlib","ecosystem":"Go"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"1.26.9"}]}]},
|
||||
{"package":{"name":"golang.org/x/net","ecosystem":"Go"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"0.60.0"}]}]}]}]}`))
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
res, err := New(config.OSVConfig{APIURL: srv.URL}).Scan(context.Background(), "go", "golang.org/x/net/@v/v0.56.0.zip", "v0.56.0", "")
|
||||
if err != nil {
|
||||
t.Fatalf("Scan: %v", err)
|
||||
}
|
||||
if len(res.Vulnerabilities) != 1 || res.Vulnerabilities[0].FixedIn != "0.60.0" {
|
||||
t.Fatalf("vulnerabilities = %+v, want one fixed in 0.60.0", res.Vulnerabilities)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user