fix putting of a nil ClientSessionState into a qtls.ClientSessionCache

This commit is contained in:
Marten Seemann
2019-10-13 05:09:59 -07:00
parent 413dd08bc6
commit efe65b5491
2 changed files with 13 additions and 0 deletions

View File

@@ -51,6 +51,10 @@ func (c *clientSessionCache) Get(sessionKey string) (*qtls.ClientSessionState, b
}
func (c *clientSessionCache) Put(sessionKey string, cs *qtls.ClientSessionState) {
if cs == nil {
c.ClientSessionCache.Put(sessionKey, nil)
return
}
// qtls.ClientSessionState is identical to the tls.ClientSessionState.
// In order to allow users of quic-go to use a tls.Config,
// we need this workaround to use the ClientSessionCache.

View File

@@ -125,5 +125,14 @@ var _ = Describe("qtls.Config generation", func() {
_, ok := qtlsConf.ClientSessionCache.Get("raboof")
Expect(ok).To(BeTrue())
})
It("puts a nil session state", func() {
csc := NewMockClientSessionCache(mockCtrl)
tlsConf := &tls.Config{ClientSessionCache: csc}
qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{})
// put something
csc.EXPECT().Put("foobar", nil)
qtlsConf.ClientSessionCache.Put("foobar", nil)
})
})
})