diff --git a/Taskfile.yml b/Taskfile.yml index b3d058e16..314ac2390 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -47,10 +47,15 @@ tasks: cmds: - scripts/fuzz.sh ./internal/tmpl 30s + fuzz:artifact: + cmds: + - scripts/fuzz.sh ./internal/artifact 30s + fuzz: desc: Run fuzz tests cmds: - task: fuzz:tmpl + - task: fuzz:artifact test:golden:update: desc: Run all tests that write goldne files, updating the files. diff --git a/internal/artifact/artifact_fuzz_test.go b/internal/artifact/artifact_fuzz_test.go index 6e6a7695f..bfe5ffd55 100644 --- a/internal/artifact/artifact_fuzz_test.go +++ b/internal/artifact/artifact_fuzz_test.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "os" "path/filepath" - "strings" "testing" ) @@ -36,11 +35,9 @@ func FuzzChecksum(f *testing.F) { "blake2s": true, "sha224": true, "sha384": true, - "sha3-256": true, - "sha3-512": true, "sha3-224": true, - "sha3-384": true, "sha3-256": true, + "sha3-384": true, "sha3-512": true, } @@ -81,6 +78,28 @@ func FuzzChecksumLargeData(f *testing.F) { t.Skip() } + // Skip invalid algorithms + validAlgorithms := map[string]bool{ + "sha256": true, + "md5": true, + "sha1": true, + "crc32": true, + "sha512": true, + "blake2b": true, + "blake2s": true, + "sha224": true, + "sha384": true, + "sha3-224": true, + "sha3-256": true, + "sha3-384": true, + "sha3-512": true, + } + + // Only test with valid algorithms to avoid expected errors + if !validAlgorithms[algorithm] { + t.Skip() + } + // Generate random data of specified size data := make([]byte, size) if _, err := rand.Read(data); err != nil { diff --git a/internal/artifact/testdata/fuzz/FuzzChecksumLargeData/9f2a0bc58229b2e8 b/internal/artifact/testdata/fuzz/FuzzChecksumLargeData/9f2a0bc58229b2e8 new file mode 100644 index 000000000..7ba605995 --- /dev/null +++ b/internal/artifact/testdata/fuzz/FuzzChecksumLargeData/9f2a0bc58229b2e8 @@ -0,0 +1,3 @@ +go test fuzz v1 +string("0") +int(50000) diff --git a/scripts/fuzz.sh b/scripts/fuzz.sh index d5336d355..7397abff6 100755 --- a/scripts/fuzz.sh +++ b/scripts/fuzz.sh @@ -1,10 +1,11 @@ #!/bin/bash pkg="$1" -timeout="$1" +timeout="$2" -grep "func Fuzz" "$pkg" | - cut -f1 -d'(' | +grep "func Fuzz" "$pkg"/*.go | cut -f2 -d' ' | + cut -f1 -d'(' | while read -r f; do go test -fuzztime="$timeout" -fuzz="$f" "$pkg"/... done +go test "$pkg"/...