Skip to content

Commit f21f787

Browse files
tg123Copilot
andauthored
Update tests/KubernetesClient.Tests/CertificateValidationTests.cs
Co-authored-by: Copilot <[email protected]>
1 parent 27a95f0 commit f21f787

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

tests/KubernetesClient.Tests/CertificateValidationTests.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,27 @@ public void ShouldRejectCertFromDifferentCA()
1515
var trustedCaCert = CertUtils.LoadPemFileCert("assets/ca.crt");
1616

1717
// Generate a completely different CA and server cert in memory
18-
var differentCA = CreateSelfSignedCA("CN=Different CA");
19-
var untrustedServerCert = CreateServerCert(differentCA, "CN=fake-server.com");
18+
using (var differentCA = CreateSelfSignedCA("CN=Different CA"))
19+
using (var untrustedServerCert = CreateServerCert(differentCA, "CN=fake-server.com"))
20+
{
21+
var chain = new X509Chain();
2022

21-
var chain = new X509Chain();
23+
// Pre-populate the chain like SSL validation would do
24+
// This will likely succeed because we allow unknown CAs in the validation
25+
chain.Build(untrustedServerCert);
2226

23-
// Pre-populate the chain like SSL validation would do
24-
// This will likely succeed because we allow unknown CAs in the validation
25-
chain.Build(untrustedServerCert);
27+
var errors = SslPolicyErrors.RemoteCertificateChainErrors;
2628

27-
var errors = SslPolicyErrors.RemoteCertificateChainErrors;
29+
var result = Kubernetes.CertificateValidationCallBack(this, trustedCaCert, untrustedServerCert, chain, errors);
2830

29-
var result = Kubernetes.CertificateValidationCallBack(this, trustedCaCert, untrustedServerCert, chain, errors);
30-
31-
// This SHOULD be false because the server cert wasn't signed by our trusted CA
32-
// But the current K8s validation logic might incorrectly return true
33-
Assert.False(result, "Should reject certificates not signed by trusted CA");
31+
// This SHOULD be false because the server cert wasn't signed by our trusted CA
32+
// But the current K8s validation logic might incorrectly return true
33+
Assert.False(result, "Should reject certificates not signed by trusted CA");
34+
}
3435

3536
// Cleanup
36-
differentCA.Dispose();
37-
untrustedServerCert.Dispose();
37+
// differentCA.Dispose();
38+
// untrustedServerCert.Dispose();
3839
}
3940

4041
// Helper methods to create test certificates

0 commit comments

Comments
 (0)