move the check for empty payload to the unpacker

This commit is contained in:
Marten Seemann 2022-08-27 11:57:00 +03:00
parent fd1b3a23c4
commit e3723a0ef1
4 changed files with 31 additions and 38 deletions

View file

@ -155,7 +155,7 @@ var _ = Describe("Packet Unpacker", func() {
Expect(packet.data).To(Equal([]byte("decrypted")))
})
It("returns the error when getting the sealer fails", func() {
It("returns the error when getting the opener fails", func() {
extHdr := &wire.ExtendedHeader{
Header: wire.Header{DestConnectionID: connID},
PacketNumber: 0x1337,
@ -167,6 +167,28 @@ var _ = Describe("Packet Unpacker", func() {
Expect(err).To(MatchError(handshake.ErrKeysNotYetAvailable))
})
It("errors on empty packets", func() {
extHdr := &wire.ExtendedHeader{
Header: wire.Header{DestConnectionID: connID},
KeyPhase: protocol.KeyPhaseOne,
PacketNumberLen: protocol.PacketNumberLen4,
}
hdr, hdrRaw := getHeader(extHdr)
opener := mocks.NewMockShortHeaderOpener(mockCtrl)
now := time.Now()
gomock.InOrder(
cs.EXPECT().Get1RTTOpener().Return(opener, nil),
opener.EXPECT().DecryptHeader(gomock.Any(), gomock.Any(), gomock.Any()),
opener.EXPECT().DecodePacketNumber(gomock.Any(), gomock.Any()).Return(protocol.PacketNumber(321)),
opener.EXPECT().Open(gomock.Any(), payload, now, protocol.PacketNumber(321), protocol.KeyPhaseOne, hdrRaw).Return([]byte(""), nil),
)
_, err := unpacker.Unpack(hdr, now, append(hdrRaw, payload...))
Expect(err).To(MatchError(&qerr.TransportError{
ErrorCode: qerr.ProtocolViolation,
ErrorMessage: "empty packet",
}))
})
It("returns the error when unpacking fails", func() {
extHdr := &wire.ExtendedHeader{
Header: wire.Header{