internal/format: drop go-fuzz test case

We were not running it in CI, so it had rotted or was going to rot.
We'll replace it with a native fuzz test once that's ready.
This commit is contained in:
Filippo Valsorda
2021-03-09 20:07:07 -05:00
committed by Filippo Valsorda
parent 732f3e8a94
commit 69e2222921
4 changed files with 1 additions and 106 deletions

View File

@@ -1,21 +0,0 @@
# Copyright 2019 Google LLC
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
# docker run --rm -v $PWD/workdir:/workdir $(docker build -q -f internal/format/Dockerfile.go-fuzz .)
FROM golang:1.14-alpine3.11
RUN apk add --no-cache git
RUN go get github.com/dvyukov/go-fuzz/...
ADD . $GOPATH/src/filippo.io/age/
WORKDIR $GOPATH/src/filippo.io/age
RUN go-fuzz-build ./internal/format
VOLUME /workdir
ENTRYPOINT ["go-fuzz", "-workdir", "/workdir", "-bin", "format-fuzz.zip"]

View File

@@ -1,60 +0,0 @@
// Copyright 2019 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
// +build gofuzz
package format
import (
"bytes"
"fmt"
"io"
"strings"
"github.com/sergi/go-diff/diffmatchpatch"
)
func Fuzz(data []byte) int {
isArmored := bytes.HasPrefix(data, []byte("-----BEGIN AGE ENCRYPTED FILE-----"))
h, payload, err := Parse(bytes.NewReader(data))
if err != nil {
if h != nil {
panic("h != nil on error")
}
if payload != nil {
panic("payload != nil on error")
}
return 0
}
w := &bytes.Buffer{}
if isArmored {
w := ArmoredWriter(w)
if err := h.Marshal(w); err != nil {
panic(err)
}
if _, err := io.Copy(w, payload); err != nil {
if strings.Contains(err.Error(), "invalid armor") {
return 0
}
panic(err)
}
w.Close()
} else {
if err := h.Marshal(w); err != nil {
panic(err)
}
if _, err := io.Copy(w, payload); err != nil {
panic(err)
}
}
if !bytes.Equal(w.Bytes(), data) {
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(string(data), string(w.Bytes()), false)
fmt.Println(dmp.DiffToDelta(diffs))
panic("Marshal output different from input")
}
return 1
}