public async Task Should_Store_Certificate_On_Cache() { var ca = X509CertificateFactory.LoadCertificate(CertificateProvider.RootCA); var provider = new CachedCertificateProvider(new BouncyCastleCertificateProvider(ca)); var createdCert = await provider.GetCertificateForSubjectAsync("*.proxy.com.ar"); Assert.IsNotNull(createdCert); Assert.AreEqual("CN=*.proxy.com.ar", createdCert.Subject); Assert.AreEqual("CN=*.proxy.com.ar", createdCert.Issuer); Assert.IsTrue(createdCert.HasPrivateKey); VerifyChain(createdCert); createdCert = await provider.GetCertificateForSubjectAsync("*.proxy.com.ar"); Assert.IsNotNull(createdCert); Assert.AreEqual("CN=*.proxy.com.ar", createdCert.Subject); Assert.AreEqual("CN=*.proxy.com.ar", createdCert.Issuer); Assert.IsTrue(createdCert.HasPrivateKey); VerifyChain(createdCert); createdCert = await provider.GetCertificateForSubjectAsync("*.proxy.com.ar"); Assert.IsNotNull(createdCert); Assert.AreEqual("CN=*.proxy.com.ar", createdCert.Subject); Assert.AreEqual("CN=*.proxy.com.ar", createdCert.Issuer); Assert.IsTrue(createdCert.HasPrivateKey); VerifyChain(createdCert); }
public async Task Should_Be_Safe_in_Multithreading() { var ca = X509CertificateFactory.LoadCertificate(CertificateProvider.RootCA); var provider = new CachedCertificateProvider( new StoredCertificateProvider( new BouncyCastleCertificateProvider(ca))); var tasks = new Task[10]; for (var i = 0; i < 10; i++) { tasks[i] = Task.Run(async() => { var createdCert = await provider.GetCertificateForSubjectAsync("*.proxy.com.ar"); Assert.IsNotNull(createdCert); Assert.AreEqual("CN=*.proxy.com.ar", createdCert.Subject); Assert.AreEqual("CN=*.proxy.com.ar", createdCert.Issuer); Assert.IsTrue(createdCert.HasPrivateKey); VerifyChain(createdCert); }); } Task.WaitAll(tasks); }