Skip to content

Commit 6c5d964

Browse files
🐛 Fix broken go mod download check (#2550)
- Fixed the #2549 Signed-off-by: naveensrinivasan <[email protected]> Signed-off-by: naveensrinivasan <[email protected]>
1 parent a71b47e commit 6c5d964

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

checks/raw/shell_download_validate.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ func isGoUnpinnedDownload(cmd []string) bool {
425425
if !isBinaryName("go", cmd[0]) {
426426
return false
427427
}
428-
429428
// `Go install` will automatically look up the
430429
// go.mod and go.sum, so we don't flag it.
431430
if len(cmd) <= 2 {
@@ -456,6 +455,10 @@ func isGoUnpinnedDownload(cmd []string) bool {
456455
i++
457456
}
458457

458+
if i+1 >= len(cmd) {
459+
// this is case go get -d -v
460+
return false
461+
}
459462
// TODO check more than one package
460463
pkg := cmd[i+1]
461464
// Consider strings that are not URLs as local folders

checks/raw/shell_download_validate_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,36 @@ func TestValidateShellFile(t *testing.T) {
106106
t.Errorf("failed to detect shell parsing error: %v", err)
107107
}
108108
}
109+
110+
func Test_isGoUnpinnedDownload(t *testing.T) {
111+
type args struct {
112+
cmd []string
113+
}
114+
tests := []struct {
115+
name string
116+
args args
117+
want bool
118+
}{
119+
{
120+
name: "go get",
121+
args: args{
122+
cmd: []string{"go", "get", "github.com/ossf/scorecard"},
123+
},
124+
want: true,
125+
},
126+
{
127+
name: "go get with -d -v",
128+
args: args{
129+
cmd: []string{"go", "get", "-d", "-v"},
130+
},
131+
want: false,
132+
},
133+
}
134+
for _, tt := range tests {
135+
t.Run(tt.name, func(t *testing.T) {
136+
if got := isGoUnpinnedDownload(tt.args.cmd); got != tt.want {
137+
t.Errorf("isGoUnpinnedDownload() = %v, want %v", got, tt.want)
138+
}
139+
})
140+
}
141+
}

0 commit comments

Comments
 (0)