MCPcopy
hub / github.com/livekit/livekit / TestDecompressGzip

Function TestDecompressGzip

pkg/service/utils_test.go:93–129  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func 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}

Callers

nothing calls this directly

Calls 5

DecompressGzipFunction · 0.92
compressFunction · 0.85
RunMethod · 0.45
LenMethod · 0.45
LessMethod · 0.45

Tested by

no test coverage detected