public void ItFindsCertTheCertWithLongestLifespan() { var commonName = "x509store-ttl.letsencrypt.test.natemcmaster.com"; using var x509store = new X509Store(StoreName.My, StoreLocation.CurrentUser); x509store.Open(OpenFlags.ReadWrite); var testCert0 = CreateTestCert(commonName, DateTimeOffset.Now.AddMinutes(2)); var testCert1 = CreateTestCert(commonName, DateTimeOffset.Now.AddHours(1)); var testCert2 = CreateTestCert(commonName, DateTimeOffset.Now.AddHours(2)); x509store.Add(testCert2); x509store.Add(testCert1); x509store.Add(testCert0); try { using var certStore = new X509CertStoreFinder(Mock.Of <ILogger <X509CertStoreFinder> >()) { AllowInvalidCerts = true }; var foundCert = certStore.GetCertificate(commonName); Assert.NotNull(foundCert); Assert.Equal(testCert2, foundCert); } finally { x509store.Remove(testCert0); x509store.Remove(testCert1); x509store.Remove(testCert2); } }
public void ItFindsCertByCommonName() { var commonName = "x509store.letsencrypt.test.natemcmaster.com"; using var x509store = new X509Store(StoreName.My, StoreLocation.CurrentUser); x509store.Open(OpenFlags.ReadWrite); var testCert = CreateTestCert(commonName); x509store.Add(testCert); try { var logger = new Mock <ILogger <X509CertStoreFinder> >(); logger.Setup(l => l.IsEnabled(It.IsAny <LogLevel>())).Returns(true); using var certStore = new X509CertStoreFinder(logger.Object) { AllowInvalidCerts = true }; var foundCert = certStore.GetCertificate(commonName); Assert.NotNull(foundCert); Assert.Equal(testCert, foundCert); } finally { x509store.Remove(testCert); } }
public void ItReturnsNullWhenCantFindCert() { var commonName = "notfound.letsencrypt.test.natemcmaster.com"; using var certStore = new X509CertStoreFinder(Mock.Of <ILogger <X509CertStoreFinder> >()) { AllowInvalidCerts = true }; var foundCert = certStore.GetCertificate(commonName); Assert.Null(foundCert); }