Fix TLS error if CA certificate is not set (#412)

This commit is contained in:
Hidetake Iwata
2020-11-08 15:56:41 +09:00
committed by GitHub
parent ce7784b8a0
commit 8926e8940a
2 changed files with 13 additions and 0 deletions
+4
View File
@@ -37,6 +37,10 @@ func (l *Loader) Load(config tlsclientconfig.Config) (*tls.Config, error) {
return nil, xerrors.Errorf("could not load the certificate: %w", err)
}
}
if len(rootCAs.Subjects()) == 0 {
// use the host's root CA set
rootCAs = nil
}
return &tls.Config{
RootCAs: rootCAs,
InsecureSkipVerify: config.SkipTLSVerify,
+9
View File
@@ -9,6 +9,15 @@ import (
func TestLoader_Load(t *testing.T) {
var loader Loader
t.Run("Zero", func(t *testing.T) {
cfg, err := loader.Load(tlsclientconfig.Config{})
if err != nil {
t.Errorf("Load error: %s", err)
}
if cfg.RootCAs != nil {
t.Errorf("RootCAs wants nil but was %+v", cfg.RootCAs)
}
})
t.Run("ValidFile", func(t *testing.T) {
cfg, err := loader.Load(tlsclientconfig.Config{
CACertFilename: []string{"testdata/ca1.crt"},