github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/internal/qtls/go121_test.go (about)

     1  //go:build go1.21
     2  
     3  package qtls
     4  
     5  import (
     6  	"crypto/tls"
     7  
     8  	"github.com/metacubex/quic-go/internal/protocol"
     9  
    10  	. "github.com/onsi/ginkgo/v2"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("Go 1.21", func() {
    15  	It("converts to tls.EncryptionLevel", func() {
    16  		Expect(ToTLSEncryptionLevel(protocol.EncryptionInitial)).To(Equal(tls.QUICEncryptionLevelInitial))
    17  		Expect(ToTLSEncryptionLevel(protocol.EncryptionHandshake)).To(Equal(tls.QUICEncryptionLevelHandshake))
    18  		Expect(ToTLSEncryptionLevel(protocol.Encryption1RTT)).To(Equal(tls.QUICEncryptionLevelApplication))
    19  		Expect(ToTLSEncryptionLevel(protocol.Encryption0RTT)).To(Equal(tls.QUICEncryptionLevelEarly))
    20  	})
    21  
    22  	It("converts from tls.EncryptionLevel", func() {
    23  		Expect(FromTLSEncryptionLevel(tls.QUICEncryptionLevelInitial)).To(Equal(protocol.EncryptionInitial))
    24  		Expect(FromTLSEncryptionLevel(tls.QUICEncryptionLevelHandshake)).To(Equal(protocol.EncryptionHandshake))
    25  		Expect(FromTLSEncryptionLevel(tls.QUICEncryptionLevelApplication)).To(Equal(protocol.Encryption1RTT))
    26  		Expect(FromTLSEncryptionLevel(tls.QUICEncryptionLevelEarly)).To(Equal(protocol.Encryption0RTT))
    27  	})
    28  
    29  	Context("setting up a tls.Config for the client", func() {
    30  		It("sets up a session cache if there's one present on the config", func() {
    31  			csc := tls.NewLRUClientSessionCache(1)
    32  			conf := &QUICConfig{TLSConfig: &tls.Config{ClientSessionCache: csc}}
    33  			SetupConfigForClient(conf, nil, nil)
    34  			Expect(conf.TLSConfig.ClientSessionCache).ToNot(BeNil())
    35  			Expect(conf.TLSConfig.ClientSessionCache).ToNot(Equal(csc))
    36  		})
    37  
    38  		It("doesn't set up a session cache if there's none present on the config", func() {
    39  			conf := &QUICConfig{TLSConfig: &tls.Config{}}
    40  			SetupConfigForClient(conf, nil, nil)
    41  			Expect(conf.TLSConfig.ClientSessionCache).To(BeNil())
    42  		})
    43  	})
    44  
    45  	Context("setting up a tls.Config for the server", func() {
    46  		It("sets the minimum TLS version to TLS 1.3", func() {
    47  			orig := &tls.Config{MinVersion: tls.VersionTLS12}
    48  			conf := &QUICConfig{TLSConfig: orig}
    49  			SetupConfigForServer(conf, false, nil, nil)
    50  			Expect(conf.TLSConfig.MinVersion).To(BeEquivalentTo(tls.VersionTLS13))
    51  			// check that the original config wasn't modified
    52  			Expect(orig.MinVersion).To(BeEquivalentTo(tls.VersionTLS12))
    53  		})
    54  	})
    55  })