github.com/tumi8/quic-go@v0.37.4-tum/integrationtests/versionnegotiation/versionnegotiation_suite_test.go (about) 1 package versionnegotiation 2 3 import ( 4 "context" 5 "crypto/tls" 6 "crypto/x509" 7 "flag" 8 "testing" 9 10 "github.com/tumi8/quic-go/integrationtests/tools" 11 "github.com/tumi8/quic-go/logging" 12 13 "github.com/tumi8/quic-go" 14 15 . "github.com/onsi/ginkgo/v2" 16 . "github.com/onsi/gomega" 17 ) 18 19 var ( 20 enableQlog bool 21 tlsConfig *tls.Config 22 tlsClientConfig *tls.Config 23 ) 24 25 func init() { 26 flag.BoolVar(&enableQlog, "qlog", false, "enable qlog") 27 28 ca, caPrivateKey, err := tools.GenerateCA() 29 if err != nil { 30 panic(err) 31 } 32 leafCert, leafPrivateKey, err := tools.GenerateLeafCert(ca, caPrivateKey) 33 if err != nil { 34 panic(err) 35 } 36 tlsConfig = &tls.Config{ 37 Certificates: []tls.Certificate{{ 38 Certificate: [][]byte{leafCert.Raw}, 39 PrivateKey: leafPrivateKey, 40 }}, 41 NextProtos: []string{tools.ALPN}, 42 } 43 44 root := x509.NewCertPool() 45 root.AddCert(ca) 46 tlsClientConfig = &tls.Config{ 47 ServerName: "localhost", 48 RootCAs: root, 49 NextProtos: []string{tools.ALPN}, 50 } 51 } 52 53 func getTLSConfig() *tls.Config { return tlsConfig } 54 func getTLSClientConfig() *tls.Config { return tlsClientConfig } 55 56 func TestQuicVersionNegotiation(t *testing.T) { 57 RegisterFailHandler(Fail) 58 RunSpecs(t, "Version Negotiation Suite") 59 } 60 61 func maybeAddQLOGTracer(c *quic.Config) *quic.Config { 62 if c == nil { 63 c = &quic.Config{} 64 } 65 if !enableQlog { 66 return c 67 } 68 qlogger := tools.NewQlogger(GinkgoWriter) 69 if c.Tracer == nil { 70 c.Tracer = qlogger 71 } else if qlogger != nil { 72 origTracer := c.Tracer 73 c.Tracer = func(ctx context.Context, p logging.Perspective, connID quic.ConnectionID) logging.ConnectionTracer { 74 return logging.NewMultiplexedConnectionTracer( 75 qlogger(ctx, p, connID), 76 origTracer(ctx, p, connID), 77 ) 78 } 79 } 80 return c 81 }