mirror of https://github.com/helm/helm
parent
e81d56a247
commit
faa0007b58
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package testdata
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"crypto/x509"
|
|
||||||
"embed"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed rootca.crt rootca.key crt.pem key.pem
|
|
||||||
var tlsFiles embed.FS
|
|
||||||
|
|
||||||
func ReadTLSConfig(insecureSkipTLSverify bool) (*tls.Config, error) {
|
|
||||||
config := tls.Config{
|
|
||||||
InsecureSkipVerify: insecureSkipTLSverify,
|
|
||||||
}
|
|
||||||
|
|
||||||
certFile := "crt.pem"
|
|
||||||
keyFile := "key.pem"
|
|
||||||
caFile := "rootca.crt"
|
|
||||||
|
|
||||||
certPEMBlock, err := tlsFiles.ReadFile(certFile)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "unable to read cert file: file=%q", certFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
keyPEMBlock, err := tlsFiles.ReadFile(keyFile)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "unable to read key file: file=%q", keyFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
cert, err := tls.X509KeyPair(certPEMBlock, keyPEMBlock)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
config.Certificates = []tls.Certificate{cert}
|
|
||||||
|
|
||||||
tlsFiles.ReadFile("rootca.crt")
|
|
||||||
|
|
||||||
b, err := tlsFiles.ReadFile(caFile)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "unable to read CA file: caFile=%q", caFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
cp := x509.NewCertPool()
|
|
||||||
if !cp.AppendCertsFromPEM(b) {
|
|
||||||
return nil, errors.Wrapf(err, "failed to append certificates from file: caFile=%q", caFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
config.RootCAs = cp
|
|
||||||
|
|
||||||
return &config, nil
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package testdata
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/x509"
|
|
||||||
"net"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestReadTLSConfig(t *testing.T) {
|
|
||||||
|
|
||||||
insecureSkipVerify := false
|
|
||||||
|
|
||||||
tlsConfig, err := ReadTLSConfig(insecureSkipVerify)
|
|
||||||
|
|
||||||
require.Nil(t, err)
|
|
||||||
assert.Equal(t, insecureSkipVerify, tlsConfig.InsecureSkipVerify)
|
|
||||||
|
|
||||||
require.Len(t, tlsConfig.Certificates, 1)
|
|
||||||
require.Len(t, tlsConfig.Certificates[0].Certificate, 1)
|
|
||||||
|
|
||||||
leaf, err := x509.ParseCertificate(tlsConfig.Certificates[0].Certificate[0])
|
|
||||||
assert.Nil(t, err)
|
|
||||||
|
|
||||||
assert.Equal(t, []string{"helm.sh"}, leaf.DNSNames)
|
|
||||||
assert.Equal(t, []net.IP{{127, 0, 0, 1}}, leaf.IPAddresses)
|
|
||||||
}
|
|
Loading…
Reference in new issue