Merge remote-tracking branch 'origin/master'

This commit is contained in:
stefanbenten
2019-10-28 22:37:27 +01:00
7 changed files with 255 additions and 62 deletions

View File

@ -35,7 +35,7 @@ import (
"encoding/json"
"errors"
"fmt"
blackfriday "gopkg.in/russross/blackfriday.v2"
blackfriday "github.com/russross/blackfriday/v2"
"html"
html_template "html/template"
"io"

90
server/server_fuzz.go Normal file
View File

@ -0,0 +1,90 @@
// +build gofuzz
package server
import (
"bytes"
"io"
"math/rand"
"reflect"
)
const applicationOctetStream = "application/octet-stream"
// FuzzLocalStorage tests the Local Storage.
func FuzzLocalStorage(fuzz []byte) int {
var fuzzLength = uint64(len(fuzz))
if fuzzLength == 0 {
return -1
}
storage, err := NewLocalStorage("/tmp", nil)
if err != nil {
panic("unable to create local storage")
}
token := Encode(10000000 + int64(rand.Intn(1000000000)))
filename := Encode(10000000 + int64(rand.Intn(1000000000))) + ".bin"
input := bytes.NewReader(fuzz)
err = storage.Put(token, filename, input, applicationOctetStream, fuzzLength)
if err != nil {
panic("unable to save file")
}
contentType, contentLength, err := storage.Head(token, filename)
if err != nil {
panic("not visible through head")
}
if contentType != applicationOctetStream {
panic("incorrect content type")
}
if contentLength != fuzzLength {
panic("incorrect content length")
}
output, contentType, contentLength, err := storage.Get(token, filename)
if err != nil {
panic("not visible through get")
}
if contentType != applicationOctetStream {
panic("incorrect content type")
}
if contentLength != fuzzLength {
panic("incorrect content length")
}
var length uint64
b := make([]byte, len(fuzz))
for {
n, err := output.Read(b)
length += uint64(n)
if err == io.EOF {
break
}
}
if !reflect.DeepEqual(b, fuzz) {
panic("incorrect content body")
}
if length != fuzzLength {
panic("incorrect content length")
}
err = storage.Delete(token, filename)
if err != nil {
panic("unable to delete file")
}
_, _, err = storage.Head(token, filename)
if !storage.IsNotExist(err) {
panic("file not deleted")
}
return 1
}