* fix SA1505 and SA1508 * fix SA1116 * fix SA1009 * fix SA1019 * fix SA1127 * fix SA1128 * fix SA1134 * fix indent * allow CA2227 * fix CA1810 * using clean up * fix naming * fix CA1806 * fix await * Revert "fix CA1806" This reverts commit a3b465087fdaf26ec461272373ee9810a90de2cc. * fix dotnet format * allow SA1009
65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using System.Net.Security;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using Xunit;
|
|
|
|
namespace k8s.Tests
|
|
{
|
|
public class CertificateValidationTests
|
|
{
|
|
[Fact]
|
|
public void ValidCert()
|
|
{
|
|
var caCert = CertUtils.LoadPemFileCert("assets/ca.crt");
|
|
var testCert = new X509Certificate2("assets/ca.crt");
|
|
var chain = new X509Chain();
|
|
var errors = SslPolicyErrors.RemoteCertificateChainErrors;
|
|
|
|
var result = Kubernetes.CertificateValidationCallBack(this, caCert, testCert, chain, errors);
|
|
|
|
Assert.True(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void InvalidCert()
|
|
{
|
|
var caCert = CertUtils.LoadPemFileCert("assets/ca.crt");
|
|
var testCert = new X509Certificate2("assets/ca2.crt");
|
|
var chain = new X509Chain();
|
|
var errors = SslPolicyErrors.RemoteCertificateChainErrors;
|
|
|
|
var result = Kubernetes.CertificateValidationCallBack(this, caCert, testCert, chain, errors);
|
|
|
|
Assert.False(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void ValidBundleCert()
|
|
{
|
|
var caCert = CertUtils.LoadPemFileCert("assets/ca-bundle.crt");
|
|
|
|
// Load the intermediate cert
|
|
//
|
|
var testCert = caCert[0];
|
|
var chain = new X509Chain();
|
|
var errors = SslPolicyErrors.RemoteCertificateChainErrors;
|
|
|
|
var result = Kubernetes.CertificateValidationCallBack(this, caCert, testCert, chain, errors);
|
|
|
|
Assert.True(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void InvalidBundleCert()
|
|
{
|
|
var caCert = CertUtils.LoadPemFileCert("assets/ca-bundle.crt");
|
|
var testCert = new X509Certificate2("assets/ca2.crt");
|
|
var chain = new X509Chain();
|
|
var errors = SslPolicyErrors.RemoteCertificateChainErrors;
|
|
|
|
var result = Kubernetes.CertificateValidationCallBack(this, caCert, testCert, chain, errors);
|
|
|
|
Assert.False(result);
|
|
}
|
|
}
|
|
}
|