1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-03-10 03:05:55 +00:00

test: Update fuzz tests to use the built-in infrastructure

Go 1.18 supports fuzzing natively, so this patch migrates our fuzzing
tests to make use of it.
This commit is contained in:
Alberto Bertogli
2023-02-05 12:30:25 +00:00
parent a54d81f406
commit efefee9fbb
88 changed files with 246 additions and 470 deletions

View File

@@ -1,6 +1,7 @@
package aliases
import (
"bytes"
"errors"
"os"
"os/exec"
@@ -482,3 +483,10 @@ func TestHookError(t *testing.T) {
t.Errorf("expected *exec.ExitError, got %T - %v", err, err)
}
}
// Fuzz testing for the parser.
func FuzzReader(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
parseReader("domain", bytes.NewReader(data))
})
}

View File

@@ -1,23 +0,0 @@
// Fuzz testing for package aliases.
//go:build gofuzz
// +build gofuzz
package aliases
import "bytes"
func Fuzz(data []byte) int {
interesting := 0
aliases, _ := parseReader("domain", bytes.NewReader(data))
// Mark cases with actual aliases as more interesting.
for _, rcpts := range aliases {
if len(rcpts) > 0 {
interesting = 1
break
}
}
return interesting
}

View File

@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("# First some valid cases.\na: b\nc: d@e, f,\nx: | command\n\n# The following is invalid, should be ignored.\na@dom: x@dom\n\n# Overrides.\no1: a\no1: b\n\n# Finally one to make the file NOT end in \\n:\ny: z\n")

View File

@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("\nfail: | false\n\n")

View File

@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("\naliasA: aliasB@srv-B\n")

View File

@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("\n# Easy aliases.\npepe: jose\njoan: juan\n\n# UTF-8 aliases.\npitanga: ñangapirí\nañil: azul, índigo\n\n# Pipe aliases.\ntubo: | writemailto ../.data/pipe_alias_worked\n\n")

View File

@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("")

View File

@@ -1,14 +0,0 @@
# First some valid cases.
a: b
c: d@e, f,
x: | command
# The following is invalid, should be ignored.
a@dom: x@dom
# Overrides.
o1: a
o1: b
# Finally one to make the file NOT end in \n:
y: z

View File

@@ -1,12 +0,0 @@
# Easy aliases.
pepe: jose
joan: juan
# UTF-8 aliases.
pitanga: ñangapirí
añil: azul, índigo
# Pipe aliases.
tubo: | writemailto ../.data/pipe_alias_worked

View File

@@ -1,3 +0,0 @@
fail: | false

View File

@@ -1,2 +0,0 @@
aliasA: aliasB@srv-B