-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_test.go
More file actions
147 lines (127 loc) · 3.62 KB
/
fuzz_test.go
File metadata and controls
147 lines (127 loc) · 3.62 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package config
import (
"os"
"testing"
)
// FuzzGetBoolEnv tests the getBoolEnv function with various malformed inputs
func FuzzGetBoolEnv(f *testing.F) {
// Seed corpus with known values
f.Add("true")
f.Add("false")
f.Add("1")
f.Add("0")
f.Add("TRUE")
f.Add("FALSE")
f.Add("")
f.Add("invalid")
f.Add("truee")
f.Add("falsee")
f.Fuzz(func(t *testing.T, value string) {
// Set environment variable with fuzzed value
key := "FUZZ_TEST_BOOL_VAR"
_ = os.Setenv(key, value)
defer func() { _ = os.Unsetenv(key) }()
// Function should never panic regardless of input
result := getBoolEnv(key, false)
// Result should always be a boolean
if result != true && result != false {
t.Errorf("getBoolEnv returned non-boolean value: %v", result)
}
})
}
// FuzzGetIntEnv tests the getIntEnv function with various malformed inputs
func FuzzGetIntEnv(f *testing.F) {
// Seed corpus with known values
f.Add("0")
f.Add("1")
f.Add("-1")
f.Add("100")
f.Add("invalid")
f.Add("")
f.Add("9999999999999999999999")
f.Add("1.5")
f.Add("0x10")
f.Add("10e3")
f.Fuzz(func(t *testing.T, value string) {
// Set environment variable with fuzzed value
key := "FUZZ_TEST_INT_VAR"
_ = os.Setenv(key, value)
defer func() { _ = os.Unsetenv(key) }()
// Function should never panic regardless of input
result := getIntEnv(key, 42)
// Result should always be an integer
if result < -2147483648 || result > 2147483647 {
t.Errorf("getIntEnv returned out-of-range value: %d", result)
}
})
}
// FuzzGetStringEnv tests the getStringEnv function with various inputs
func FuzzGetStringEnv(f *testing.F) {
// Seed corpus with various string inputs
f.Add("")
f.Add("normal")
f.Add("with spaces")
f.Add("\n\t\r")
f.Add("unicode: 🚀")
f.Add("null\x00byte")
f.Add("very long string that might cause issues: " + string(make([]byte, 1000)))
f.Fuzz(func(_ *testing.T, value string) {
// Set environment variable with fuzzed value
key := "FUZZ_TEST_STRING_VAR"
_ = os.Setenv(key, value)
defer func() { _ = os.Unsetenv(key) }()
// Function should never panic regardless of input
result := getStringEnv(key, "default")
// Result should always be a string - function may trim or process the value
// Only check for completely unexpected behavior
_ = result // Just ensure we got a result
})
}
// FuzzConfigValidation tests config validation with malformed configurations
func FuzzConfigValidation(f *testing.F) {
// Seed corpus with various config scenarios
f.Add("debug")
f.Add("info")
f.Add("warn")
f.Add("error")
f.Add("invalid")
f.Add("")
f.Add("DEBUG")
f.Add("debug\x00")
f.Fuzz(func(_ *testing.T, logLevel string) {
cfg := &Config{
Enabled: true,
LogLevel: logLevel,
MaxFileSize: 1024 * 1024,
MaxFilesOpen: 100,
Timeout: 60,
}
cfg.Performance.ParallelWorkers = 2
// Validation should never panic regardless of input
err := cfg.Validate()
// Should return validation error or nil - both are acceptable
_ = err // Validation may succeed or fail, both are fine
})
}
// FuzzIsValidVersion tests version validation with various malformed versions
func FuzzIsValidVersion(f *testing.F) {
// Seed corpus with version-like strings
f.Add("v1.0.0")
f.Add("v1.2.3")
f.Add("1.0.0")
f.Add("v1.0")
f.Add("v1")
f.Add("invalid")
f.Add("")
f.Add("v1.0.0-beta")
f.Add("v1.0.0+build")
f.Add("v999.999.999")
f.Fuzz(func(t *testing.T, version string) {
// Function should never panic regardless of input
result := isValidVersion(version)
// Result should always be a boolean
if result != true && result != false {
t.Errorf("isValidVersion returned non-boolean value: %v", result)
}
})
}