Added user-password test
This commit is contained in:
@@ -13,8 +13,16 @@ namespace k8s.Tests
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly string kubeConfigFileName = "assets/kubeconfig.yml";
|
private static readonly string kubeConfigFileName = "assets/kubeconfig.yml";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invalid test file with no context on purpose
|
||||||
|
/// </summary>
|
||||||
private static readonly string kubeConfigNoContexts = "assets/kubeconfig-no-context.yml";
|
private static readonly string kubeConfigNoContexts = "assets/kubeconfig-no-context.yml";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sample configuration file with user/password authentication
|
||||||
|
/// </summary>
|
||||||
|
private static readonly string kubeConfigUserPassword = "assets/kubeconfig.user-pass.yml";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks Host is loaded from the default configuration file
|
/// Checks Host is loaded from the default configuration file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -100,7 +108,19 @@ namespace k8s.Tests
|
|||||||
{
|
{
|
||||||
var fi = new FileInfo(kubeConfigNoContexts);
|
var fi = new FileInfo(kubeConfigNoContexts);
|
||||||
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi, "context"));
|
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi, "context"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks user/password authentication information is read properly
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void UserPasswordAuthentication()
|
||||||
|
{
|
||||||
|
var fi = new FileInfo(kubeConfigUserPassword);
|
||||||
|
var cfg = new KubernetesClientConfiguration(fi);
|
||||||
|
Assert.Equal("admin", cfg.Username);
|
||||||
|
Assert.Equal("secret", cfg.Password);
|
||||||
|
}
|
||||||
|
|
||||||
// /// <summary>
|
// /// <summary>
|
||||||
// /// Checks if the are pods
|
// /// Checks if the are pods
|
||||||
|
|||||||
22
tests/assets/kubeconfig.user-pass.yml
Normal file
22
tests/assets/kubeconfig.user-pass.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: 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