Exemplo n.º 1
0
        public async Task CheckHealthAsync_ExpiredCertificate_CheckFailed()
        {
            var certificate = new X509Certificate2(TestResources.TestCertificatePath, "testPassword");
            var check       = new X509CertificateCheck(new TestClock(certificate.NotAfter.AddDays(30)), new TestCertificateResolver(certificate));

            var settings = new X509CertificateCheckSettings("x509", false, 0, null, "thumbprint", StoreName.My, StoreLocation.CurrentUser, 1440.0);
            var context  = new HealthCheckContext(settings);

            await check.CheckHealthAsync(context, settings);

            Assert.False(context.HasSucceeded);
        }
Exemplo n.º 2
0
        public async Task CheckHealthAsync_Unhealthy_ThrowsException()
        {
            var certificateResolver = new Mock <ICertificateResolver>();

            certificateResolver
            .Setup(r => r.ResolveCertificate(It.IsAny <StoreName>(), It.IsAny <StoreLocation>(), It.IsAny <string>()))
            .Throws(new CryptographicException());
            var check = new X509CertificateCheck(new TestClock(DateTime.UtcNow), certificateResolver.Object);

            var settings = new X509CertificateCheckSettings("x509", false, 0, null, "thumbprint", StoreName.My, StoreLocation.CurrentUser, 1440.0);
            var context  = new HealthCheckContext(settings);

            await Assert.ThrowsAsync <CryptographicException>(async() => await check.CheckHealthAsync(context, settings));
        }