зеркало из https://github.com/golang/vulndb.git
all: (cleanup) remove unnecessary words from function names
No-op refactor to remove redundant words like "get" from function names. Change-Id: I899556dbbe8caa790593bee8d952d1b3f557387b Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/497499 Run-TryBot: Tatiana Bradley <tatianabradley@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Родитель
5da7e3174d
Коммит
5c064e0c02
10
all_test.go
10
all_test.go
|
@ -81,8 +81,8 @@ func TestLintReports(t *testing.T) {
|
|||
if len(lints) > 0 {
|
||||
t.Errorf(strings.Join(lints, "\n"))
|
||||
}
|
||||
goID := report.GetGoIDFromFilename(filename)
|
||||
for _, alias := range r.GetAliases() {
|
||||
goID := report.GoID(filename)
|
||||
for _, alias := range r.Aliases() {
|
||||
if report, ok := aliases[alias]; ok {
|
||||
t.Errorf("report %s shares duplicate alias %s with report %s", filename, alias, report)
|
||||
} else {
|
||||
|
@ -91,8 +91,8 @@ func TestLintReports(t *testing.T) {
|
|||
}
|
||||
// Check that a correct OSV file was generated for each YAML report.
|
||||
if r.Excluded == "" {
|
||||
generated := r.GenerateOSVEntry(goID, time.Time{})
|
||||
osvFilename := report.GetOSVFilename(goID)
|
||||
generated := r.ToOSV(goID, time.Time{})
|
||||
osvFilename := report.OSVFilename(goID)
|
||||
current, err := report.ReadOSV(osvFilename)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -109,7 +109,7 @@ func TestLintReports(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cvePath := report.GetCVEFilename(goID)
|
||||
cvePath := report.CVEFilename(goID)
|
||||
current, err := cveschema5.Read(cvePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
@ -71,7 +71,7 @@ func main() {
|
|||
logFatalUsageErr("cve", fmt.Errorf("must provide subcommand"))
|
||||
}
|
||||
|
||||
c := cveclient.New(*getCfgFromFlags())
|
||||
c := cveclient.New(*cfgFromFlags())
|
||||
|
||||
cmd := flag.Arg(0)
|
||||
switch cmd {
|
||||
|
@ -80,7 +80,7 @@ func main() {
|
|||
case "reserve":
|
||||
year := *year
|
||||
if year == 0 {
|
||||
year = getCurrentYear()
|
||||
year = currentYear()
|
||||
}
|
||||
mode := cveclient.SequentialRequest
|
||||
if !*reserveSequential {
|
||||
|
@ -159,12 +159,12 @@ func logFatalUsageErr(context string, err error) {
|
|||
log.Fatalf("%s: %s\n", context, err)
|
||||
}
|
||||
|
||||
func getCurrentYear() int {
|
||||
func currentYear() int {
|
||||
year, _, _ := time.Now().Date()
|
||||
return year
|
||||
}
|
||||
|
||||
func getCfgFromFlags() *cveclient.Config {
|
||||
func cfgFromFlags() *cveclient.Config {
|
||||
if *test {
|
||||
if *testApiKey == "" {
|
||||
logFatalUsageErr("cve", errors.New("the test CVE API key (flag -test-key or env var TEST_CVE_API_KEY) must be set in test env"))
|
||||
|
@ -321,7 +321,7 @@ func publish(c *cveclient.Client, filename string) (err error) {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%s is published at %s\n", cveID, c.GetWebURL(cveID))
|
||||
fmt.Printf("%s is published at %s\n", cveID, c.WebURL(cveID))
|
||||
if diff := cmp.Diff(existing.Containers, *toPublish); diff != "" {
|
||||
fmt.Printf("publish would update record with diff (-existing, +new):\n%s\n", diff)
|
||||
} else {
|
||||
|
@ -351,7 +351,7 @@ func publish(c *cveclient.Client, filename string) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("successfully %sd record for %s at %s\n", action, cveID, c.GetWebURL(cveID))
|
||||
fmt.Printf("successfully %sd record for %s at %s\n", action, cveID, c.WebURL(cveID))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ func constructIssue(ctx context.Context, c *issues.Client, ghsaClient *ghsa.Clie
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, allReports, err := report.GetAllExisting(repo)
|
||||
_, allReports, err := report.All(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, existingByFile, err := report.GetAllExisting(repo)
|
||||
_, existingByFile, err := report.All(repo)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ func setupCreate(ctx context.Context, args []string) ([]int, *createCfg, error)
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
existingByIssue, existingByFile, err := report.GetAllExisting(localRepo)
|
||||
existingByIssue, existingByFile, err := report.All(localRepo)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ func createReport(ctx context.Context, cfg *createCfg, iss *issues.Issue) (r *re
|
|||
func create(ctx context.Context, issueNumber int, cfg *createCfg) (err error) {
|
||||
defer derrors.Wrap(&err, "create(%d)", issueNumber)
|
||||
// Get GitHub issue.
|
||||
iss, err := cfg.issuesClient.GetIssue(ctx, issueNumber)
|
||||
iss, err := cfg.issuesClient.Issue(ctx, issueNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ func create(ctx context.Context, issueNumber int, cfg *createCfg) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
filename := r.GetYAMLFilename(iss.NewGoID())
|
||||
filename := r.YAMLFilename(iss.NewGoID())
|
||||
if err := r.Write(filename); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ func handleExcludedIssue(ctx context.Context, cfg *createCfg, iss *issues.Issue)
|
|||
}
|
||||
r.Fix()
|
||||
|
||||
filename := r.GetYAMLFilename(iss.NewGoID())
|
||||
filename := r.YAMLFilename(iss.NewGoID())
|
||||
if err := r.Write(filename); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ func createExcluded(ctx context.Context, cfg *createCfg) (err error) {
|
|||
}
|
||||
for _, label := range excludedLabels {
|
||||
tempIssues, err :=
|
||||
cfg.issuesClient.GetIssues(ctx, issues.GetIssuesOptions{Labels: []string{label}, State: stateOption})
|
||||
cfg.issuesClient.Issues(ctx, issues.IssuesOptions{Labels: []string{label}, State: stateOption})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ func createExcluded(ctx context.Context, cfg *createCfg) (err error) {
|
|||
continue
|
||||
}
|
||||
successfulIssNums = append(successfulIssNums, fmt.Sprintf("golang/vulndb#%d", iss.Number))
|
||||
successfulGoIDs = append(successfulGoIDs, report.GetGoIDFromFilename(filename))
|
||||
successfulGoIDs = append(successfulGoIDs, report.GoID(filename))
|
||||
}
|
||||
fmt.Printf("Skipped %d issues\n", skipped)
|
||||
|
||||
|
@ -688,7 +688,7 @@ func fix(ctx context.Context, filename string, ghsaClient *ghsa.Client) (err err
|
|||
if err := r.Write(filename); err != nil {
|
||||
return err
|
||||
}
|
||||
goID := report.GetGoIDFromFilename(filename)
|
||||
goID := report.GoID(filename)
|
||||
if _, err := writeOSV(r, goID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -867,7 +867,7 @@ func osvCmd(filename string) (err error) {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
osvFilename, err := writeOSV(r, report.GetGoIDFromFilename(filename))
|
||||
osvFilename, err := writeOSV(r, report.GoID(filename))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -877,8 +877,8 @@ func osvCmd(filename string) (err error) {
|
|||
|
||||
func writeOSV(r *report.Report, goID string) (string, error) {
|
||||
if r.Excluded == "" {
|
||||
entry := r.GenerateOSVEntry(goID, time.Time{})
|
||||
osvFilename := report.GetOSVFilename(goID)
|
||||
entry := r.ToOSV(goID, time.Time{})
|
||||
osvFilename := report.OSVFilename(goID)
|
||||
if err := database.WriteJSON(osvFilename, entry, true); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -893,7 +893,7 @@ func cveCmd(ctx context.Context, filename string) (err error) {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return writeCVE(r, report.GetGoIDFromFilename(filename))
|
||||
return writeCVE(r, report.GoID(filename))
|
||||
}
|
||||
|
||||
// writeCVE takes a report and its Go ID, converts the report
|
||||
|
@ -905,7 +905,7 @@ func writeCVE(r *report.Report, goID string) error {
|
|||
var cve *cveschema5.CVERecord
|
||||
var err error
|
||||
|
||||
cvePath := report.GetCVEFilename(goID)
|
||||
cvePath := report.CVEFilename(goID)
|
||||
if cve, err = r.ToCVE5(goID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -945,12 +945,12 @@ func commit(ctx context.Context, filename string, ghsaClient *ghsa.Client) (err
|
|||
|
||||
// Find all derived files (OSV and CVE).
|
||||
files := []string{filename}
|
||||
goID := report.GetGoIDFromFilename(filename)
|
||||
goID := report.GoID(filename)
|
||||
if r.Excluded == "" {
|
||||
files = append(files, report.GetOSVFilename(goID))
|
||||
files = append(files, report.OSVFilename(goID))
|
||||
}
|
||||
if r.CVEMetadata != nil {
|
||||
files = append(files, report.GetCVEFilename(goID))
|
||||
files = append(files, report.CVEFilename(goID))
|
||||
}
|
||||
|
||||
// Add the files.
|
||||
|
@ -996,7 +996,7 @@ func newCommitMsg(r *report.Report, filepath string) (string, error) {
|
|||
|
||||
return fmt.Sprintf(
|
||||
"%s: %s %s\n\nAliases: %s\n\n%s golang/vulndb#%d",
|
||||
folder, fileAction, filename, strings.Join(r.GetAliases(), ", "),
|
||||
folder, fileAction, filename, strings.Join(r.Aliases(), ", "),
|
||||
issueAction, issueID), nil
|
||||
}
|
||||
|
||||
|
@ -1163,7 +1163,7 @@ func dedupeAndSort[T constraints.Ordered](s []T) []T {
|
|||
// addGHSAs adds any missing GHSAs that correspond to the CVEs in the report.
|
||||
func addGHSAs(ctx context.Context, r *report.Report, ghsaClient *ghsa.Client) error {
|
||||
ghsas := r.GHSAs
|
||||
for _, cve := range r.GetCVEs() {
|
||||
for _, cve := range r.AllCVEs() {
|
||||
sas, err := ghsaClient.ListForCVE(ctx, cve)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -258,7 +258,7 @@ func createIssuesCommand(ctx context.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, allReports, err := report.GetAllExisting(repo)
|
||||
_, allReports, err := report.All(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -40,9 +40,9 @@ type Client struct {
|
|||
c *http.Client
|
||||
}
|
||||
|
||||
// GetWebURL returns the URL that can be used to view a published
|
||||
// WebURL returns the URL that can be used to view a published
|
||||
// CVE record on the web.
|
||||
func (c *Client) GetWebURL(cveID string) string {
|
||||
func (c *Client) WebURL(cveID string) string {
|
||||
baseURL := WebURL
|
||||
if c.Config.Endpoint == TestEndpoint {
|
||||
baseURL = TestWebURL
|
||||
|
@ -132,7 +132,7 @@ const (
|
|||
NonsequentialRequest RequestType = "nonsequential"
|
||||
)
|
||||
|
||||
func (o *ReserveOptions) getURLParams(org string) url.Values {
|
||||
func (o *ReserveOptions) urlParams(org string) url.Values {
|
||||
params := url.Values{}
|
||||
params.Set("amount", fmt.Sprint(o.NumIDs))
|
||||
if o.Year != 0 {
|
||||
|
@ -147,11 +147,11 @@ func (o *ReserveOptions) getURLParams(org string) url.Values {
|
|||
|
||||
func (c *Client) createReserveIDsRequest(opts ReserveOptions) (*http.Request, error) {
|
||||
req, err := c.createRequest(http.MethodPost,
|
||||
c.getURL(cveIDTarget), nil)
|
||||
c.requestURL(cveIDTarget), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.URL.RawQuery = opts.getURLParams(c.Org).Encode()
|
||||
req.URL.RawQuery = opts.urlParams(c.Org).Encode()
|
||||
return req, err
|
||||
}
|
||||
|
||||
|
@ -188,24 +188,24 @@ type Quota struct {
|
|||
|
||||
// RetrieveQuota queries the API for the organizations reservation quota.
|
||||
func (c *Client) RetrieveQuota() (q *Quota, err error) {
|
||||
err = c.queryAPI(http.MethodGet, c.getURL(orgTarget, c.Org, quotaTarget), nil, &q)
|
||||
err = c.queryAPI(http.MethodGet, c.requestURL(orgTarget, c.Org, quotaTarget), nil, &q)
|
||||
return
|
||||
}
|
||||
|
||||
// RetrieveID requests information about an assigned CVE ID.
|
||||
func (c *Client) RetrieveID(id string) (cve *AssignedCVE, err error) {
|
||||
err = c.queryAPI(http.MethodGet, c.getURL(cveIDTarget, id), nil, &cve)
|
||||
err = c.queryAPI(http.MethodGet, c.requestURL(cveIDTarget, id), nil, &cve)
|
||||
return
|
||||
}
|
||||
|
||||
// RetrieveRecord requests a CVE record.
|
||||
func (c *Client) RetrieveRecord(id string) (cve *cveschema5.CVERecord, err error) {
|
||||
err = c.queryAPI(http.MethodGet, c.getURL(cveTarget, id), nil, &cve)
|
||||
err = c.queryAPI(http.MethodGet, c.requestURL(cveTarget, id), nil, &cve)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) getCVERecordEndpoint(cveID string) string {
|
||||
return c.getURL(cveTarget, cveID, cnaTarget)
|
||||
func (c *Client) cveRecordEndpoint(cveID string) string {
|
||||
return c.requestURL(cveTarget, cveID, cnaTarget)
|
||||
}
|
||||
|
||||
type recordRequestBody struct {
|
||||
|
@ -220,7 +220,7 @@ func (c *Client) CreateRecord(id string, record *cveschema5.Containers) (*cvesch
|
|||
CNAContainer: record.CNAContainer,
|
||||
}
|
||||
var response createResponse
|
||||
err := c.queryAPI(http.MethodPost, c.getCVERecordEndpoint(id), requestBody, &response)
|
||||
err := c.queryAPI(http.MethodPost, c.cveRecordEndpoint(id), requestBody, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ func (c *Client) UpdateRecord(id string, record *cveschema5.Containers) (*cvesch
|
|||
CNAContainer: record.CNAContainer,
|
||||
}
|
||||
var response updateResponse
|
||||
err := c.queryAPI(http.MethodPut, c.getCVERecordEndpoint(id), requestBody, &response)
|
||||
err := c.queryAPI(http.MethodPut, c.cveRecordEndpoint(id), requestBody, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ type Org struct {
|
|||
|
||||
// RetrieveOrg requests information about an organization.
|
||||
func (c *Client) RetrieveOrg() (org *Org, err error) {
|
||||
err = c.queryAPI(http.MethodGet, c.getURL(orgTarget, c.Org), nil, &org)
|
||||
err = c.queryAPI(http.MethodGet, c.requestURL(orgTarget, c.Org), nil, &org)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ func (o ListOptions) String() string {
|
|||
return strings.Join(s, ", ")
|
||||
}
|
||||
|
||||
func (o *ListOptions) getURLParams() url.Values {
|
||||
func (o *ListOptions) urlParams() url.Values {
|
||||
params := url.Values{}
|
||||
if o == nil {
|
||||
return params
|
||||
|
@ -322,11 +322,11 @@ type listOrgCVEsResponse struct {
|
|||
}
|
||||
|
||||
func (c Client) createListOrgCVEsRequest(opts *ListOptions, page int) (req *http.Request, err error) {
|
||||
req, err = c.createRequest(http.MethodGet, c.getURL(cveIDTarget), nil)
|
||||
req, err = c.createRequest(http.MethodGet, c.requestURL(cveIDTarget), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params := opts.getURLParams()
|
||||
params := opts.urlParams()
|
||||
if page > 0 {
|
||||
params.Set("page", fmt.Sprint(page))
|
||||
}
|
||||
|
@ -432,7 +432,7 @@ var (
|
|||
cnaTarget = "cna"
|
||||
)
|
||||
|
||||
func (c *Client) getURL(targets ...string) string {
|
||||
func (c *Client) requestURL(targets ...string) string {
|
||||
return fmt.Sprintf("%s/api/%s", c.Endpoint, strings.Join(targets, "/"))
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ func readTestData(t *testing.T, filename string) *cveschema5.CVERecord {
|
|||
return record
|
||||
}
|
||||
|
||||
var getDefaultTestCVERecord = func(t *testing.T) *cveschema5.CVERecord {
|
||||
var defaultTestCVERecord = func(t *testing.T) *cveschema5.CVERecord {
|
||||
return readTestData(t, "basic-example.json")
|
||||
}
|
||||
|
||||
|
@ -212,16 +212,16 @@ var (
|
|||
return c.RetrieveQuota()
|
||||
}
|
||||
retrieveIDQuery = func(t *testing.T, c *Client) (any, error) {
|
||||
return c.RetrieveID(getDefaultTestCVERecord(t).Metadata.ID)
|
||||
return c.RetrieveID(defaultTestCVERecord(t).Metadata.ID)
|
||||
}
|
||||
retrieveRecordQuery = func(t *testing.T, c *Client) (any, error) {
|
||||
return c.RetrieveRecord(getDefaultTestCVERecord(t).Metadata.ID)
|
||||
return c.RetrieveRecord(defaultTestCVERecord(t).Metadata.ID)
|
||||
}
|
||||
createRecordQuery = func(t *testing.T, c *Client) (any, error) {
|
||||
return c.CreateRecord(defaultTestCVE.ID, &getDefaultTestCVERecord(t).Containers)
|
||||
return c.CreateRecord(defaultTestCVE.ID, &defaultTestCVERecord(t).Containers)
|
||||
}
|
||||
updateRecordQuery = func(t *testing.T, c *Client) (any, error) {
|
||||
return c.UpdateRecord(defaultTestCVE.ID, &getDefaultTestCVERecord(t).Containers)
|
||||
return c.UpdateRecord(defaultTestCVE.ID, &defaultTestCVERecord(t).Containers)
|
||||
}
|
||||
retrieveOrgQuery = func(t *testing.T, c *Client) (any, error) {
|
||||
return c.RetrieveOrg()
|
||||
|
@ -232,7 +232,7 @@ var (
|
|||
)
|
||||
|
||||
func TestAllSuccess(t *testing.T) {
|
||||
defaultTestCVERecord := getDefaultTestCVERecord(t)
|
||||
defaultTestCVERecord := defaultTestCVERecord(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
mockStatus int
|
||||
|
|
|
@ -102,7 +102,7 @@ func (d *Database) checkNoUnexpectedFiles(dbPath string) error {
|
|||
if fname == indexFile {
|
||||
return nil
|
||||
}
|
||||
id := report.GetGoIDFromFilename(fname)
|
||||
id := report.GoID(fname)
|
||||
if _, ok := d.EntriesByID[id]; !ok {
|
||||
return fmt.Errorf("found unexpected file %q which is not present in %s", fname, filepath.Join(idDirectory, indexFile))
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ type Issue struct {
|
|||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// GetIssuesOptions are options for GetIssues
|
||||
type GetIssuesOptions struct {
|
||||
// IssuesOptions are options for Issues
|
||||
type IssuesOptions struct {
|
||||
// State filters issues based on their state. Possible values are: open,
|
||||
// closed, all. Default is "open".
|
||||
State string
|
||||
|
@ -135,9 +135,9 @@ func convertGithubIssueToIssue(ghIss *github.Issue) *Issue {
|
|||
return iss
|
||||
}
|
||||
|
||||
// GetIssue returns the issue with the given issue number.
|
||||
func (c *Client) GetIssue(ctx context.Context, number int) (_ *Issue, err error) {
|
||||
defer derrors.Wrap(&err, "GetIssue(%d)", number)
|
||||
// Issue returns the issue with the given issue number.
|
||||
func (c *Client) Issue(ctx context.Context, number int) (_ *Issue, err error) {
|
||||
defer derrors.Wrap(&err, "Issue(%d)", number)
|
||||
ghIss, _, err := c.GitHub.Issues.Get(ctx, c.Owner, c.Repo, number)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -147,9 +147,9 @@ func (c *Client) GetIssue(ctx context.Context, number int) (_ *Issue, err error)
|
|||
return iss, nil
|
||||
}
|
||||
|
||||
// GetIssues returns all Github issues that match the filters in opts.
|
||||
func (c *Client) GetIssues(ctx context.Context, opts GetIssuesOptions) (_ []*Issue, err error) {
|
||||
defer derrors.Wrap(&err, "GetIssues()")
|
||||
// Issues returns all Github issues that match the filters in opts.
|
||||
func (c *Client) Issues(ctx context.Context, opts IssuesOptions) (_ []*Issue, err error) {
|
||||
defer derrors.Wrap(&err, "Issues()")
|
||||
clientOpts := &github.IssueListByRepoOptions{
|
||||
State: opts.State,
|
||||
Labels: opts.Labels,
|
||||
|
|
|
@ -54,7 +54,7 @@ func TestCreateIssue(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetIssueAndIssueExists(t *testing.T) {
|
||||
func TestIssueAndIssueExists(t *testing.T) {
|
||||
c, mux := githubtest.Setup(context.Background(), t, testConfig)
|
||||
want := &issues.Issue{
|
||||
Number: 7,
|
||||
|
@ -69,7 +69,7 @@ func TestGetIssueAndIssueExists(t *testing.T) {
|
|||
}
|
||||
})
|
||||
ctx := context.Background()
|
||||
got, err := c.GetIssue(ctx, want.Number)
|
||||
got, err := c.Issue(ctx, want.Number)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func TestGetIssueAndIssueExists(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetIssues(t *testing.T) {
|
||||
func TestIssues(t *testing.T) {
|
||||
c, mux := githubtest.Setup(context.Background(), t, testConfig)
|
||||
iss := &issues.Issue{
|
||||
Number: 1,
|
||||
|
@ -106,7 +106,7 @@ func TestGetIssues(t *testing.T) {
|
|||
})
|
||||
ctx := context.Background()
|
||||
want := []*issues.Issue{iss, iss2}
|
||||
got, err := c.GetIssues(ctx, issues.GetIssuesOptions{State: "open"})
|
||||
got, err := c.Issues(ctx, issues.IssuesOptions{State: "open"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ func testClient(t *testing.T, c *Client) {
|
|||
if !gotExists {
|
||||
t.Error("created issue doesn't exist")
|
||||
}
|
||||
gotIss, err := c.GetIssue(ctx, num)
|
||||
gotIss, err := c.Issue(ctx, num)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ func testClient(t *testing.T, c *Client) {
|
|||
}
|
||||
|
||||
want := []*Issue{iss, iss2}
|
||||
got, err := c.GetIssues(ctx, GetIssuesOptions{Labels: []string{"testing"}})
|
||||
got, err := c.Issues(ctx, IssuesOptions{Labels: []string{"testing"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ func testClient(t *testing.T, c *Client) {
|
|||
t.Errorf("mismatch (-want, +got):\n%s", diff)
|
||||
}
|
||||
want = []*Issue{iss2}
|
||||
got, err = c.GetIssues(ctx, GetIssuesOptions{Labels: []string{"other"}})
|
||||
got, err = c.Issues(ctx, IssuesOptions{Labels: []string{"other"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"golang.org/x/vulndb/internal/stdlib"
|
||||
)
|
||||
|
||||
func getVendor(modulePath string) string {
|
||||
func vendor(modulePath string) string {
|
||||
switch modulePath {
|
||||
case stdlib.ModulePath:
|
||||
return "Go standard library"
|
||||
|
|
|
@ -75,7 +75,7 @@ func (r *Report) ToCVE5(goID string) (_ *cveschema5.CVERecord, err error) {
|
|||
}
|
||||
for _, p := range m.Packages {
|
||||
affected := cveschema5.Affected{
|
||||
Vendor: getVendor(m.Module),
|
||||
Vendor: vendor(m.Module),
|
||||
Product: p.Package,
|
||||
CollectionURL: "https://pkg.go.dev",
|
||||
PackageName: p.Package,
|
||||
|
@ -93,7 +93,7 @@ func (r *Report) ToCVE5(goID string) (_ *cveschema5.CVERecord, err error) {
|
|||
for _, ref := range r.References {
|
||||
c.References = append(c.References, cveschema5.Reference{URL: ref.URL})
|
||||
}
|
||||
advisoryLink := GetGoAdvisoryLink(goID)
|
||||
advisoryLink := GoAdvisory(goID)
|
||||
c.References = append(c.References, cveschema5.Reference{URL: advisoryLink})
|
||||
|
||||
for _, credit := range r.Credits {
|
||||
|
@ -115,7 +115,7 @@ func (r *Report) ToCVE5(goID string) (_ *cveschema5.CVERecord, err error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func GetCVEFilename(goID string) string {
|
||||
func CVEFilename(goID string) string {
|
||||
return filepath.Join(cve5Dir, goID+".json")
|
||||
}
|
||||
|
||||
|
|
|
@ -263,7 +263,7 @@ func TestToCVE5(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := r.ToCVE5(GetGoIDFromFilename(test.filename))
|
||||
got, err := r.ToCVE5(GoID(test.filename))
|
||||
if err != nil {
|
||||
t.Fatalf("ToCVE5(%s) failed unexpectedly; err=%v", test.filename, err)
|
||||
}
|
||||
|
@ -274,9 +274,9 @@ func TestToCVE5(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetCVEFilename(t *testing.T) {
|
||||
func TestCVEFilename(t *testing.T) {
|
||||
want := "data/cve/v5/GO-1999-0001.json"
|
||||
if got := GetCVEFilename("GO-1999-0001"); got != want {
|
||||
if got := CVEFilename("GO-1999-0001"); got != want {
|
||||
t.Errorf("got %s, want %s", got, want)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,10 +29,10 @@ var (
|
|||
SchemaVersion = "1.3.1"
|
||||
)
|
||||
|
||||
// GenerateOSVEntry create an osv.Entry for a report.
|
||||
// ToOSV creates an osv.Entry for a report.
|
||||
// In addition to the report, it takes the ID for the vuln and the time
|
||||
// the vuln was last modified.
|
||||
func (r *Report) GenerateOSVEntry(goID string, lastModified time.Time) osv.Entry {
|
||||
func (r *Report) ToOSV(goID string, lastModified time.Time) osv.Entry {
|
||||
var credits []osv.Credit
|
||||
for _, credit := range r.Credits {
|
||||
credits = append(credits, osv.Credit{
|
||||
|
@ -53,11 +53,11 @@ func (r *Report) GenerateOSVEntry(goID string, lastModified time.Time) osv.Entry
|
|||
Details: trimWhitespace(r.Description),
|
||||
Credits: credits,
|
||||
SchemaVersion: SchemaVersion,
|
||||
DatabaseSpecific: &osv.DatabaseSpecific{URL: GetGoAdvisoryLink(goID)},
|
||||
DatabaseSpecific: &osv.DatabaseSpecific{URL: GoAdvisory(goID)},
|
||||
}
|
||||
|
||||
for _, m := range r.Modules {
|
||||
entry.Affected = append(entry.Affected, generateAffected(m))
|
||||
entry.Affected = append(entry.Affected, toAffected(m))
|
||||
}
|
||||
for _, ref := range r.References {
|
||||
entry.References = append(entry.References, osv.Reference{
|
||||
|
@ -65,11 +65,11 @@ func (r *Report) GenerateOSVEntry(goID string, lastModified time.Time) osv.Entry
|
|||
URL: ref.URL,
|
||||
})
|
||||
}
|
||||
entry.Aliases = r.GetAliases()
|
||||
entry.Aliases = r.Aliases()
|
||||
return entry
|
||||
}
|
||||
|
||||
func GetOSVFilename(goID string) string {
|
||||
func OSVFilename(goID string) string {
|
||||
return filepath.Join(OSVDir, goID+".json")
|
||||
}
|
||||
|
||||
|
@ -134,8 +134,8 @@ func trimWhitespace(s string) string {
|
|||
return s
|
||||
}
|
||||
|
||||
func generateImports(m *Module) (imps []osv.Package) {
|
||||
for _, p := range m.Packages {
|
||||
func toOSVPackages(pkgs []*Package) (imps []osv.Package) {
|
||||
for _, p := range pkgs {
|
||||
syms := append([]string{}, p.Symbols...)
|
||||
syms = append(syms, p.DerivedSymbols...)
|
||||
sort.Strings(syms)
|
||||
|
@ -149,7 +149,7 @@ func generateImports(m *Module) (imps []osv.Package) {
|
|||
return imps
|
||||
}
|
||||
|
||||
func generateAffected(m *Module) osv.Affected {
|
||||
func toAffected(m *Module) osv.Affected {
|
||||
name := m.Module
|
||||
switch name {
|
||||
case stdlib.ModulePath:
|
||||
|
@ -164,7 +164,7 @@ func generateAffected(m *Module) osv.Affected {
|
|||
},
|
||||
Ranges: AffectedRanges(m.Versions),
|
||||
EcosystemSpecific: &osv.EcosystemSpecific{
|
||||
Packages: generateImports(m),
|
||||
Packages: toOSVPackages(m.Packages),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"golang.org/x/vulndb/internal/osv"
|
||||
)
|
||||
|
||||
func TestGenerateOSVEntry(t *testing.T) {
|
||||
func TestToOSV(t *testing.T) {
|
||||
r := &Report{
|
||||
Modules: []*Module{
|
||||
{
|
||||
|
@ -200,20 +200,20 @@ func TestGenerateOSVEntry(t *testing.T) {
|
|||
DatabaseSpecific: &osv.DatabaseSpecific{URL: "https://pkg.go.dev/vuln/GO-1991-0001"},
|
||||
}
|
||||
|
||||
gotEntry := r.GenerateOSVEntry("GO-1991-0001", time.Time{})
|
||||
gotEntry := r.ToOSV("GO-1991-0001", time.Time{})
|
||||
if diff := cmp.Diff(wantEntry, gotEntry, cmp.Comparer(func(a, b time.Time) bool { return a.Equal(b) })); diff != "" {
|
||||
t.Errorf("GenerateOSVEntry returned unexpected entry (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOSVFilename(t *testing.T) {
|
||||
func TestOSVFilename(t *testing.T) {
|
||||
want := "data/osv/GO-1999-0001.json"
|
||||
if got := GetOSVFilename("GO-1999-0001"); got != want {
|
||||
if got := OSVFilename("GO-1999-0001"); got != want {
|
||||
t.Errorf("got %s, want %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemverCanonicalize(t *testing.T) {
|
||||
func TestAffectedRanges(t *testing.T) {
|
||||
in := []VersionRange{
|
||||
{
|
||||
Introduced: "1.16.0",
|
||||
|
|
|
@ -133,17 +133,17 @@ type Report struct {
|
|||
CVEMetadata *CVEMeta `yaml:"cve_metadata,omitempty"`
|
||||
}
|
||||
|
||||
// GetCVEs returns all CVE IDs for a report.
|
||||
func (r *Report) GetCVEs() []string {
|
||||
// AllCVEs returns all CVE IDs for a report, including any in cve_metadata.
|
||||
func (r *Report) AllCVEs() []string {
|
||||
if r.CVEMetadata != nil {
|
||||
return []string{r.CVEMetadata.ID}
|
||||
}
|
||||
return r.CVEs
|
||||
}
|
||||
|
||||
// GetAliases returns all aliases (e.g., CVEs, GHSAs) for a report.
|
||||
func (r *Report) GetAliases() []string {
|
||||
return append(r.GetCVEs(), r.GHSAs...)
|
||||
// Aliases returns all aliases (e.g., CVEs, GHSAs) for a report.
|
||||
func (r *Report) Aliases() []string {
|
||||
return append(r.AllCVEs(), r.GHSAs...)
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -152,11 +152,13 @@ const (
|
|||
goURLPrefix = "https://pkg.go.dev/vuln/"
|
||||
)
|
||||
|
||||
func GetGoIDFromFilename(filename string) string {
|
||||
// GoID returns the Go ID from the given filename, assuming the filename
|
||||
// is of the form "*/<goID>.<ext>".
|
||||
func GoID(filename string) string {
|
||||
return strings.TrimSuffix(filepath.Base(filename), filepath.Ext(filename))
|
||||
}
|
||||
|
||||
func GetGoAdvisoryLink(id string) string {
|
||||
func GoAdvisory(id string) string {
|
||||
return fmt.Sprintf("%s%s", goURLPrefix, id)
|
||||
}
|
||||
|
||||
|
@ -215,7 +217,7 @@ func ReadAndLint(filename string) (r *Report, err error) {
|
|||
return r, nil
|
||||
}
|
||||
|
||||
func (r *Report) GetYAMLFilename(goID string) string {
|
||||
func (r *Report) YAMLFilename(goID string) string {
|
||||
dir := YAMLDir
|
||||
if r.Excluded != "" {
|
||||
dir = ExcludedDir
|
||||
|
|
|
@ -67,7 +67,7 @@ func TestGetYAMLFilename(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if got := test.r.GetYAMLFilename(test.goID); got != test.want {
|
||||
if got := test.r.YAMLFilename(test.goID); got != test.want {
|
||||
t.Errorf("got %s, want %s", got, test.want)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,9 @@ var (
|
|||
ExcludedDir = "data/excluded"
|
||||
)
|
||||
|
||||
func GetAllExisting(repo *git.Repository) (byIssue map[int]*Report, byFile map[string]*Report, err error) {
|
||||
defer derrors.Wrap(&err, "GetAllExisting")
|
||||
// All returns all the reports in the repo, indexed by issue and by filename.
|
||||
func All(repo *git.Repository) (byIssue map[int]*Report, byFile map[string]*Report, err error) {
|
||||
defer derrors.Wrap(&err, "All()")
|
||||
root, err := gitrepo.Root(repo)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
@ -78,8 +79,8 @@ func XRef(r *Report, existingByFile map[string]*Report) (matches map[string][]st
|
|||
// matches is a map from filename -> alias/module
|
||||
matches = make(map[string][]string)
|
||||
for fname, rr := range existingByFile {
|
||||
for _, alias := range rr.GetAliases() {
|
||||
if slices.Contains(r.GetAliases(), alias) {
|
||||
for _, alias := range rr.Aliases() {
|
||||
if slices.Contains(r.Aliases(), alias) {
|
||||
matches[fname] = append(matches[fname], alias)
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +118,7 @@ func Aliases(repo *git.Repository) (_ []string, err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
aliases = append(aliases, r.GetAliases()...)
|
||||
aliases = append(aliases, r.Aliases()...)
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
|
|
|
@ -46,7 +46,7 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
func TestGetAllExisting(t *testing.T) {
|
||||
func TestAll(t *testing.T) {
|
||||
|
||||
wantByIssue := map[int]*Report{1: &r1, 2: &r2, 4: &r4, 5: &r5}
|
||||
wantByFile := map[string]*Report{
|
||||
|
@ -61,16 +61,16 @@ func TestGetAllExisting(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
gotByIssue, gotByFile, err := GetAllExisting(repo)
|
||||
gotByIssue, gotByFile, err := All(repo)
|
||||
if err != nil {
|
||||
t.Fatalf("GetAllExisting() error = %v, ", err)
|
||||
t.Fatalf("All() error = %v, ", err)
|
||||
}
|
||||
if diff := cmp.Diff(gotByIssue, wantByIssue); diff != "" {
|
||||
t.Errorf("GetAllExisting(): byIssue mismatch (-got, +want): %s", diff)
|
||||
t.Errorf("All(): byIssue mismatch (-got, +want): %s", diff)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(gotByFile, wantByFile); diff != "" {
|
||||
t.Errorf("GetAllExisting() byFile mismatch (-got, +want): %s", diff)
|
||||
t.Errorf("All() byFile mismatch (-got, +want): %s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright 2022 The Go Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
Repo for testing reports.GetAllExisting, semi in the shape of
|
||||
Repo for testing reports.All(), semi in the shape of
|
||||
github.com/golang/vulndb
|
||||
|
||||
-- data/reports/GO-9999-0001.yaml --
|
||||
|
|
|
@ -356,7 +356,7 @@ func (s *Server) handleIssues(w http.ResponseWriter, r *http.Request) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, allReports, err := report.GetAllExisting(repo)
|
||||
_, allReports, err := report.All(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче