uquic/internal/wire/version_negotiation_test.go
Marten Seemann cef26922b4 when parsing the header from the invariant header, start from first byte
This will be needed once we implement header encryption, because the
flags in the first byte are encrypted.
2018-11-26 15:57:54 +07:00

35 lines
1.2 KiB
Go

package wire
import (
"bytes"
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Version Negotiation Packets", func() {
It("writes", func() {
srcConnID := protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}
destConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8}
versions := []protocol.VersionNumber{1001, 1003}
data, err := ComposeVersionNegotiation(destConnID, srcConnID, versions)
Expect(err).ToNot(HaveOccurred())
Expect(data[0] & 0x80).ToNot(BeZero())
iHdr, err := ParseInvariantHeader(bytes.NewReader(data), 4)
Expect(err).ToNot(HaveOccurred())
b := bytes.NewReader(data)
hdr, err := iHdr.Parse(b, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
Expect(hdr.IsVersionNegotiation).To(BeTrue())
Expect(hdr.DestConnectionID).To(Equal(destConnID))
Expect(hdr.SrcConnectionID).To(Equal(srcConnID))
Expect(hdr.Version).To(BeZero())
// the supported versions should include one reserved version number
Expect(hdr.SupportedVersions).To(HaveLen(len(versions) + 1))
for _, version := range versions {
Expect(hdr.SupportedVersions).To(ContainElement(version))
}
Expect(b.Len()).To(BeZero())
})
})