Added new tests to check cluster and tls correctness

This commit is contained in:
Sergio Sisternes
2017-06-27 20:26:15 +02:00
parent c38ee42c37
commit 1571aa435e
4 changed files with 118 additions and 1 deletions

View File

@@ -38,6 +38,21 @@ namespace k8s.Tests
/// </summary> /// </summary>
private static readonly string kubeConfigNoCluster = "assets/kubeconfig.no-cluster.yml"; private static readonly string kubeConfigNoCluster = "assets/kubeconfig.no-cluster.yml";
/// <summary>
/// Sample configuration file with incorrect match in cluster name
/// </summary>
private static readonly string kubeConfigClusterMissmatch = "assets/kubeconfig.cluster-missmatch.yml";
/// <summary>
/// Sample configuration file with incorrect TLS configuration in cluster section
/// </summary>
private static readonly string kubeConfigTlsNoSkipError = "assets/kubeconfig.tls-no-skip-error.yml";
/// <summary>
/// Sample configuration file with incorrect TLS configuration in cluster section
/// </summary>
private static readonly string kubeConfigTlsSkip = "assets/kubeconfig.tls-skip.yml";
/// <summary> /// <summary>
/// The configuration file is not present. An KubeConfigException should be thrown /// The configuration file is not present. An KubeConfigException should be thrown
/// </summary> /// </summary>
@@ -177,6 +192,39 @@ namespace k8s.Tests
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi)); Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi));
} }
/// <summary>
/// Checks that a KubeConfigException is thrown when the cluster defined in clusters and contexts do not match
/// </summary>
[Fact]
public void ClusterNameMissmatch()
{
var fi = new FileInfo(kubeConfigClusterMissmatch);
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi));
}
/// <summary>
/// Checks that a KubeConfigException is thrown when no certificate-authority-data is set and user do not require tls skip
/// </summary>
[Fact]
public void CheckClusterTlsCorrectness()
{
var fi = new FileInfo(kubeConfigTlsNoSkipError);
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi));
}
/// <summary>
/// Checks that a KubeConfigException is thrown when no certificate-authority-data is set and user do not require tls skip
/// </summary>
[Fact]
public void CheckClusterTlsSkipCorrectness()
{
var fi = new FileInfo(kubeConfigTlsSkip);
var cfg = new KubernetesClientConfiguration(fi);
Assert.NotNull(cfg.Host);
Assert.Null(cfg.SslCaCert);
Assert.True(cfg.SkipTlsVerify);
}
// /// <summary> // /// <summary>
// /// Checks if the are pods // /// Checks if the are pods
// /// </summary> // /// </summary>

View File

@@ -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: bad-name-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

View File

@@ -0,0 +1,25 @@
# 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:
server: http://cow.org:8080
name: cow-cluster
- 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:
client-certificate-data: path/to/my/client/cert
client-key-data: path/to/my/client/key

View File

@@ -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:
insecure-skip-tls-verify: true
server: https://horse.org:443
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