| 54 | } |
| 55 | |
| 56 | func TestReadFrameTooLarge(t *testing.T) { |
| 57 | t.Parallel() |
| 58 | |
| 59 | // Hand construct a header that indicates the message size exceeds the maximum |
| 60 | // message size for codec.TagV1 by one. We just write the header to buf because |
| 61 | // we expect codec.ReadFrame to bail out when reading the invalid length. |
| 62 | header := uint32(codec.TagV1)<<codec.DataLength | (codec.MaxMessageSizeV1 + 1) |
| 63 | data := make([]byte, 4) |
| 64 | binary.BigEndian.PutUint32(data, header) |
| 65 | |
| 66 | var buf bytes.Buffer |
| 67 | _, err := buf.Write(data) |
| 68 | require.NoError(t, err) |
| 69 | |
| 70 | readBuf := make([]byte, 1) |
| 71 | _, _, err = codec.ReadFrame(&buf, readBuf) |
| 72 | require.ErrorIs(t, err, codec.ErrMessageTooLarge) |
| 73 | } |
| 74 | |
| 75 | func TestReadFrameEmptyReader(t *testing.T) { |
| 76 | t.Parallel() |