@@ -53,8 +53,6 @@ import (
5353 "go.opentelemetry.io/otel/sdk/metric/metricdata"
5454 "go.uber.org/zap/zaptest"
5555
56- "github.com/elastic/pkcs8"
57-
5856 "gopkg.in/yaml.v2"
5957
6058 "github.com/elastic/beats/v7/libbeat/otelbeat/beatconverter"
@@ -101,7 +99,7 @@ func TestMTLS(t *testing.T) {
10199 }
102100
103101 // get client certificates paths
104- clientCertificate , clientKey := getClientCerts (t , caCert , "" )
102+ clientCertificate , clientKey := GetClientCerts (t , caCert , "" )
105103
106104 // start test server with given server and root certs
107105 certPool := x509 .NewCertPool ()
@@ -117,11 +115,11 @@ func TestMTLS(t *testing.T) {
117115
118116 inputConfig := `
119117receivers:
120- filebeatreceiver:
118+ filebeatreceiver:
121119 output:
122120 elasticsearch:
123121 hosts: {{ .Host }}
124- ssl:
122+ ssl:
125123 enabled: true
126124 certificate_authorities:
127125 - {{ .CACertificate }}
@@ -175,7 +173,7 @@ func TestKeyPassPhrase(t *testing.T) {
175173 }
176174
177175 // get client certificates paths with key file encrypted in PKCS#8 format
178- clientCertificate , clientKey := getClientCerts (t , caCert , "your-password" )
176+ clientCertificate , clientKey := GetClientCerts (t , caCert , "your-password" )
179177
180178 // start test server with given server and root certs
181179 certPool := x509 .NewCertPool ()
@@ -191,17 +189,17 @@ func TestKeyPassPhrase(t *testing.T) {
191189
192190 inputConfig := `
193191receivers:
194- filebeatreceiver:
192+ filebeatreceiver:
195193 output:
196194 elasticsearch:
197195 hosts: {{ .Host }}
198- ssl:
196+ ssl:
199197 enabled: true
200198 certificate_authorities:
201199 - {{ .CACertificate }}
202200 certificate: {{ .ClientCert }}
203201 key: {{ .ClientKey }}
204- key_passphrase: your-password
202+ key_passphrase: your-password
205203`
206204
207205 var otelConfigBuffer bytes.Buffer
@@ -262,13 +260,13 @@ func TestCATrustedFingerPrint(t *testing.T) {
262260
263261 inputConfig := `
264262receivers:
265- filebeatreceiver:
263+ filebeatreceiver:
266264 output:
267265 elasticsearch:
268266 hosts: {{ .Host }}
269- ssl:
267+ ssl:
270268 enabled: true
271- ca_trusted_fingerprint: {{ .CATrustedFingerPrint }}
269+ ca_trusted_fingerprint: {{ .CATrustedFingerPrint }}
272270`
273271
274272 var otelConfigBuffer bytes.Buffer
@@ -440,11 +438,11 @@ func TestVerificationMode(t *testing.T) {
440438
441439 inputConfig := `
442440receivers:
443- filebeatreceiver:
441+ filebeatreceiver:
444442 output:
445443 elasticsearch:
446444 hosts: {{ .Host }}
447- ssl:
445+ ssl:
448446 enabled: true
449447 certificate_authorities:
450448 - {{ .CACertificate }}
@@ -536,7 +534,7 @@ func TestProxyHTTP(t *testing.T) {
536534 proxytest .WithRequestLog ("https" , t .Logf )},
537535 inputConfig : `
538536receivers:
539- filebeatreceiver:
537+ filebeatreceiver:
540538 output:
541539 elasticsearch:
542540 hosts: {{ .Host }}
@@ -569,7 +567,7 @@ receivers:
569567 })},
570568 inputConfig : `
571569receivers:
572- filebeatreceiver:
570+ filebeatreceiver:
573571 output:
574572 elasticsearch:
575573 hosts: {{ .Host }}
@@ -587,7 +585,7 @@ receivers:
587585 proxytest .WithRequestLog ("https" , t .Logf )},
588586 inputConfig : `
589587receivers:
590- filebeatreceiver:
588+ filebeatreceiver:
591589 output:
592590 elasticsearch:
593591 hosts: {{ .Host }}
@@ -762,54 +760,6 @@ func mustSendLogs(t *testing.T, exporter exporter.Logs, logs plog.Logs) error {
762760 return err
763761}
764762
765- // getClientCerts creates client certificates, writes them to a file and return the path of certificate and key
766- // if passphrase is passed, it is used to encrypt the key file
767- func getClientCerts (t * testing.T , caCert tls.Certificate , passphrase string ) (certificate string , key string ) {
768- // create client certificates
769- clientCerts , err := tlscommontest .GenSignedCert (caCert , x509 .KeyUsageCertSign , false , "client" , []string {"localhost" }, []net.IP {net .IPv4 (127 , 0 , 0 , 1 )}, false )
770- if err != nil {
771- t .Fatalf ("could not generate certificates: %s" , err )
772- }
773-
774- tempDir := t .TempDir ()
775- clientCertPath := filepath .Join (tempDir , "client-cert.pem" )
776- clientKeyPath := filepath .Join (tempDir , "client-key.pem" )
777-
778- if passphrase != "" {
779- clientKey , err := pkcs8 .MarshalPrivateKey (clientCerts .PrivateKey , []byte (passphrase ), pkcs8 .DefaultOpts )
780- if err != nil {
781- t .Fatalf ("could not marshal private key: %v" , err )
782- }
783-
784- if err = os .WriteFile (clientKeyPath , pem .EncodeToMemory (& pem.Block {
785- Type : "ENCRYPTED PRIVATE KEY" ,
786- Bytes : clientKey ,
787- }), 0400 ); err != nil {
788- t .Fatalf ("could not write client key to file" )
789- }
790- } else {
791- clientKey , err := x509 .MarshalPKCS8PrivateKey (clientCerts .PrivateKey )
792- if err != nil {
793- t .Fatalf ("could not marshal private key: %v" , err )
794- }
795- if err = os .WriteFile (clientKeyPath , pem .EncodeToMemory (& pem.Block {
796- Type : "RSA PRIVATE KEY" ,
797- Bytes : clientKey ,
798- }), 0400 ); err != nil {
799- t .Fatalf ("could not write client key to file" )
800- }
801- }
802-
803- if err = os .WriteFile (clientCertPath , pem .EncodeToMemory (& pem.Block {
804- Type : "CERTIFICATE" ,
805- Bytes : clientCerts .Leaf .Raw ,
806- }), 0400 ); err != nil {
807- t .Fatalf ("could not write client certificate to file" )
808- }
809-
810- return clientCertPath , clientKeyPath
811- }
812-
813763func getTranslatedConf (t * testing.T , input []byte ) * confmap.Conf {
814764 c := beatconverter.Converter {}
815765
0 commit comments