-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_test.go
More file actions
57 lines (50 loc) · 1.3 KB
/
fuzz_test.go
File metadata and controls
57 lines (50 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"bytes"
"testing"
)
func FuzzParseJailFile(f *testing.F) {
f.Add([]byte("+ 'ls -l\n- r'^rm"))
f.Add([]byte("# A comment\n\n+ 'whoami"))
f.Add([]byte("malformed line"))
f.Add([]byte("+"))
f.Add([]byte("- r'['")) // Invalid regex
f.Fuzz(func(t *testing.T, data []byte) {
conf := Config{
JailFile: "fuzz.jail",
ShellCmd: []string{"bash", "-c"},
}
// The function should never panic. It should either return a valid
// JailFile or a parsing error.
_, _ = parseJailFile(conf, bytes.NewReader(data))
})
}
func FuzzEvaluateCmd(f *testing.F) {
jailFileContent := `
+ 'whoami
+ 'ls -l
- r'^rm
+ grep -qE '^(date|uptime)'
`
conf := Config{
JailFile: "fuzz.jail",
ShellCmd: []string{"bash", "-c"},
}
jailFile, err := parseJailFile(conf, bytes.NewReader([]byte(jailFileContent)))
if err != nil {
f.Fatalf("Failed to parse seed jail file: %v", err)
}
f.Add("ls -l")
f.Add("whoami")
f.Add("rm -rf /")
f.Add("date")
f.Add("uptime")
f.Add("echo; whoami")
f.Add("'; whoami #")
f.Add(string([]byte{0x00, 0x01, 0x02})) // Non-printable characters
f.Fuzz(func(t *testing.T, intentCmd string) {
// The evaluation function should never panic, regardless of the
// intent command string. It should always return a valid CheckResult.
_ = evaluateCmd(intentCmd, jailFile)
})
}