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 <[email protected]>

* force repo to lowercase when comparing names.

Signed-off-by: Spencer Schrock <[email protected]>

---------

Signed-off-by: Spencer Schrock <[email protected]>
  • Loading branch information
spencerschrock authored 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.