Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/valyala/fasthttp"
)

func TestValidateCompressedBody(t *testing.T) {
Expand All @@ -26,6 +27,10 @@ func TestValidateCompressedBody(t *testing.T) {
}
valid := loadTestdata(t, "valid.publiccode.yml")
compressed := compress(valid)
layered := valid
for range 6 {
layered = compress(layered)
}
for _, method := range []string{http.MethodPost, "QUERY"} {
for _, tc := range []struct {
name, encoding, body string
Expand All @@ -35,9 +40,13 @@ func TestValidateCompressedBody(t *testing.T) {
{"truncated", "gzip", compressed[:len(compressed)-5], 400},
{"oversized", "gzip", compress(strings.Repeat("a", 6_000_000)), 413},
{"unsupported", "unknown", valid, 415},
{"too many codings", "gzip, gzip, gzip, gzip, gzip, gzip", layered, 415},
{"unimplemented", "compress", valid, 501},
{"valid", "gzip", compressed, 200},
{"stacked", "gzip, gzip", compress(compressed), 200},
{"x-gzip alias", "x-gzip", compressed, 200},
{"brotli alias", "brotli", string(fasthttp.AppendBrotliBytes(nil, []byte(valid))), 200},
{"identity", "gzip, identity", compressed, 200},
} {
contentType := "application/problem+json"
if tc.status == 200 {
Expand Down
Loading