From f7ac5b728bb3cbe2f165cc74ab00738e155c7ab4 Mon Sep 17 00:00:00 2001 From: Sergio Sisternes Date: Tue, 27 Jun 2017 19:19:02 +0200 Subject: [PATCH] Added user-password test --- tests/KubernetesClientConfigurationTests.cs | 22 ++++++++++++++++++++- tests/assets/kubeconfig.user-pass.yml | 22 +++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/assets/kubeconfig.user-pass.yml diff --git a/tests/KubernetesClientConfigurationTests.cs b/tests/KubernetesClientConfigurationTests.cs index f4f9e91..32d59ec 100755 --- a/tests/KubernetesClientConfigurationTests.cs +++ b/tests/KubernetesClientConfigurationTests.cs @@ -13,8 +13,16 @@ namespace k8s.Tests /// private static readonly string kubeConfigFileName = "assets/kubeconfig.yml"; + /// + /// Invalid test file with no context on purpose + /// private static readonly string kubeConfigNoContexts = "assets/kubeconfig-no-context.yml"; + /// + /// Sample configuration file with user/password authentication + /// + private static readonly string kubeConfigUserPassword = "assets/kubeconfig.user-pass.yml"; + /// /// Checks Host is loaded from the default configuration file /// @@ -100,7 +108,19 @@ namespace k8s.Tests { var fi = new FileInfo(kubeConfigNoContexts); Assert.Throws(() => new KubernetesClientConfiguration(fi, "context")); - } + } + + /// + /// Checks user/password authentication information is read properly + /// + [Fact] + public void UserPasswordAuthentication() + { + var fi = new FileInfo(kubeConfigUserPassword); + var cfg = new KubernetesClientConfiguration(fi); + Assert.Equal("admin", cfg.Username); + Assert.Equal("secret", cfg.Password); + } // /// // /// Checks if the are pods diff --git a/tests/assets/kubeconfig.user-pass.yml b/tests/assets/kubeconfig.user-pass.yml new file mode 100644 index 0000000..b426ef5 --- /dev/null +++ b/tests/assets/kubeconfig.user-pass.yml @@ -0,0 +1,22 @@ +# Sample file based on https://kubernetes.io/docs/tasks/access-application-cluster/authenticate-across-clusters-kubeconfig/ +# WARNING: File includes minor fixes +--- +current-context: federal-context +apiVersion: v1 +clusters: +- cluster: + certificate-authority-data: path/to/my/cafile + server: https://horse.org:4443 + name: horse-cluster +contexts: +- context: + cluster: horse-cluster + namespace: chisel-ns + user: green-user + name: federal-context +kind: Config +users: +- name: green-user + user: + password: secret + username: admin \ No newline at end of file