rename test certificate folder

Signed-off-by: ezgidemirel <ezgidemirel91@gmail.com>
This commit is contained in:
ezgidemirel 2023-03-21 17:46:08 +03:00
parent b0785ed1ca
commit 72e474ea27
No known key found for this signature in database
GPG Key ID: 89568F0941364589
12 changed files with 15 additions and 15 deletions

View File

@ -26,12 +26,6 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/errors" "github.com/crossplane/crossplane-runtime/pkg/errors"
) )
const (
caCertFileName = "ca.crt"
tlsCertFileName = "tls.crt"
tlsKeyFileName = "tls.key"
)
const ( const (
errLoadCert = "cannot load certificate" errLoadCert = "cannot load certificate"
errLoadCA = "cannot load CA 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. // 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)) tlsCertFilePath := filepath.Clean(filepath.Join(certsFolderPath, tlsCertFileName))
tlsKeyFilePath := filepath.Clean(filepath.Join(certsFolderPath, tlsKeyFileName)) tlsKeyFilePath := filepath.Clean(filepath.Join(certsFolderPath, tlsKeyFileName))
certificate, err := tls.LoadX509KeyPair(tlsCertFilePath, tlsKeyFilePath) certificate, err := tls.LoadX509KeyPair(tlsCertFilePath, tlsKeyFilePath)

View File

@ -12,7 +12,13 @@ import (
var ( var (
errNoSuchFile = errors.New("open invalid/path/tls.crt: no such file or directory") 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) { func TestLoad(t *testing.T) {
@ -42,7 +48,7 @@ func TestLoad(t *testing.T) {
"LoadCAError": { "LoadCAError": {
reason: "Should return a proper error if CA certificate does not exist.", reason: "Should return a proper error if CA certificate does not exist.",
args: args{ args: args{
certsFolderPath: "fake/no-ca", certsFolderPath: "test-data/no-ca",
}, },
want: want{ want: want{
err: errors.Wrap(errNoCAFile, errLoadCA), err: errors.Wrap(errNoCAFile, errLoadCA),
@ -52,7 +58,7 @@ func TestLoad(t *testing.T) {
"InvalidCAError": { "InvalidCAError": {
reason: "Should return a proper error if CA certificate is not valid.", reason: "Should return a proper error if CA certificate is not valid.",
args: args{ args: args{
certsFolderPath: "fake/invalid-certs/", certsFolderPath: "test-data/invalid-certs/",
}, },
want: want{ want: want{
err: errors.New(errInvalidCA), err: errors.New(errInvalidCA),
@ -62,7 +68,7 @@ func TestLoad(t *testing.T) {
"NoError": { "NoError": {
reason: "Should not return an error after loading certificates.", reason: "Should not return an error after loading certificates.",
args: args{ args: args{
certsFolderPath: "fake/certs/", certsFolderPath: "test-data/certs/",
}, },
want: want{ want: want{
err: nil, err: nil,
@ -72,7 +78,7 @@ func TestLoad(t *testing.T) {
"NoErrorWithClientValidation": { "NoErrorWithClientValidation": {
reason: "Should not return an error after loading certificates.", reason: "Should not return an error after loading certificates.",
args: args{ args: args{
certsFolderPath: "fake/certs/", certsFolderPath: "test-data/certs/",
requireClientValidation: true, requireClientValidation: true,
}, },
want: want{ want: want{
@ -88,7 +94,7 @@ func TestLoad(t *testing.T) {
certsFolderPath := tc.args.certsFolderPath certsFolderPath := tc.args.certsFolderPath
requireClient := tc.args.requireClientValidation 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 != "" { 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) t.Errorf("\n%s\nLoad(...): -want error, +got error:\n%s", tc.reason, diff)
} }

View File

@ -100,7 +100,7 @@ func TestManagerConnectStore(t *testing.T) {
}, },
MockScheme: test.NewMockSchemeFn(resourcefake.SchemeWith(&fake.StoreConfig{})), 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) return nil, errors.New(errBuildStore)
}, },
p: &v1.PublishConnectionDetailsTo{ p: &v1.PublishConnectionDetailsTo{

View File

@ -57,7 +57,7 @@ type SecretStore struct {
} }
// NewSecretStore returns a new Kubernetes SecretStore. // 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) kube, err := buildClient(ctx, local, cfg)
if err != nil { if err != nil {
return nil, errors.Wrap(err, errBuildClient) return nil, errors.Wrap(err, errBuildClient)