From 9033d5149647fc72ae91429ac95df29ea9dd74ce Mon Sep 17 00:00:00 2001 From: Spencer Schrock Date: Wed, 9 Aug 2023 13:18:26 -0700 Subject: [PATCH] :bug: Fix parsing OSSFuzz project repos with subfolders and capitalization. (#3364) * Split main_repo with correct number of parts. Add go-cmp test. Signed-off-by: Spencer Schrock * force repo to lowercase when comparing names. Signed-off-by: Spencer Schrock --------- Signed-off-by: Spencer Schrock --- clients/ossfuzz/client.go | 10 ++++++---- clients/ossfuzz/client_test.go | 14 ++++++++++++++ clients/ossfuzz/testdata/status.json | 8 ++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/clients/ossfuzz/client.go b/clients/ossfuzz/client.go index 02799fe5d50..054ea50a122 100644 --- a/clients/ossfuzz/client.go +++ b/clients/ossfuzz/client.go @@ -83,7 +83,8 @@ func (c *client) Search(request clients.SearchRequest) (clients.SearchResponse, if c.err != nil { return sr, c.err } - if c.projects[request.Query] { + projectURI := strings.ToLower(request.Query) + if c.projects[projectURI] { sr.Hits = 1 } return sr, nil @@ -135,13 +136,14 @@ func fetchStatusFile(uri string) ([]byte, error) { } func normalize(rawURL string) (string, error) { - u, err := url.Parse(rawURL) + u, err := url.Parse(strings.ToLower(rawURL)) if err != nil { return "", fmt.Errorf("url.Parse: %w", err) } - const splitLen = 2 + const splitLen = 3 // corresponding to owner/repo/rest + const minLen = 2 // corresponds to owner/repo split := strings.SplitN(strings.Trim(u.Path, "/"), "/", splitLen) - if len(split) != splitLen { + if len(split) < minLen { return "", fmt.Errorf("%s: %w", rawURL, errMalformedURL) } org := split[0] diff --git a/clients/ossfuzz/client_test.go b/clients/ossfuzz/client_test.go index 7a964645833..dbb856fd139 100644 --- a/clients/ossfuzz/client_test.go +++ b/clients/ossfuzz/client_test.go @@ -56,6 +56,20 @@ func TestClient(t *testing.T) { wantHit: false, wantErr: false, }, + { + name: "project with main_repo link longer than owner/repo", + project: "github.com/google/go-cmp", + statusFile: "status.json", + wantHit: true, + wantErr: false, + }, + { + name: "project case insensitive", + project: "github.com/FFTW/fftw3", + statusFile: "status.json", + wantHit: true, + wantErr: false, + }, { name: "non existent status file", project: "github.com/ossf/scorecard", diff --git a/clients/ossfuzz/testdata/status.json b/clients/ossfuzz/testdata/status.json index 913ad5e7391..32eaf8271ea 100644 --- a/clients/ossfuzz/testdata/status.json +++ b/clients/ossfuzz/testdata/status.json @@ -19,6 +19,14 @@ { "name": "zydis", "main_repo": "https://github.com/zyantific/zydis.git" + }, + { + "name": "go-cmp", + "main_repo": "https://github.com/google/go-cmp/cmp" + }, + { + "name": "fftw3", + "main_repo": "https://github.com/fftw/fftw3.git" } ] }