From 81c256108006a052eea4ec5c824796f7f14e82b8 Mon Sep 17 00:00:00 2001 From: Tullio Sebastiani Date: Fri, 29 Nov 2024 11:11:09 +0100 Subject: [PATCH] utils tests Signed-off-by: Tullio Sebastiani test Signed-off-by: Tullio Sebastiani test fix Signed-off-by: Tullio Sebastiani utils test Signed-off-by: Tullio Sebastiani --- cmd/graph.go | 3 + cmd/run.go | 3 + ...ctory_test.go => provider_factory_test.go} | 0 .../factory/factory_test.go | 28 ++ pkg/scenario_orchestrator/utils/utils.go | 45 +++- pkg/scenario_orchestrator/utils/utils_test.go | 247 ++++++++++++++++++ tests/data/kubeconfig | 32 +++ tests/data/test_ca | 19 ++ tests/data/test_cert | 19 ++ tests/data/test_key | 27 ++ tests/data/wrong_kubeconfig | 33 +++ 11 files changed, 450 insertions(+), 6 deletions(-) rename pkg/provider/factory/{provide_factory_test.go => provider_factory_test.go} (100%) create mode 100644 pkg/scenario_orchestrator/factory/factory_test.go create mode 100644 tests/data/kubeconfig create mode 100644 tests/data/test_ca create mode 100644 tests/data/test_cert create mode 100644 tests/data/test_key create mode 100644 tests/data/wrong_kubeconfig diff --git a/cmd/graph.go b/cmd/graph.go index e4fd9d8..53984cd 100644 --- a/cmd/graph.go +++ b/cmd/graph.go @@ -73,6 +73,9 @@ func NewGraphRunCommand(factory *providerfactory.ProviderFactory, scenarioOrches if err != nil { return err } + if kubeconfigPath == nil { + return fmt.Errorf("kubeconfig not found: %s", kubeconfig) + } volumes[*kubeconfigPath] = config.KubeconfigPath if metricsProfile != "" { diff --git a/cmd/run.go b/cmd/run.go index 17ceea3..839894c 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -144,6 +144,9 @@ func NewRunCommand(factory *factory.ProviderFactory, scenarioOrchestrator *scena if err != nil { return err } + if kubeconfigPath == nil { + return fmt.Errorf("kubeconfig not found: %s", *foundKubeconfig) + } volumes[*kubeconfigPath] = config.KubeconfigPath if metricsProfile != nil { volumes[*metricsProfile] = config.MetricsProfilePath diff --git a/pkg/provider/factory/provide_factory_test.go b/pkg/provider/factory/provider_factory_test.go similarity index 100% rename from pkg/provider/factory/provide_factory_test.go rename to pkg/provider/factory/provider_factory_test.go diff --git a/pkg/scenario_orchestrator/factory/factory_test.go b/pkg/scenario_orchestrator/factory/factory_test.go new file mode 100644 index 0000000..07b89f0 --- /dev/null +++ b/pkg/scenario_orchestrator/factory/factory_test.go @@ -0,0 +1,28 @@ +package factory + +import ( + "github.com/krkn-chaos/krknctl/internal/config" + "github.com/krkn-chaos/krknctl/pkg/scenario_orchestrator/docker" + "github.com/krkn-chaos/krknctl/pkg/scenario_orchestrator/models" + "github.com/krkn-chaos/krknctl/pkg/scenario_orchestrator/podman" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestScenarioOrchestratorFactory_NewInstance(t *testing.T) { + typeProviderPodman := &podman.ScenarioOrchestrator{} + typeProviderDocker := &docker.ScenarioOrchestrator{} + conf, err := config.LoadConfig() + assert.Nil(t, err) + assert.NotNil(t, conf) + factory := NewScenarioOrchestratorFactory(conf) + assert.NotNil(t, factory) + scenarioDocker := factory.NewInstance(models.Docker) + assert.NotNil(t, scenarioDocker) + assert.IsType(t, scenarioDocker, typeProviderDocker) + + scenarioPodman := factory.NewInstance(models.Podman) + assert.NotNil(t, scenarioPodman) + assert.IsType(t, scenarioPodman, typeProviderPodman) + +} diff --git a/pkg/scenario_orchestrator/utils/utils.go b/pkg/scenario_orchestrator/utils/utils.go index db74800..2637b54 100644 --- a/pkg/scenario_orchestrator/utils/utils.go +++ b/pkg/scenario_orchestrator/utils/utils.go @@ -10,6 +10,7 @@ import ( "github.com/krkn-chaos/krknctl/internal/config" orchestatormodels "github.com/krkn-chaos/krknctl/pkg/scenario_orchestrator/models" "github.com/krkn-chaos/krknctl/pkg/text" + "io/fs" "k8s.io/client-go/tools/clientcmd" "os" "path/filepath" @@ -26,25 +27,36 @@ type SigTermChannel struct { func PrepareKubeconfig(kubeconfigPath *string, config config.Config) (*string, error) { var configPath string - + var configFolder string if kubeconfigPath == nil || *kubeconfigPath == "" { configPath = clientcmd.NewDefaultClientConfigLoadingRules().GetDefaultFilename() } else { - path, err := ExpandHomeFolder(*kubeconfigPath) + path, err := ExpandFolder(*kubeconfigPath, nil) if err != nil { return nil, err } configPath = *path } + configFolder = filepath.Dir(configPath) + kubeconfig, err := clientcmd.LoadFromFile(configPath) if err != nil { + var fserr *fs.PathError + if errors.As(err, &fserr) { + return nil, nil + } return nil, fmt.Errorf("failed to load kubeconfig: %v", err) } for clusterName, cluster := range kubeconfig.Clusters { if cluster.CertificateAuthorityData == nil && cluster.CertificateAuthority != "" { - certData, err := os.ReadFile(cluster.CertificateAuthority) + path, err := ExpandFolder(cluster.CertificateAuthority, &configFolder) + if err != nil { + return nil, err + } + + certData, err := os.ReadFile(*path) if err != nil { return nil, fmt.Errorf("failed to load cluster certificate '%s': %v", clusterName, err) } @@ -55,7 +67,11 @@ func PrepareKubeconfig(kubeconfigPath *string, config config.Config) (*string, e for authName, auth := range kubeconfig.AuthInfos { if auth.ClientCertificateData == nil && auth.ClientCertificate != "" { - certData, err := os.ReadFile(auth.ClientCertificate) + path, err := ExpandFolder(auth.ClientCertificate, &configFolder) + if err != nil { + return nil, err + } + certData, err := os.ReadFile(*path) if err != nil { return nil, fmt.Errorf("failed to load user certificate '%s': %v", authName, err) } @@ -64,7 +80,11 @@ func PrepareKubeconfig(kubeconfigPath *string, config config.Config) (*string, e } if auth.ClientKeyData == nil && auth.ClientKey != "" { - keyData, err := os.ReadFile(auth.ClientKey) + path, err := ExpandFolder(auth.ClientKey, &configFolder) + if err != nil { + return nil, err + } + keyData, err := os.ReadFile(*path) if err != nil { return nil, fmt.Errorf("failed to load user key '%s': %v", authName, err) } @@ -141,7 +161,7 @@ func CleanLogFiles(config config.Config) (*int, error) { return &deletedFiles, nil } -func ExpandHomeFolder(folder string) (*string, error) { +func ExpandFolder(folder string, basePath *string) (*string, error) { if strings.HasPrefix(folder, "~/") { home, err := os.UserHomeDir() if err != nil { @@ -151,6 +171,19 @@ func ExpandHomeFolder(folder string) (*string, error) { expandedPath := filepath.Join(home, replacedHome) return &expandedPath, nil } + if filepath.IsAbs(folder) == false { + if basePath != nil { + path := filepath.Join(*basePath, folder) + return &path, nil + } else { + path, err := filepath.Abs(folder) + if err != nil { + return nil, err + } + return &path, nil + } + + } return &folder, nil } diff --git a/pkg/scenario_orchestrator/utils/utils_test.go b/pkg/scenario_orchestrator/utils/utils_test.go index d2c22de..6d1ffe5 100644 --- a/pkg/scenario_orchestrator/utils/utils_test.go +++ b/pkg/scenario_orchestrator/utils/utils_test.go @@ -1,9 +1,256 @@ package utils import ( + "fmt" + krknctlconfig "github.com/krkn-chaos/krknctl/internal/config" + "github.com/krkn-chaos/krknctl/pkg/scenario_orchestrator/models" + "github.com/stretchr/testify/assert" + "io/fs" + "k8s.io/client-go/tools/clientcmd" + "os" + "path/filepath" + "regexp" + "runtime" "testing" ) func TestFlatten(t *testing.T) { + conf, err := krknctlconfig.LoadConfig() + assert.Nil(t, err) + + not_existing_kubeconfig := "tests/data/not_existing" + flat_kubeconfig_path, err := PrepareKubeconfig(¬_existing_kubeconfig, conf) + assert.Nil(t, err) + assert.Nil(t, flat_kubeconfig_path) + + wrong_kubeconfig := "tests/data/not_existing" + wrong_kubeconfig_path, err := PrepareKubeconfig(&wrong_kubeconfig, conf) + assert.Nil(t, err) + assert.Nil(t, wrong_kubeconfig_path) + + kubeconfig_path := "../../../tests/data/kubeconfig" + flat_kubeconfig_path, err = PrepareKubeconfig(&kubeconfig_path, conf) + assert.Nil(t, err) + assert.NotNil(t, flat_kubeconfig_path) + + kubeconfig, err := clientcmd.LoadFromFile(*flat_kubeconfig_path) + assert.Nil(t, err) + assert.NotNil(t, kubeconfig) + + assert.NotEmpty(t, kubeconfig.Clusters) + ca, err := os.ReadFile("../../../tests/data/test_ca") + cert, err := os.ReadFile("../../../tests/data/test_cert") + key, err := os.ReadFile("../../../tests/data/test_key") + assert.Nil(t, err) + + for _, v := range kubeconfig.Clusters { + assert.NotEmpty(t, v.CertificateAuthorityData) + assert.Equal(t, ca, v.CertificateAuthorityData) + } + + for _, auth := range kubeconfig.AuthInfos { + assert.NotEmpty(t, auth.ClientCertificateData) + assert.Equal(t, cert, auth.ClientCertificateData) + assert.NotEmpty(t, auth.ClientKeyData) + assert.Equal(t, key, auth.ClientKeyData) + } + +} + +func TestExpandFolder(t *testing.T) { + + currentfolder, err := os.Getwd() + parentfolder := filepath.Dir(currentfolder) + grandParentFolder := filepath.Dir(parentfolder) + baseFolder := "/usr/local/bin" + homeFolder, err := os.UserHomeDir() + assert.Nil(t, err) + expectedHomeFolder := filepath.Join(homeFolder, "tests", "data") + expectedParentFolder := filepath.Join(parentfolder, "krknctl") + expectedGrandParentFolder := filepath.Join(grandParentFolder, "krknctl") + expectedCurrentFolder := filepath.Join(currentfolder, "krknctl") + expectedParentFolderWithBase := "/usr/local/krknctl" + + resultParentFolder, err := ExpandFolder("../krknctl", nil) + assert.Nil(t, err) + assert.Equal(t, expectedParentFolder, *resultParentFolder) + + resultGrandParentFolder, err := ExpandFolder("../../krknctl", nil) + assert.Nil(t, err) + assert.Equal(t, expectedGrandParentFolder, *resultGrandParentFolder) + + resultCurrentFolder, err := ExpandFolder("./krknctl", nil) + assert.Nil(t, err) + assert.Equal(t, expectedCurrentFolder, *resultCurrentFolder) + + resultHomeFolder, err := ExpandFolder("~/tests/data", nil) + assert.Nil(t, err) + assert.Equal(t, expectedHomeFolder, *resultHomeFolder) + + resultSameAbsoluteFolder, err := ExpandFolder(currentfolder, nil) + assert.Nil(t, err) + assert.Equal(t, currentfolder, *resultSameAbsoluteFolder) + + resultParentFolderWithBase, err := ExpandFolder("../krknctl", &baseFolder) + assert.Nil(t, err) + assert.Equal(t, expectedParentFolderWithBase, *resultParentFolderWithBase) + +} + +func TestCleanKubeconfigFiles(t *testing.T) { + cwd, err := os.Getwd() + assert.Nil(t, err) + conf, err := krknctlconfig.LoadConfig() + assert.Nil(t, err) + kubeconfig_path := "../../../tests/data/kubeconfig" + flat_kubeconfig_path, err := PrepareKubeconfig(&kubeconfig_path, conf) + assert.Nil(t, err) + assert.NotNil(t, flat_kubeconfig_path) + root := os.DirFS(cwd) + mdFiles, err := fs.Glob(root, "krknctl-kubeconfig-*") + assert.Nil(t, err) + assert.Greater(t, len(mdFiles), 0) + num, err := CleanKubeconfigFiles(conf) + assert.Nil(t, err) + assert.Equal(t, *num, len(mdFiles)) + + mdFiles, err = fs.Glob(root, "krkctl-kubeconifig-*") + assert.Nil(t, err) + assert.Equal(t, len(mdFiles), 0) +} + +func TestCleanLogFiles(t *testing.T) { + cwd, err := os.Getwd() + assert.Nil(t, err) + conf, err := krknctlconfig.LoadConfig() + assert.Nil(t, err) + nodename1 := "dummy-random" + containername1 := GenerateContainerName(conf, "dummy-scenario", &nodename1) + containername2 := GenerateContainerName(conf, "dummy-scenario", nil) + filename1 := fmt.Sprintf("%s.log", containername1) + filename2 := fmt.Sprintf("%s.log", containername2) + // this one will be kept + filename3 := "random-log.log" + + file, err := os.Create(filename1) + file.Close() + file, err = os.Create(filename2) + file.Close() + file, err = os.Create(filename3) + file.Close() + + root := os.DirFS(cwd) + mdFiles, err := fs.Glob(root, "*.log") + assert.GreaterOrEqual(t, len(mdFiles), 3) + num, err := CleanLogFiles(conf) + assert.Nil(t, err) + assert.Equal(t, *num, len(mdFiles)-1) + +} + +func TestGetSocketByContainerEnvironment(t *testing.T) { + conf, err := krknctlconfig.LoadConfig() + uid := 1337 + root := 0 + assert.Nil(t, err) + if runtime.GOOS == "linux" { + + // not testing nil because might be root or user depending on the test environment + socket, err := GetSocketByContainerEnvironment(models.Podman, conf, &uid) + assert.Nil(t, err) + assert.Equal(t, *socket, fmt.Sprintf(conf.PodmanLinuxSocketTemplate, uid)) + socket, err = GetSocketByContainerEnvironment(models.Podman, conf, &root) + assert.Nil(t, err) + assert.Equal(t, *socket, conf.PodmanSocketRoot) + + socket, err = GetSocketByContainerEnvironment(models.Docker, conf, nil) + assert.Nil(t, err) + assert.Equal(t, *socket, conf.DockerSocketRoot) + socket, err = GetSocketByContainerEnvironment(models.Docker, conf, &uid) + assert.Nil(t, err) + assert.Equal(t, *socket, conf.DockerSocketRoot) + socket, err = GetSocketByContainerEnvironment(models.Docker, conf, &root) + assert.Nil(t, err) + assert.Equal(t, *socket, conf.DockerSocketRoot) + + socket, err = GetSocketByContainerEnvironment(models.Both, conf, &root) + assert.NotNil(t, err) + + } else if runtime.GOOS == "darwin" { + home, err := os.UserHomeDir() + assert.Nil(t, err) + + socket, err := GetSocketByContainerEnvironment(models.Podman, conf, &uid) + assert.Nil(t, err) + assert.Equal(t, *socket, fmt.Sprintf(conf.PodmanDarwinSocketTemplate, home)) + + socket, err = GetSocketByContainerEnvironment(models.Podman, conf, &root) + assert.Nil(t, err) + assert.Equal(t, *socket, fmt.Sprintf(conf.PodmanDarwinSocketTemplate, home)) + + socket, err = GetSocketByContainerEnvironment(models.Docker, conf, &uid) + assert.Nil(t, err) + assert.Equal(t, *socket, conf.DockerSocketRoot) + + socket, err = GetSocketByContainerEnvironment(models.Docker, conf, &root) + assert.Nil(t, err) + assert.Equal(t, *socket, conf.DockerSocketRoot) + + socket, err = GetSocketByContainerEnvironment(models.Both, conf, &root) + assert.NotNil(t, err) + + } else { + assert.False(t, true, "😱") + } +} + +func TestDetectContainerRuntime(t *testing.T) { + // **** WARNING + // Works only on Github Action where both the platforms are installed + // or on systems where both the platform are installed + conf, err := krknctlconfig.LoadConfig() + assert.Nil(t, err) + + cont, err := DetectContainerRuntime(conf) + assert.Nil(t, err) + assert.Equal(t, *cont, models.Both) +} + +func TestGenerateContainerName(t *testing.T) { + conf, err := krknctlconfig.LoadConfig() + assert.Nil(t, err) + nodename := "dummy-random" + scenarioname := "dummy-scenario" + renode, err := regexp.Compile(fmt.Sprintf("%s-%s-[0-9]+", conf.ContainerPrefix, nodename)) + assert.Nil(t, err) + rescenario, err := regexp.Compile(fmt.Sprintf("%s-%s-[0-9]+", conf.ContainerPrefix, scenarioname)) + assert.Nil(t, err) + + containerscenario := GenerateContainerName(conf, scenarioname, nil) + assert.True(t, rescenario.MatchString(containerscenario)) + + containernode := GenerateContainerName(conf, scenarioname, &nodename) + assert.True(t, renode.MatchString(containernode)) + +} + +func TestEnvironmentFromString(t *testing.T) { + + defer func() { + if r := recover(); r == nil { + assert.Fail(t, "unknown string did not panic") + } + }() + + podman := EnvironmentFromString("podman") + assert.Equal(t, podman, models.Podman) + + docker := EnvironmentFromString("docker") + assert.Equal(t, docker, models.Docker) + + both := EnvironmentFromString("both") + assert.Equal(t, both, models.Both) + + EnvironmentFromString("unknown") } diff --git a/tests/data/kubeconfig b/tests/data/kubeconfig new file mode 100644 index 0000000..26ce946 --- /dev/null +++ b/tests/data/kubeconfig @@ -0,0 +1,32 @@ +apiVersion: v1 +clusters: +- cluster: + certificate-authority: ./test_ca + extensions: + - extension: + last-update: Thu, 28 Nov 2024 11:50:15 CET + provider: minikube.sigs.k8s.io + version: v1.34.0 + name: cluster_info + server: https://127.0.0.1:53279 + name: minikube +contexts: +- context: + cluster: minikube + extensions: + - extension: + last-update: Thu, 28 Nov 2024 11:50:15 CET + provider: minikube.sigs.k8s.io + version: v1.34.0 + name: context_info + namespace: default + user: minikube + name: minikube +current-context: minikube +kind: Config +preferences: {} +users: +- name: minikube + user: + client-certificate: ./test_cert + client-key: ./test_key \ No newline at end of file diff --git a/tests/data/test_ca b/tests/data/test_ca new file mode 100644 index 0000000..580fa76 --- /dev/null +++ b/tests/data/test_ca @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDBjCCAe6gAwIBAgIBATANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDEwptaW5p +a3ViZUNBMB4XDTI0MTAyMTA4MTIzNloXDTM0MTAyMDA4MTIzNlowFTETMBEGA1UE +AxMKbWluaWt1YmVDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANG4 +wLzUuP8RrpWwl8hJVfyTE2HDg0/bn5lSIeDQ2khAcdPrYdF5vpUJzr28qxwAH1rP +ipxzW8WaUJ9psUV82WU6Ij104ipwojiC28qGEPEcbOBfqYKJ1vnUT0BHXXvrPZJ3 +PDrcncnsqAOcD4F1HnYIVz7g0Drh49NUtdmMkYPhXM4uDPtJBacMGlXlqVU07AE/ +5Dp1n6zdliCgooXOmEb8u97ZRcVppqUa9/E1KdycoafB6yVLxe5hmCU2Yfy0QF1L +xu39UpJZ7VWz+aUAdQ0q7IA5SXmuWzjFKc8ovUzzrkJ8hG+0+/2dnmXuQNdX9HE7 +J1qdFMncRmp1UtVN/i0CAwEAAaNhMF8wDgYDVR0PAQH/BAQDAgKkMB0GA1UdJQQW +MBQGCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQW +BBRlLh2lkN4vyZ2zcYqjG45Ig2A3WDANBgkqhkiG9w0BAQsFAAOCAQEAD66Q2xY0 +oWAw35lM1C+XEWBD9+ujengEYC9nlQRrqGOzupUoHCsAthwH86WmynB3y8QjqC8y +1uwtWUuY6WAK0NGFuXdgPKaijrPhWwOy8Bz7GmDMNXxegEApZP4gRJ9LsUwE1XHf +BSAdzeKag4XmuvUeMiwVV4TEkyQQ2TqGjZD2uZqTiuBGF/+C4+6+oea86pNwYbr0 +amfaB97io7028YkBJNJhm0rToKqU3/hk/He0WtKs2YHDA6TYn8BFqYpcET8iJWSf +M959M3EjOIRTaPCdkMFVgmSqWkRaZWSuZTNpMJdyRBPk/R3qhyCaIGYFxd/vv0mq +6cBGVBSkJazsqw== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/tests/data/test_cert b/tests/data/test_cert new file mode 100644 index 0000000..2734c04 --- /dev/null +++ b/tests/data/test_cert @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDITCCAgmgAwIBAgIBAjANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDEwptaW5p +a3ViZUNBMB4XDTI0MTAyODA5MDMxNloXDTI3MTAyOTA5MDMxNlowMTEXMBUGA1UE +ChMOc3lzdGVtOm1hc3RlcnMxFjAUBgNVBAMTDW1pbmlrdWJlLXVzZXIwggEiMA0G +CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDRur0yLzvOiQQDhub8Ij2mliAasfcp +jt6a9J2dX9OKJ6DMNIScO8bK5LTpYFVtOrZVz48Y1M8u1pPwMKBGVDm1hdW7lRLF +w4KahO5BpOEvsemFJnDOmOQ6WP5jpNtFD8XLSFiikG/BLPWm+lj/HmP54z65p6vD +5TxNJNVIx5dbv+6K94viVh+Y6b/ceCeL1jfrh6g75G3Q75FPwGjmCVK4nVDLVJgJ +reaeTvwdjrMzD8fOtAwui63Ye5yPwIGa28b7sdY9L2Gf9Ytz/xQEVvdy39VdQ5SM +sSCm/kzs1oL3gs2CbcIcdr4ErjSOeDU+5WuSPwkoW9MAKV4jX3fHWhZfAgMBAAGj +YDBeMA4GA1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUH +AwIwDAYDVR0TAQH/BAIwADAfBgNVHSMEGDAWgBRlLh2lkN4vyZ2zcYqjG45Ig2A3 +WDANBgkqhkiG9w0BAQsFAAOCAQEAghjyC9PPrVGqvKRUlJYPQm2aXOh0eCZcvD7G +VFYn7cvwbesEhgaSZPmbVkawPe6bkY1qjoE1SiwGcn1gGx6CRoLRha6qhJ0CN3kn +bMMaGXUMyTOkoD5IwTkf+hEWZpp0s2ZA1LlARFhwca4xJvLN6E0asvuUWg4NRknc +x6Bn83Po/sDK+8DM940EN3qtVdG6bbblxGbiv0aCS0zXcq6xsuRtyFTJLrKmAWXh +/zFPeFglp2naeF9JEJiLALJsxizHo9yIrVpJD6RU/+ZO+zNWKHN8JMlPHEB9At2e +8PHsXMnx/SwdfvuevYgscYGehYLyqzo/G0kCWindpfqlNUT8bg== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/tests/data/test_key b/tests/data/test_key new file mode 100644 index 0000000..eeba295 --- /dev/null +++ b/tests/data/test_key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEA0bq9Mi87zokEA4bm/CI9ppYgGrH3KY7emvSdnV/TiiegzDSE +nDvGyuS06WBVbTq2Vc+PGNTPLtaT8DCgRlQ5tYXVu5USxcOCmoTuQaThL7HphSZw +zpjkOlj+Y6TbRQ/Fy0hYopBvwSz1pvpY/x5j+eM+uaerw+U8TSTVSMeXW7/uiveL +4lYfmOm/3Hgni9Y364eoO+Rt0O+RT8Bo5glSuJ1Qy1SYCa3mnk78HY6zMw/HzrQM +Lout2Hucj8CBmtvG+7HWPS9hn/WLc/8UBFb3ct/VXUOUjLEgpv5M7NaC94LNgm3C +HHa+BK40jng1PuVrkj8JKFvTACleI193x1oWXwIDAQABAoIBAGvnPavyLT0HtW7z +GyghncJ1frL9WQKipNjofacYREfSN6KYapnPD2oX3RQtIgZ+rIzdquvFoYqhj5+G +BQ/qCX7hCqPmALCK9Ej3l3VilRDq4hBFRMimVNXIL6moib+wa704zZFl6nli3kg4 +iU1In3tTdVQjdfXlnO67wpgdSDxFRsyuDgCzjR6p4DMLO0W6TwA9qXm7+3ONn2Tx +ISSbd5XOwY+D33+sthvuTa67wPaBgC6+MKT/Peuz8boR8JLBwMcrEl4ndljD4154 +0jxHLNKh2NCVNA+H6qIKs5U7yBNKZ4kZbMR7HT8XfAiJaKhj0VU81OhZV39Ml14x +xUWARwECgYEA6pDeSO0cDa0dajwBqGS9wcnxfJl6xH92hLhw24Fc69pPYq1guJlS +MQBJQbK8Pmc87buSi8auOTYNvxfGdNY6+fQxF2SjP39yJIEcL8xz+lU4lgojNe3Z +9JAtVH+VG06PPxrU1bgLxYgLYcdW+dLu7iwaWUDWUrUzWZsi2yLPCR8CgYEA5OTh +Ctguh+uX3VN6/S3TWZwrDyrlxc7znQoahsZSciA0JrVlBaHMWgh25zg7EP/60/+8 +sc7VdiFvgmfOuQyWFX/MO4TKHR1DEDIJzf6hH8D13PRbsQ2RaYMHKu6LHfXMQHcM +VCKjahzn3CWNjRokylEoHibqfwcRuY8bWJr3CsECgYEAj7o2yh6nquWheX/NUD5y +W3T/CGcO56pml8pgNNAefNInBILSGiqwRyAywxPe7qnZlp3xnL4f8SRi5e2Oh/bg +6lmrXvcmZHkWGrIV8F/pzME9TApoKtpUS9uwOu92EOZhNbyeH1qHtAC5YK+BZtDN +4JibiIcHDGTFUymRAQ9iJucCgYAZ2if4u5X10Awk+UrI0aYvVs4eNnAhOVCWig+Y +7UlejniVbqNsUWvtN0uGrfkt4FuKGjZLttqxLvGTPvpAOEWzQ+3jQwo445cxexVU +aM/18CtUu1yn0Kp9ykjC9pJL3fklxsxjrE3crEsbuDoWl79UAnqPfUG6+ydrV9h0 +13vTgQKBgQCJPKjV6/EoD5PdpYEQ/9zJ6jicMey1mZDhuVGbeUkoCvpguQkty7F5 +6dkHQy/Y/3xarJOxn+f1yVcvGcRmhB67CQiGXUmDpk+pRg9x3Cr51hF36W/QmONl +qAnJ0YSlWlsb4zmpJ14V2BShyeglM6tqF9GCdZbfrA1HtYtp3gvkaw== +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/tests/data/wrong_kubeconfig b/tests/data/wrong_kubeconfig new file mode 100644 index 0000000..212285f --- /dev/null +++ b/tests/data/wrong_kubeconfig @@ -0,0 +1,33 @@ + +{apiVersion: v1 +clusters: +- cluster: + certificate-authority: ./test_ca + extensions:} + - extension: + last-update: Thu, 28 Nov 2024 11:50:15 CET + {provider: minikube.sigs.k8s.io + version: v1.34.0} + name: cluster_info + server: https://127.0.0.1:53279 + {name: minikube +contexts: +- context: + cluster: minikube + extensions:}# + - extension:!! + last-update: Thu, 28 Nov 2024 11:50:15 CET + provider: minikube.sigs.k8s.io + version: v1.34.0 + name: context_info + namespace: default + user: minikube + name: minikube +current-context: minikube +kind: Config +preferences: {} +users: +- name: minikube + user: + client-certificate: ./test_cert + client-key: ./test_key \ No newline at end of file