mirror of
https://github.com/int128/kubelogin.git
synced 2026-08-28 22:57:19 +00:00
Fix TLS error if CA certificate is not set (#412)
This commit is contained in:
@@ -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,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"},
|
||||
|
||||
Reference in New Issue
Block a user