forked from quic-go/quic-go
wire: correctly parse multi-byte frame types (#3736)
This commit is contained in:
@@ -13,8 +13,7 @@ import (
|
||||
var _ = Describe("NEW_CONNECTION_ID frame", func() {
|
||||
Context("when parsing", func() {
|
||||
It("accepts a sample frame", func() {
|
||||
data := []byte{0x18}
|
||||
data = append(data, encodeVarInt(0xdeadbeef)...) // sequence number
|
||||
data := encodeVarInt(0xdeadbeef) // sequence number
|
||||
data = append(data, encodeVarInt(0xcafe)...) // retire prior to
|
||||
data = append(data, 10) // connection ID length
|
||||
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...) // connection ID
|
||||
@@ -26,35 +25,31 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() {
|
||||
Expect(frame.RetirePriorTo).To(Equal(uint64(0xcafe)))
|
||||
Expect(frame.ConnectionID).To(Equal(protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})))
|
||||
Expect(string(frame.StatelessResetToken[:])).To(Equal("deadbeefdecafbad"))
|
||||
Expect(b.Len()).To(BeZero())
|
||||
})
|
||||
|
||||
It("errors when the Retire Prior To value is larger than the Sequence Number", func() {
|
||||
data := []byte{0x18}
|
||||
data = append(data, encodeVarInt(1000)...) // sequence number
|
||||
data := encodeVarInt(1000) // sequence number
|
||||
data = append(data, encodeVarInt(1001)...) // retire prior to
|
||||
data = append(data, 3)
|
||||
data = append(data, []byte{1, 2, 3}...)
|
||||
data = append(data, []byte("deadbeefdecafbad")...) // stateless reset token
|
||||
b := bytes.NewReader(data)
|
||||
_, err := parseNewConnectionIDFrame(b, protocol.Version1)
|
||||
_, err := parseNewConnectionIDFrame(bytes.NewReader(data), protocol.Version1)
|
||||
Expect(err).To(MatchError("Retire Prior To value (1001) larger than Sequence Number (1000)"))
|
||||
})
|
||||
|
||||
It("errors when the connection ID has an invalid length", func() {
|
||||
data := []byte{0x18}
|
||||
data = append(data, encodeVarInt(0xdeadbeef)...) // sequence number
|
||||
data := encodeVarInt(0xdeadbeef) // sequence number
|
||||
data = append(data, encodeVarInt(0xcafe)...) // retire prior to
|
||||
data = append(data, 21) // connection ID length
|
||||
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}...) // connection ID
|
||||
data = append(data, []byte("deadbeefdecafbad")...) // stateless reset token
|
||||
b := bytes.NewReader(data)
|
||||
_, err := parseNewConnectionIDFrame(b, protocol.Version1)
|
||||
_, err := parseNewConnectionIDFrame(bytes.NewReader(data), protocol.Version1)
|
||||
Expect(err).To(MatchError(protocol.ErrInvalidConnectionIDLen))
|
||||
})
|
||||
|
||||
It("errors on EOFs", func() {
|
||||
data := []byte{0x18}
|
||||
data = append(data, encodeVarInt(0xdeadbeef)...) // sequence number
|
||||
data := encodeVarInt(0xdeadbeef) // sequence number
|
||||
data = append(data, encodeVarInt(0xcafe1234)...) // retire prior to
|
||||
data = append(data, 10) // connection ID length
|
||||
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...) // connection ID
|
||||
@@ -62,7 +57,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() {
|
||||
_, err := parseNewConnectionIDFrame(bytes.NewReader(data), protocol.Version1)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
for i := range data {
|
||||
_, err := parseNewConnectionIDFrame(bytes.NewReader(data[0:i]), protocol.Version1)
|
||||
_, err := parseNewConnectionIDFrame(bytes.NewReader(data[:i]), protocol.Version1)
|
||||
Expect(err).To(MatchError(io.EOF))
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user