Skip to content

Commit 7fc9099

Browse files
committed
chore: fuzz tests
1 parent 0872dd3 commit 7fc9099

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

pkg/config/config_helpers_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,10 +1493,6 @@ func TestStrContainsArityRegression(t *testing.T) {
14931493
func TestRunCommandOptionsOnlyArityRegression(t *testing.T) {
14941494
t.Parallel()
14951495

1496-
if runtime.GOOS == "windows" {
1497-
t.Skip("Skipping test on Windows because it doesn't support bash")
1498-
}
1499-
15001496
testCases := []struct {
15011497
name string
15021498
params []string

pkg/config/fuzz_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ func FuzzHCLStringHelpers(f *testing.F) {
3838
})
3939
}
4040

41-
// FuzzHCLRunCommandOptions: run_cmd must never panic on any mix of option flags and commands.
41+
// FuzzHCLRunCommandOptions: run_cmd must never panic on any mix of recognized option flags.
42+
// Fuzz input is filtered to known --terragrunt-* flags so the fuzzer cannot launch arbitrary host commands.
4243
func FuzzHCLRunCommandOptions(f *testing.F) {
4344
if runtime.GOOS == "windows" {
4445
f.Skip("run_cmd happy-path requires bash; skip on Windows")
@@ -50,8 +51,6 @@ func FuzzHCLRunCommandOptions(f *testing.F) {
5051
"--terragrunt-global-cache",
5152
"--terragrunt-quiet\x00--terragrunt-no-cache",
5253
"--terragrunt-quiet\x00--terragrunt-quiet",
53-
"--terragrunt-quiet\x00/bin/echo\x00hi",
54-
"/bin/echo\x00hi",
5554
"--terragrunt-no-cache\x00--terragrunt-global-cache",
5655
"--unknown-flag",
5756
"",
@@ -61,7 +60,17 @@ func FuzzHCLRunCommandOptions(f *testing.F) {
6160
}
6261

6362
f.Fuzz(func(t *testing.T, raw string) {
64-
args := strings.Split(raw, "\x00")
63+
parts := strings.Split(raw, "\x00")
64+
65+
args := make([]string, 0, len(parts)+2)
66+
for _, part := range parts {
67+
switch part {
68+
case "--terragrunt-quiet", "--terragrunt-no-cache", "--terragrunt-global-cache":
69+
args = append(args, part)
70+
}
71+
}
72+
73+
args = append(args, "/bin/echo", "hi")
6574

6675
l := logger.CreateLogger()
6776
ctx, pctx := newTestParsingContext(t, "")

0 commit comments

Comments
 (0)