add an integration test for HelloRetryRequests

This commit is contained in:
Marten Seemann
2019-03-10 12:27:00 +09:00
parent f103919bf1
commit dc3ad9ccc5

View File

@@ -2,7 +2,6 @@ package self_test
import ( import (
"crypto/tls" "crypto/tls"
"fmt"
"net" "net"
"time" "time"
@@ -20,6 +19,7 @@ var _ = Describe("Handshake RTT tests", func() {
proxy *quicproxy.QuicProxy proxy *quicproxy.QuicProxy
server quic.Listener server quic.Listener
serverConfig *quic.Config serverConfig *quic.Config
serverTLSConfig *tls.Config
testStartedAt time.Time testStartedAt time.Time
acceptStopped chan struct{} acceptStopped chan struct{}
) )
@@ -29,6 +29,7 @@ var _ = Describe("Handshake RTT tests", func() {
BeforeEach(func() { BeforeEach(func() {
acceptStopped = make(chan struct{}) acceptStopped = make(chan struct{})
serverConfig = &quic.Config{} serverConfig = &quic.Config{}
serverTLSConfig = testdata.GetTLSConfig()
}) })
AfterEach(func() { AfterEach(func() {
@@ -40,7 +41,7 @@ var _ = Describe("Handshake RTT tests", func() {
runServerAndProxy := func() { runServerAndProxy := func() {
var err error var err error
// start the server // start the server
server, err = quic.ListenAddr("localhost:0", testdata.GetTLSConfig(), serverConfig) server, err = quic.ListenAddr("localhost:0", serverTLSConfig, serverConfig)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
// start the proxy // start the proxy
proxy, err = quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{ proxy, err = quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
@@ -83,7 +84,6 @@ var _ = Describe("Handshake RTT tests", func() {
} }
_, err := quic.DialAddr(proxy.LocalAddr().String(), nil, clientConfig) _, err := quic.DialAddr(proxy.LocalAddr().String(), nil, clientConfig)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
fmt.Println(err)
// Expect(err.(qerr.ErrorCode)).To(Equal(qerr.InvalidVersion)) // Expect(err.(qerr.ErrorCode)).To(Equal(qerr.InvalidVersion))
expectDurationInRTTs(1) expectDurationInRTTs(1)
}) })
@@ -113,7 +113,7 @@ var _ = Describe("Handshake RTT tests", func() {
expectDurationInRTTs(2) expectDurationInRTTs(2)
}) })
It("is forward-secure after 1 RTTs when the server doesn't require a Cookie", func() { It("establishes a connection in 1 RTT when the server doesn't require a Cookie", func() {
serverConfig.AcceptCookie = func(_ net.Addr, _ *quic.Cookie) bool { serverConfig.AcceptCookie = func(_ net.Addr, _ *quic.Cookie) bool {
return true return true
} }
@@ -127,6 +127,21 @@ var _ = Describe("Handshake RTT tests", func() {
expectDurationInRTTs(1) expectDurationInRTTs(1)
}) })
It("establishes a connection in 2 RTTs if a HelloRetryRequest is performed", func() {
serverConfig.AcceptCookie = func(_ net.Addr, _ *quic.Cookie) bool {
return true
}
serverTLSConfig.CurvePreferences = []tls.CurveID{tls.CurveP384}
runServerAndProxy()
_, err := quic.DialAddr(
proxy.LocalAddr().String(),
clientTLSConfig,
clientConfig,
)
Expect(err).ToNot(HaveOccurred())
expectDurationInRTTs(2)
})
It("doesn't complete the handshake when the server never accepts the Cookie", func() { It("doesn't complete the handshake when the server never accepts the Cookie", func() {
serverConfig.AcceptCookie = func(_ net.Addr, _ *quic.Cookie) bool { serverConfig.AcceptCookie = func(_ net.Addr, _ *quic.Cookie) bool {
return false return false