Skip to content

Commit 635f23b

Browse files
authored
add fuzz test (#5150)
Signed-off-by: xliuqq <xlzq1992@gmail.com>
1 parent 80194af commit 635f23b

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

pkg/utils/validation/validation_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,23 @@ package validation
1919
import (
2020
"fmt"
2121
"path/filepath"
22+
"strings"
2223
"testing"
2324
)
2425

26+
func FuzzIsSafePath(f *testing.F) {
27+
// f.Add()
28+
f.Fuzz(func(t *testing.T, input string) {
29+
err := IsValidMountRoot(input)
30+
if err == nil {
31+
// valid input must start with "/"
32+
if !strings.HasPrefix(input, string(filepath.Separator)) {
33+
t.Errorf("testcase %s failed, expect the input starts with '/'", input)
34+
}
35+
}
36+
})
37+
}
38+
2539
func TestIsSafePathWithSafePath(t *testing.T) {
2640

2741
type testCase struct {

0 commit comments

Comments
 (0)