MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestReadMessageInvalidLength

Function TestReadMessageInvalidLength

server/wire/protocol_test.go:160–186  ·  view source on GitHub ↗

Regression test for #715 (hardening half): malformed regular-message lengths must return an error, not panic in make().

(t *testing.T)

Source from the content-addressed store, hash-verified

158 }
159 msgType, body, err := ReadMessage(&buf)
160 if err != nil {
161 t.Fatalf("ReadMessage: %v", err)
162 }
163 if msgType != MsgQuery || string(body) != "SELECT 1\x00" {
164 t.Fatalf("unexpected message: type=%c body=%q", msgType, body)
165 }
166}
167
168func TestReadMessageEmptyBody(t *testing.T) {
169 var buf bytes.Buffer
170 if err := WriteMessage(&buf, MsgSync, nil); err != nil {
171 t.Fatalf("WriteMessage: %v", err)
172 }
173 msgType, body, err := ReadMessage(&buf)
174 if err != nil {
175 t.Fatalf("ReadMessage: %v", err)
176 }
177 if msgType != MsgSync || len(body) != 0 {
178 t.Fatalf("unexpected message: type=%c body=%q", msgType, body)
179 }
180}
181
182// Regression test for #715 (hardening half): malformed regular-message
183// lengths must return an error, not panic in make().
184func TestReadMessageInvalidLength(t *testing.T) {
185 cases := []struct {
186 name string
187 length int32
188 }{
189 {"negative", -1},

Callers

nothing calls this directly

Calls 4

ReadMessageFunction · 0.70
RunMethod · 0.65
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected