From 45e43d5d12f051fe5e9f538f0f237d58016b6866 Mon Sep 17 00:00:00 2001 From: Kamil Kisiel Date: Tue, 18 Aug 2015 13:59:03 -0700 Subject: Added fuzz testing facilities. --- fuzz/gencorpus.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 fuzz/gencorpus.go (limited to 'fuzz/gencorpus.go') diff --git a/fuzz/gencorpus.go b/fuzz/gencorpus.go new file mode 100644 index 0000000..368192b --- /dev/null +++ b/fuzz/gencorpus.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + "io" + "math/rand" + "os" + "reflect" + "testing/quick" + + "github.com/gorilla/securecookie" +) + +var hashKey = []byte("very-secret12345") +var blockKey = []byte("a-lot-secret1234") +var s = securecookie.New(hashKey, blockKey) + +type Cookie struct { + B bool + I int + S string +} + +func main() { + var c Cookie + t := reflect.TypeOf(c) + rnd := rand.New(rand.NewSource(0)) + for i := 0; i < 100; i++ { + v, ok := quick.Value(t, rnd) + if !ok { + panic("couldn't generate value") + } + encoded, err := s.Encode("fuzz", v.Interface()) + if err != nil { + panic(err) + } + f, err := os.Create(fmt.Sprintf("corpus/%d.sc", i)) + if err != nil { + panic(err) + } + _, err = io.WriteString(f, encoded) + if err != nil { + panic(err) + } + f.Close() + } +} -- cgit v1.2.3