diff options
| author | Jonathan Amsterdam <jba@google.com> | 2022-01-31 16:55:24 -0500 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2022-02-01 13:28:11 +0000 |
| commit | cf6808f5d9d8b356cdbc465375e357614a4dd68d (patch) | |
| tree | 2415b599164df0e95786649a538e5e6c677ffbc1 | |
| parent | a46155174c3c18de3d54e4b1866909fc48b56788 (diff) | |
| download | go-x-pkgsite-cf6808f5d9d8b356cdbc465375e357614a4dd68d.tar.xz | |
internal/frontend: display vuln list most recent first
Change-Id: I342703673651430c6be19ea52fd35833cbf158ef
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/382094
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
| -rwxr-xr-x | all.bash | 9 | ||||
| -rw-r--r-- | internal/frontend/vulns.go | 4 | ||||
| -rw-r--r-- | internal/frontend/vulns_test.go | 24 |
3 files changed, 23 insertions, 14 deletions
@@ -143,10 +143,11 @@ check_vet() { } # check_staticcheck runs staticcheck on source files. -check_staticcheck() { - ensure_go_binary honnef.co/go/tools/cmd/staticcheck - runcmd staticcheck $(go list ./... | grep -v third_party | grep -v internal/doc | grep -v internal/render) -} +# TODO: uncomment when updated to go 1.18 +# check_staticcheck() { +# ensure_go_binary honnef.co/go/tools/cmd/staticcheck +# runcmd staticcheck $(go list ./... | grep -v third_party | grep -v internal/doc | grep -v internal/render) +# } # check_misspell runs misspell on source files. check_misspell() { diff --git a/internal/frontend/vulns.go b/internal/frontend/vulns.go index c795941d..27274ff6 100644 --- a/internal/frontend/vulns.go +++ b/internal/frontend/vulns.go @@ -7,6 +7,7 @@ package frontend import ( "fmt" "net/http" + "sort" "golang.org/x/mod/semver" "golang.org/x/pkgsite/internal" @@ -145,6 +146,9 @@ func newVulnListPage(client vulnc.Client) (*VulnListPage, error) { if err != nil { return nil, err } + // Sort from most to least recent. + sort.Slice(ids, func(i, j int) bool { return ids[i] > ids[j] }) + entries := make([]*osv.Entry, len(ids)) sem := make(chan struct{}, concurrency) var g errgroup.Group diff --git a/internal/frontend/vulns_test.go b/internal/frontend/vulns_test.go index 91950fc1..7d624aca 100644 --- a/internal/frontend/vulns_test.go +++ b/internal/frontend/vulns_test.go @@ -58,13 +58,13 @@ func TestVulnsForPackage(t *testing.T) { } var testEntries = []*osv.Entry{ - {ID: "one", Details: "a"}, - {ID: "two", Details: "b"}, - {ID: "three", Details: "c"}, - {ID: "four", Details: "d"}, - {ID: "five", Details: "e"}, - {ID: "six", Details: "f"}, - {ID: "seven", Details: "g"}, + {ID: "GO-1990-01", Details: "a"}, + {ID: "GO-1990-02", Details: "b"}, + {ID: "GO-1990-10", Details: "c"}, + {ID: "GO-1991-01", Details: "d"}, + {ID: "GO-1991-05", Details: "e"}, + {ID: "GO-1991-23", Details: "f"}, + {ID: "GO-1991-30", Details: "g"}, } func TestNewVulnListPage(t *testing.T) { @@ -73,8 +73,12 @@ func TestNewVulnListPage(t *testing.T) { if err != nil { t.Fatal(err) } - // testEntries is already sorted by ID. - want := &VulnListPage{Entries: testEntries} + // testEntries is already sorted by ID, but it should be reversed. + var wantEntries []*osv.Entry + for i := len(testEntries) - 1; i >= 0; i-- { + wantEntries = append(wantEntries, testEntries[i]) + } + want := &VulnListPage{Entries: wantEntries} if diff := cmp.Diff(want, got, cmpopts.IgnoreUnexported(VulnListPage{})); diff != "" { t.Errorf("mismatch (-want, +got):\n%s", diff) } @@ -82,7 +86,7 @@ func TestNewVulnListPage(t *testing.T) { func TestNewVulnPage(t *testing.T) { c := &vulndbTestClient{entries: testEntries} - got, err := newVulnPage(c, "two") + got, err := newVulnPage(c, "GO-1990-02") if err != nil { t.Fatal(err) } |
