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