Skip to content

Commit 29a3dac

Browse files
committed
Added tow new tests, checking for no credentials and no server
1 parent bd2fca1 commit 29a3dac

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

tests/KubernetesClientConfigurationTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ public class KubernetesClientConfigurationTests
2323
/// </summary>
2424
private static readonly string kubeConfigUserPassword = "assets/kubeconfig.user-pass.yml";
2525

26+
/// <summary>
27+
/// Sample configuration file with incorrect user credentials structures on purpose
28+
/// </summary>
29+
private static readonly string kubeConfigNoCredentials = "assets/kubeconfig.no-credentials.yml";
30+
31+
/// <summary>
32+
/// Sample configuration file with incorrect cluster/server structure on purpose
33+
/// </summary>
34+
private static readonly string kubeConfigNoServer = "assets/kubeconfig.no-server.yml";
35+
2636
/// <summary>
2737
/// The configuration file is not present. An KubeConfigException should be thrown
2838
/// </summary>
@@ -132,6 +142,26 @@ public void UserPasswordAuthentication()
132142
Assert.Equal("secret", cfg.Password);
133143
}
134144

145+
/// <summary>
146+
/// Checks that a KubeConfigException is thrown when incomplete user credentials
147+
/// </summary>
148+
[Fact]
149+
public void IncompleteUserCredentials()
150+
{
151+
var fi = new FileInfo(kubeConfigNoCredentials);
152+
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi));
153+
}
154+
155+
/// <summary>
156+
/// Checks that a KubeConfigException is thrown when the server property is not set in cluster
157+
/// </summary>
158+
[Fact]
159+
public void ServerNotFound()
160+
{
161+
var fi = new FileInfo(kubeConfigNoServer);
162+
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi));
163+
}
164+
135165
// /// <summary>
136166
// /// Checks if the are pods
137167
// /// </summary>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Sample file based on https://kubernetes.io/docs/tasks/access-application-cluster/authenticate-across-clusters-kubeconfig/
2+
# WARNING: File includes minor fixes
3+
---
4+
current-context: federal-context
5+
apiVersion: v1
6+
clusters:
7+
- cluster:
8+
certificate-authority-data: path/to/my/cafile
9+
server: https://horse.org:4443
10+
name: horse-cluster
11+
contexts:
12+
- context:
13+
cluster: horse-cluster
14+
namespace: chisel-ns
15+
user: green-user
16+
name: federal-context
17+
kind: Config
18+
users:
19+
- name: green-user
20+
user:

tests/assets/kubeconfig.no-server.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Sample file based on https://kubernetes.io/docs/tasks/access-application-cluster/authenticate-across-clusters-kubeconfig/
2+
# WARNING: File includes minor fixes
3+
---
4+
current-context: federal-context
5+
apiVersion: v1
6+
clusters:
7+
- cluster:
8+
certificate-authority-data: path/to/my/cafile
9+
name: horse-cluster
10+
contexts:
11+
- context:
12+
cluster: horse-cluster
13+
namespace: chisel-ns
14+
user: green-user
15+
name: federal-context
16+
kind: Config
17+
users:
18+
- name: green-user
19+
user:
20+
password: secret
21+
username: admin

0 commit comments

Comments
 (0)