Skip to content

Commit f7ac5b7

Browse files
committed
Added user-password test
1 parent bead9e3 commit f7ac5b7

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

tests/KubernetesClientConfigurationTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ public class KubernetesClientConfigurationTests
1313
/// </summary>
1414
private static readonly string kubeConfigFileName = "assets/kubeconfig.yml";
1515

16+
/// <summary>
17+
/// Invalid test file with no context on purpose
18+
/// </summary>
1619
private static readonly string kubeConfigNoContexts = "assets/kubeconfig-no-context.yml";
1720

21+
/// <summary>
22+
/// Sample configuration file with user/password authentication
23+
/// </summary>
24+
private static readonly string kubeConfigUserPassword = "assets/kubeconfig.user-pass.yml";
25+
1826
/// <summary>
1927
/// Checks Host is loaded from the default configuration file
2028
/// </summary>
@@ -100,7 +108,19 @@ public void NoContextsExplicit()
100108
{
101109
var fi = new FileInfo(kubeConfigNoContexts);
102110
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi, "context"));
103-
}
111+
}
112+
113+
/// <summary>
114+
/// Checks user/password authentication information is read properly
115+
/// </summary>
116+
[Fact]
117+
public void UserPasswordAuthentication()
118+
{
119+
var fi = new FileInfo(kubeConfigUserPassword);
120+
var cfg = new KubernetesClientConfiguration(fi);
121+
Assert.Equal("admin", cfg.Username);
122+
Assert.Equal("secret", cfg.Password);
123+
}
104124

105125
// /// <summary>
106126
// /// Checks if the are pods

tests/assets/kubeconfig.user-pass.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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:
21+
password: secret
22+
username: admin

0 commit comments

Comments
 (0)