Merge pull request #2042 from lucas-clemente/token-cache

implement a store for address validation tokes
This commit is contained in:
Marten Seemann 2019-08-25 14:02:16 +07:00 committed by GitHub
commit f1d14ecdea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 457 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/rand"
"crypto/tls"
"errors"
"net"
"runtime/pprof"
@ -311,6 +312,13 @@ var _ = Describe("Session", func() {
Expect(frames).To(Equal([]wire.Frame{&wire.PathResponseFrame{Data: data}}))
})
It("rejects NEW_TOKEN frames", func() {
err := sess.handleNewTokenFrame(&wire.NewTokenFrame{})
Expect(err).To(HaveOccurred())
Expect(err).To(BeAssignableToTypeOf(&qerr.QuicError{}))
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.ProtocolViolation))
})
It("handles BLOCKED frames", func() {
err := sess.handleFrame(&wire.DataBlockedFrame{}, 0, protocol.EncryptionUnspecified)
Expect(err).NotTo(HaveOccurred())
@ -1581,6 +1589,8 @@ var _ = Describe("Client Session", func() {
packer *MockPacker
mconn *mockConnection
cryptoSetup *mocks.MockCryptoSetup
tlsConf *tls.Config
quicConf *Config
)
getPacket := func(hdr *wire.ExtendedHeader, data []byte) *receivedPacket {
@ -1593,8 +1603,15 @@ var _ = Describe("Client Session", func() {
}
BeforeEach(func() {
quicConf = populateClientConfig(&Config{}, true)
})
JustBeforeEach(func() {
Eventually(areSessionsRunning).Should(BeFalse())
if tlsConf == nil {
tlsConf = &tls.Config{}
}
mconn = newMockConnection()
sessionRunner = NewMockSessionRunner(mockCtrl)
sessP, err := newClientSession(
@ -1602,9 +1619,9 @@ var _ = Describe("Client Session", func() {
sessionRunner,
protocol.ConnectionID{8, 7, 6, 5, 4, 3, 2, 1},
protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
populateClientConfig(&Config{}, true),
nil, // tls.Config
42, // initial packet number
quicConf,
tlsConf,
42, // initial packet number
&handshake.TransportParameters{},
protocol.VersionTLS,
utils.DefaultLogger,
@ -1653,10 +1670,27 @@ var _ = Describe("Client Session", func() {
Eventually(sess.Context().Done()).Should(BeClosed())
})
Context("handling tokens", func() {
var mockTokenStore *MockTokenStore
BeforeEach(func() {
mockTokenStore = NewMockTokenStore(mockCtrl)
tlsConf = &tls.Config{ServerName: "server"}
quicConf.TokenStore = mockTokenStore
mockTokenStore.EXPECT().Pop(gomock.Any())
quicConf.TokenStore = mockTokenStore
})
It("handles NEW_TOKEN frames", func() {
mockTokenStore.EXPECT().Put("server", &ClientToken{data: []byte("foobar")})
Expect(sess.handleNewTokenFrame(&wire.NewTokenFrame{Token: []byte("foobar")})).To(Succeed())
})
})
Context("handling Retry", func() {
var validRetryHdr *wire.ExtendedHeader
BeforeEach(func() {
JustBeforeEach(func() {
validRetryHdr = &wire.ExtendedHeader{
Header: wire.Header{
IsLongHeader: true,