From 46f8c07daa1b3a4841e1d2a0eef85f80a30f945c Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 27 Aug 2018 09:07:11 +0700 Subject: [PATCH] improve the version negotiation integration test --- integrationtests/self/handshake_test.go | 11 +++++++++-- internal/protocol/version.go | 2 +- internal/wire/header_test.go | 6 +++--- packet_handler_map_test.go | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/integrationtests/self/handshake_test.go b/integrationtests/self/handshake_test.go index 5baf6d74..b3a77194 100644 --- a/integrationtests/self/handshake_test.go +++ b/integrationtests/self/handshake_test.go @@ -12,6 +12,10 @@ import ( . "github.com/onsi/gomega" ) +type versioner interface { + GetVersion() protocol.VersionNumber +} + var _ = Describe("Handshake tests", func() { var ( server quic.Listener @@ -67,19 +71,22 @@ var _ = Describe("Handshake tests", func() { // but it supports a bunch of versions that the client doesn't speak serverConfig.Versions = []protocol.VersionNumber{protocol.SupportedVersions[1], 7, 8, 9} runServer() - _, err := quic.DialAddr(server.Addr().String(), &tls.Config{InsecureSkipVerify: true}, nil) + sess, err := quic.DialAddr(server.Addr().String(), &tls.Config{InsecureSkipVerify: true}, nil) Expect(err).ToNot(HaveOccurred()) + Expect(sess.(versioner).GetVersion()).To(Equal(protocol.SupportedVersions[1])) }) It("when the client supports more versions than the server supports", func() { // the server doesn't support the highest supported version, which is the first one the client will try // but it supports a bunch of versions that the client doesn't speak + serverConfig.Versions = supportedVersions runServer() conf := &quic.Config{ Versions: []protocol.VersionNumber{7, 8, 9, protocol.SupportedVersions[1], 10}, } - _, err := quic.DialAddr(server.Addr().String(), &tls.Config{InsecureSkipVerify: true}, conf) + sess, err := quic.DialAddr(server.Addr().String(), &tls.Config{InsecureSkipVerify: true}, conf) Expect(err).ToNot(HaveOccurred()) + Expect(sess.(versioner).GetVersion()).To(Equal(protocol.SupportedVersions[1])) }) }) diff --git a/internal/protocol/version.go b/internal/protocol/version.go index 1ecfd35a..023164f5 100644 --- a/internal/protocol/version.go +++ b/internal/protocol/version.go @@ -41,7 +41,7 @@ func IsValidVersion(v VersionNumber) bool { // UsesTLS says if this QUIC version uses TLS 1.3 for the handshake func (vn VersionNumber) UsesTLS() bool { - return vn == VersionTLS + return !vn.isGQUIC() } func (vn VersionNumber) String() string { diff --git a/internal/wire/header_test.go b/internal/wire/header_test.go index 78e9ff93..a9a4fcf1 100644 --- a/internal/wire/header_test.go +++ b/internal/wire/header_test.go @@ -267,7 +267,7 @@ var _ = Describe("Header", func() { PacketNumber: 2, PacketNumberLen: protocol.PacketNumberLen2, } - err := hdr.Write(buf, protocol.PerspectiveServer, protocol.VersionWhatever) + err := hdr.Write(buf, protocol.PerspectiveServer, versionPublicHeader) Expect(err).To(MatchError("PublicHeader: wrong length for Connection ID: 7 (expected 8)")) }) @@ -277,7 +277,7 @@ var _ = Describe("Header", func() { DestConnectionID: connID, PacketNumber: 2, } - err := hdr.Write(buf, protocol.PerspectiveServer, protocol.VersionWhatever) + err := hdr.Write(buf, protocol.PerspectiveServer, versionPublicHeader) Expect(err).To(MatchError("PublicHeader: PacketNumberLen not set")) }) @@ -286,7 +286,7 @@ var _ = Describe("Header", func() { PacketNumberLen: protocol.PacketNumberLen1, PacketNumber: 1, } - err := hdr.Write(buf, protocol.PerspectiveServer, protocol.VersionWhatever) + err := hdr.Write(buf, protocol.PerspectiveServer, versionPublicHeader) Expect(err).ToNot(HaveOccurred()) Expect(buf.Bytes()).To(Equal([]byte{0x0, 0x1})) }) diff --git a/packet_handler_map_test.go b/packet_handler_map_test.go index 04eaaab8..4986081f 100644 --- a/packet_handler_map_test.go +++ b/packet_handler_map_test.go @@ -24,7 +24,7 @@ var _ = Describe("Packet Handler Map", func() { err := (&wire.Header{ DestConnectionID: connID, PacketNumberLen: protocol.PacketNumberLen1, - }).Write(buf, protocol.PerspectiveServer, protocol.VersionWhatever) + }).Write(buf, protocol.PerspectiveServer, versionGQUICFrames) Expect(err).ToNot(HaveOccurred()) return buf.Bytes() }