Added new tests to check cluster and tls correctness
This commit is contained in:
@@ -38,6 +38,21 @@ namespace k8s.Tests
|
||||
/// </summary>
|
||||
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>
|
||||
/// The configuration file is not present. An KubeConfigException should be thrown
|
||||
/// </summary>
|
||||
@@ -177,6 +192,39 @@ namespace k8s.Tests
|
||||
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>
|
||||
// /// Checks if the are pods
|
||||
// /// </summary>
|
||||
|
||||
22
tests/assets/kubeconfig.cluster-missmatch.yml
Normal file
22
tests/assets/kubeconfig.cluster-missmatch.yml
Normal 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
|
||||
25
tests/assets/kubeconfig.tls-no-skip-error.yml
Normal file
25
tests/assets/kubeconfig.tls-no-skip-error.yml
Normal 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
|
||||
22
tests/assets/kubeconfig.tls-skip.yml
Normal file
22
tests/assets/kubeconfig.tls-skip.yml
Normal 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
|
||||
Reference in New Issue
Block a user