Skip to content

Commit

Permalink
Unify TLS creation
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Jan 21, 2022
1 parent dda1294 commit 62e87fa
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions distro/otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,24 @@ func TestRunJaegerExporter(t *testing.T) {
}
}

func clientTLSConfig(t *testing.T) *tls.Config {
certs := x509.NewCertPool()
require.True(t, certs.AppendCertsFromPEM([]byte(testCA)), "failed to add CA")
return &tls.Config{RootCAs: certs, MinVersion: tls.VersionTLS13}
}

func serverTLSConfig(t *testing.T) *tls.Config {
cert, err := tls.X509KeyPair([]byte(testCert), []byte(testCertKey))
require.NoError(t, err)
return &tls.Config{Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS13}
}

func TestRunJaegerExporterTLS(t *testing.T) {
reqCh, hFunc := reqHander()
srv := httptest.NewUnstartedServer(hFunc)
t.Cleanup(srv.Close)

cert, err := tls.X509KeyPair([]byte(testCert), []byte(testCertKey))
require.NoError(t, err)
srv.TLS = &tls.Config{Certificates: []tls.Certificate{cert}}
srv.TLS = serverTLSConfig(t)
srv.StartTLS()

certs := x509.NewCertPool()
Expand All @@ -255,7 +265,7 @@ func TestRunJaegerExporterTLS(t *testing.T) {
t.Cleanup(distro.Setenv("OTEL_TRACES_EXPORTER", "jaeger-thrift-splunk"))
sdk, err := distro.Run(
distro.WithEndpoint(srv.URL),
distro.WithTLSConfig(&tls.Config{RootCAs: certs}),
distro.WithTLSConfig(clientTLSConfig(t)),
)
require.NoError(t, err)

Expand Down Expand Up @@ -373,11 +383,9 @@ func newTLSCollector(t *testing.T) *collector {
},
}

cert, err := tls.X509KeyPair([]byte(testCert), []byte(testCertKey))
require.NoError(t, err)
creds := credentials.NewServerTLSFromCert(&cert)

creds := credentials.NewTLS(serverTLSConfig(t))
srv := grpc.NewServer(grpc.Creds(creds))

ctpb.RegisterTraceServiceServer(srv, coll.traceService)
go func() { _ = srv.Serve(ln) }()
t.Cleanup(srv.GracefulStop)
Expand Down Expand Up @@ -502,7 +510,7 @@ func TestRunOTLPExporterTLS(t *testing.T) {

sdk, err := distro.Run(
distro.WithEndpoint(coll.endpoint),
distro.WithTLSConfig(&tls.Config{RootCAs: certs}),
distro.WithTLSConfig(clientTLSConfig(t)),
)
require.NoError(t, err)

Expand Down

0 comments on commit 62e87fa

Please sign in to comment.