From 4673ff4940f08b8ef1acedae45ad5ffe509bea1c Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Wed, 17 Jan 2024 13:49:32 -0800 Subject: [PATCH] code review changes --- config/configtls/configtls.go | 7 ++++++- config/configtls/configtls_test.go | 21 +++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/config/configtls/configtls.go b/config/configtls/configtls.go index 9f717d17fd2..991bb9b4dd6 100644 --- a/config/configtls/configtls.go +++ b/config/configtls/configtls.go @@ -6,6 +6,7 @@ package configtls // import "go.opentelemetry.io/collector/config/configtls" import ( "crypto/tls" "crypto/x509" + "errors" "fmt" "os" "path/filepath" @@ -197,6 +198,7 @@ func (c TLSSetting) loadTLSConfig() (*tls.Config, error) { func convertCipherSuites(cipherSuites []string) ([]uint16, error) { var result []uint16 + var errs []error for _, suite := range cipherSuites { found := false for _, supported := range tls.CipherSuites() { @@ -207,9 +209,12 @@ func convertCipherSuites(cipherSuites []string) ([]uint16, error) { } } if !found { - return nil, fmt.Errorf("invalid TLS cipher suite: %q", suite) + errs = append(errs, fmt.Errorf("invalid TLS cipher suite: %q", suite)) } } + if len(errs) != 0 { + return nil, errors.Join(errs...) + } return result, nil } diff --git a/config/configtls/configtls_test.go b/config/configtls/configtls_test.go index a5cb35b3ce3..ca705434810 100644 --- a/config/configtls/configtls_test.go +++ b/config/configtls/configtls_test.go @@ -6,7 +6,6 @@ package configtls import ( "crypto/tls" "crypto/x509" - "errors" "fmt" "io" "os" @@ -633,13 +632,12 @@ func TestCipherSuites(t *testing.T) { tests := []struct { name string tlsSetting TLSSetting - wantErr error + wantErr string result []uint16 }{ { name: "no suites set", tlsSetting: TLSSetting{}, - wantErr: nil, result: nil, }, { @@ -647,23 +645,30 @@ func TestCipherSuites(t *testing.T) { tlsSetting: TLSSetting{ CipherSuites: []string{"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"}, }, - wantErr: nil, - result: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, + result: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, }, { name: "invalid cipher suite set", tlsSetting: TLSSetting{ CipherSuites: []string{"FOO"}, }, - wantErr: errors.New(`invalid TLS cipher suite: "FOO"`), + wantErr: `invalid TLS cipher suite: "FOO"`, + }, + { + name: "multiple invalid cipher suites set", + tlsSetting: TLSSetting{ + CipherSuites: []string{"FOO", "BAR"}, + }, + wantErr: `invalid TLS cipher suite: "FOO" +invalid TLS cipher suite: "BAR"`, }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { config, err := test.tlsSetting.loadTLSConfig() - if test.wantErr != nil { - assert.Equal(t, test.wantErr, err) + if test.wantErr != "" { + assert.EqualError(t, err, test.wantErr) } else { assert.NoError(t, err) assert.Equal(t, test.result, config.CipherSuites)