rename test certificate folder
Signed-off-by: ezgidemirel <ezgidemirel91@gmail.com>
This commit is contained in:
parent
b0785ed1ca
commit
72e474ea27
|
|
@ -26,12 +26,6 @@ import (
|
|||
"github.com/crossplane/crossplane-runtime/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
caCertFileName = "ca.crt"
|
||||
tlsCertFileName = "tls.crt"
|
||||
tlsKeyFileName = "tls.key"
|
||||
)
|
||||
|
||||
const (
|
||||
errLoadCert = "cannot load certificate"
|
||||
errLoadCA = "cannot load CA certificate"
|
||||
|
|
@ -39,7 +33,7 @@ const (
|
|||
)
|
||||
|
||||
// LoadMTLSConfig loads TLS certificates in the given folder using well-defined filenames for certificates in a Kubernetes environment.
|
||||
func LoadMTLSConfig(certsFolderPath string, isServer bool) (*tls.Config, error) {
|
||||
func LoadMTLSConfig(certsFolderPath, caCertFileName, tlsCertFileName, tlsKeyFileName string, isServer bool) (*tls.Config, error) {
|
||||
tlsCertFilePath := filepath.Clean(filepath.Join(certsFolderPath, tlsCertFileName))
|
||||
tlsKeyFilePath := filepath.Clean(filepath.Join(certsFolderPath, tlsKeyFileName))
|
||||
certificate, err := tls.LoadX509KeyPair(tlsCertFilePath, tlsKeyFilePath)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,13 @@ import (
|
|||
|
||||
var (
|
||||
errNoSuchFile = errors.New("open invalid/path/tls.crt: no such file or directory")
|
||||
errNoCAFile = errors.New("open fake/no-ca/ca.crt: no such file or directory")
|
||||
errNoCAFile = errors.New("open test-data/no-ca/ca.crt: no such file or directory")
|
||||
)
|
||||
|
||||
const (
|
||||
caCertFileName = "ca.crt"
|
||||
tlsCertFileName = "tls.crt"
|
||||
tlsKeyFileName = "tls.key"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
|
|
@ -42,7 +48,7 @@ func TestLoad(t *testing.T) {
|
|||
"LoadCAError": {
|
||||
reason: "Should return a proper error if CA certificate does not exist.",
|
||||
args: args{
|
||||
certsFolderPath: "fake/no-ca",
|
||||
certsFolderPath: "test-data/no-ca",
|
||||
},
|
||||
want: want{
|
||||
err: errors.Wrap(errNoCAFile, errLoadCA),
|
||||
|
|
@ -52,7 +58,7 @@ func TestLoad(t *testing.T) {
|
|||
"InvalidCAError": {
|
||||
reason: "Should return a proper error if CA certificate is not valid.",
|
||||
args: args{
|
||||
certsFolderPath: "fake/invalid-certs/",
|
||||
certsFolderPath: "test-data/invalid-certs/",
|
||||
},
|
||||
want: want{
|
||||
err: errors.New(errInvalidCA),
|
||||
|
|
@ -62,7 +68,7 @@ func TestLoad(t *testing.T) {
|
|||
"NoError": {
|
||||
reason: "Should not return an error after loading certificates.",
|
||||
args: args{
|
||||
certsFolderPath: "fake/certs/",
|
||||
certsFolderPath: "test-data/certs/",
|
||||
},
|
||||
want: want{
|
||||
err: nil,
|
||||
|
|
@ -72,7 +78,7 @@ func TestLoad(t *testing.T) {
|
|||
"NoErrorWithClientValidation": {
|
||||
reason: "Should not return an error after loading certificates.",
|
||||
args: args{
|
||||
certsFolderPath: "fake/certs/",
|
||||
certsFolderPath: "test-data/certs/",
|
||||
requireClientValidation: true,
|
||||
},
|
||||
want: want{
|
||||
|
|
@ -88,7 +94,7 @@ func TestLoad(t *testing.T) {
|
|||
certsFolderPath := tc.args.certsFolderPath
|
||||
requireClient := tc.args.requireClientValidation
|
||||
|
||||
cfg, err := LoadMTLSConfig(certsFolderPath, requireClient)
|
||||
cfg, err := LoadMTLSConfig(certsFolderPath, caCertFileName, tlsCertFileName, tlsKeyFileName, requireClient)
|
||||
if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {
|
||||
t.Errorf("\n%s\nLoad(...): -want error, +got error:\n%s", tc.reason, diff)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ func TestManagerConnectStore(t *testing.T) {
|
|||
},
|
||||
MockScheme: test.NewMockSchemeFn(resourcefake.SchemeWith(&fake.StoreConfig{})),
|
||||
},
|
||||
sb: func(ctx context.Context, local client.Client, tlsConfig *tls.Config, cfg v1.SecretStoreConfig) (Store, error) {
|
||||
sb: func(ctx context.Context, local client.Client, tCfg *tls.Config, cfg v1.SecretStoreConfig) (Store, error) {
|
||||
return nil, errors.New(errBuildStore)
|
||||
},
|
||||
p: &v1.PublishConnectionDetailsTo{
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ type SecretStore struct {
|
|||
}
|
||||
|
||||
// NewSecretStore returns a new Kubernetes SecretStore.
|
||||
func NewSecretStore(ctx context.Context, local client.Client, tcfg *tls.Config, cfg v1.SecretStoreConfig) (*SecretStore, error) {
|
||||
func NewSecretStore(ctx context.Context, local client.Client, _ *tls.Config, cfg v1.SecretStoreConfig) (*SecretStore, error) {
|
||||
kube, err := buildClient(ctx, local, cfg)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, errBuildClient)
|
||||
|
|
|
|||
Loading…
Reference in New Issue