fix: break import cycle by inlining fuzz helpers
This commit is contained in:
@@ -3,51 +3,61 @@ package validation
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"unicode/utf8"
|
||||||
"goyco/internal/fuzz"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func FuzzValidateEmail(f *testing.F) {
|
func FuzzValidateEmail(f *testing.F) {
|
||||||
helper := fuzz.NewFuzzTestHelper()
|
runValidationFuzzTest(f, ValidateEmail)
|
||||||
helper.RunValidationFuzzTest(f, ValidateEmail)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FuzzValidateUsername(f *testing.F) {
|
func FuzzValidateUsername(f *testing.F) {
|
||||||
helper := fuzz.NewFuzzTestHelper()
|
runValidationFuzzTest(f, ValidateUsername)
|
||||||
helper.RunValidationFuzzTest(f, ValidateUsername)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FuzzValidatePassword(f *testing.F) {
|
func FuzzValidatePassword(f *testing.F) {
|
||||||
helper := fuzz.NewFuzzTestHelper()
|
runValidationFuzzTest(f, ValidatePassword)
|
||||||
helper.RunValidationFuzzTest(f, ValidatePassword)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FuzzValidateURL(f *testing.F) {
|
func FuzzValidateURL(f *testing.F) {
|
||||||
helper := fuzz.NewFuzzTestHelper()
|
runValidationFuzzTest(f, ValidateURL)
|
||||||
helper.RunValidationFuzzTest(f, ValidateURL)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FuzzValidateTitle(f *testing.F) {
|
func FuzzValidateTitle(f *testing.F) {
|
||||||
helper := fuzz.NewFuzzTestHelper()
|
runValidationFuzzTest(f, ValidateTitle)
|
||||||
helper.RunValidationFuzzTest(f, ValidateTitle)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FuzzValidateContent(f *testing.F) {
|
func FuzzValidateContent(f *testing.F) {
|
||||||
helper := fuzz.NewFuzzTestHelper()
|
runValidationFuzzTest(f, ValidateContent)
|
||||||
helper.RunValidationFuzzTest(f, ValidateContent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FuzzValidateSearchQuery(f *testing.F) {
|
func FuzzValidateSearchQuery(f *testing.F) {
|
||||||
helper := fuzz.NewFuzzTestHelper()
|
runValidationFuzzTest(f, ValidateSearchQuery)
|
||||||
helper.RunValidationFuzzTest(f, ValidateSearchQuery)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FuzzSanitizeString(f *testing.F) {
|
func FuzzSanitizeString(f *testing.F) {
|
||||||
helper := fuzz.NewFuzzTestHelper()
|
f.Add("test input")
|
||||||
helper.RunSanitizationFuzzTestWithValidation(f,
|
f.Fuzz(func(t *testing.T, input string) {
|
||||||
SanitizeString,
|
if !utf8.ValidString(input) {
|
||||||
func(result string) bool {
|
return
|
||||||
return !containsNullBytes(result)
|
}
|
||||||
|
result := SanitizeString(input)
|
||||||
|
if !utf8.ValidString(result) {
|
||||||
|
t.Fatal("Sanitized result contains invalid UTF-8")
|
||||||
|
}
|
||||||
|
if containsNullBytes(result) {
|
||||||
|
t.Fatal("Sanitized result contains null bytes")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func runValidationFuzzTest(f *testing.F, validateFunc func(string) error) {
|
||||||
|
f.Add("test input")
|
||||||
|
f.Fuzz(func(t *testing.T, input string) {
|
||||||
|
if !utf8.ValidString(input) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := validateFunc(input)
|
||||||
|
_ = err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user