(t *testing.T)
| 91 | } |
| 92 | |
| 93 | func TestDecompressGzip(t *testing.T) { |
| 94 | t.Run("small payload", func(t *testing.T) { |
| 95 | out, err := service.DecompressGzip(compress(t, []byte("hello world"))) |
| 96 | require.NoError(t, err) |
| 97 | require.Equal(t, []byte("hello world"), out) |
| 98 | }) |
| 99 | |
| 100 | t.Run("payload exactly at cap", func(t *testing.T) { |
| 101 | raw := make([]byte, http.DefaultMaxHeaderBytes) |
| 102 | out, err := service.DecompressGzip(compress(t, raw)) |
| 103 | require.NoError(t, err) |
| 104 | require.Len(t, out, http.DefaultMaxHeaderBytes) |
| 105 | }) |
| 106 | |
| 107 | t.Run("payload one byte over capd", func(t *testing.T) { |
| 108 | raw := make([]byte, http.DefaultMaxHeaderBytes+1) |
| 109 | _, err := service.DecompressGzip(compress(t, raw)) |
| 110 | require.ErrorIs(t, err, service.ErrGzipTooLarge) |
| 111 | }) |
| 112 | |
| 113 | t.Run("gzip decompression bomb", func(t *testing.T) { |
| 114 | // 100 MB of zeros |
| 115 | raw := make([]byte, 100<<20) |
| 116 | compressed := compress(t, raw) |
| 117 | require.Less(t, len(compressed), 1<<20, |
| 118 | "sanity: bomb input should compress dramatically") |
| 119 | |
| 120 | _, err := service.DecompressGzip(compressed) |
| 121 | require.ErrorIs(t, err, service.ErrGzipTooLarge) |
| 122 | }) |
| 123 | |
| 124 | t.Run("malformed gzip compression", func(t *testing.T) { |
| 125 | _, err := service.DecompressGzip([]byte("not gzip data")) |
| 126 | require.Error(t, err) |
| 127 | require.Contains(t, err.Error(), "cannot read decompressed") |
| 128 | }) |
| 129 | } |
nothing calls this directly
no test coverage detected