Skip to content

Commit

Permalink
🐛 Fix parsing OSSFuzz project repos with subfolders and capitalizatio…
Browse files Browse the repository at this point in the history
…n. (#3364)

* Split main_repo with correct number of parts. Add go-cmp test.

Signed-off-by: Spencer Schrock <sschrock@google.com>

* force repo to lowercase when comparing names.

Signed-off-by: Spencer Schrock <sschrock@google.com>

---------

Signed-off-by: Spencer Schrock <sschrock@google.com>
  • Loading branch information
spencerschrock committed Aug 9, 2023
1 parent 22fb10c commit 9033d51
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
10 changes: 6 additions & 4 deletions clients/ossfuzz/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
14 changes: 14 additions & 0 deletions clients/ossfuzz/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions clients/ossfuzz/testdata/status.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}

0 comments on commit 9033d51

Please sign in to comment.