Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix broken go mod download check #2550

Merged
merged 1 commit into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion checks/raw/shell_download_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ func isGoUnpinnedDownload(cmd []string) bool {
if !isBinaryName("go", cmd[0]) {
return false
}

// `Go install` will automatically look up the
// go.mod and go.sum, so we don't flag it.
if len(cmd) <= 2 {
Expand Down Expand Up @@ -456,6 +455,10 @@ func isGoUnpinnedDownload(cmd []string) bool {
i++
}

if i+1 >= len(cmd) {
// this is case go get -d -v
return false
}
// TODO check more than one package
pkg := cmd[i+1]
// Consider strings that are not URLs as local folders
Expand Down
33 changes: 33 additions & 0 deletions checks/raw/shell_download_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,36 @@ func TestValidateShellFile(t *testing.T) {
t.Errorf("failed to detect shell parsing error: %v", err)
}
}

func Test_isGoUnpinnedDownload(t *testing.T) {
type args struct {
cmd []string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "go get",
args: args{
cmd: []string{"go", "get", "github.com/ossf/scorecard"},
},
want: true,
},
{
name: "go get with -d -v",
args: args{
cmd: []string{"go", "get", "-d", "-v"},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isGoUnpinnedDownload(tt.args.cmd); got != tt.want {
t.Errorf("isGoUnpinnedDownload() = %v, want %v", got, tt.want)
}
})
}
}