Skip to content
Prev Previous commit
Next Next commit
Use only CA certificates in test
  • Loading branch information
rzikm committed Feb 23, 2022
commit 5cad62d00ba897bd5de528284bb65af6aa1b47fc
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@ public class SslStreamCertificateTrustTest
[PlatformSpecific(TestPlatforms.Linux | TestPlatforms.OSX)]
public async Task SslStream_SendCertificateTrust_CertificateCollection()
{
using X509Store store = new X509Store("Root", StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2[] certList = store.Certificates.DistinctBy(c => c.Subject).Take(2).ToArray();

SslCertificateTrust trust = SslCertificateTrust.CreateForX509Collection(
new X509Certificate2Collection(certList),
sendTrustInHandshake: true);
(X509Certificate2 certificate, X509Certificate2Collection caCerts) = TestHelper.GenerateCertificates("foo");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can use nameof(SslStream_SendCertificateTrust_CertificateCollection) -> using test names sometimes helps with debugging if tests are running in parallel.


SslCertificateTrust trust = SslCertificateTrust.CreateForX509Collection(caCerts, sendTrustInHandshake: true);
string[] acceptableIssuers = await ConnectAndGatherAcceptableIssuers(trust);

Assert.Equal(2, acceptableIssuers.Length);
Assert.Contains(certList[0].Subject, acceptableIssuers);
Assert.Contains(certList[1].Subject, acceptableIssuers);
Assert.Equal(caCerts.Count, acceptableIssuers.Length);
Assert.Equal(caCerts.Select(c => c.Subject), acceptableIssuers);
}

[Fact]
Expand Down