public async Task SiteCertificateRoundTrip()
        {
            var testCert = SelfSignedCertificate.Make(new DateTime(2020, 5, 24), new DateTime(2020, 5, 26));;

            await Strategy.PersistAsync(CertificateType.Site, testCert);

            var retrievedCert = (LetsEncryptX509Certificate)await Strategy.RetrieveSiteCertificateAsync();

            Assert.AreEqual(testCert.RawData, retrievedCert.RawData);
        }
コード例 #2
0
        public void ValidateCertificateTests(CertificateDates cd, ValidatorSettings vs, bool expected)
        {
            var certificateValidator = new CertificateValidator(
                new LetsEncryptOptions
            {
                TimeUntilExpiryBeforeRenewal    = vs.TimeUntilExpiryBeforeRenewal,
                TimeAfterIssueDateBeforeRenewal = vs.TimeAfterIssueDateBeforeRenewal
            },
                new NullLogger <CertificateValidator>());

            var cert = SelfSignedCertificate.Make(cd.From, cd.To);

            certificateValidator.IsCertificateValid(cert).Should().Be(expected);
        }
        public async Task OnNoValidCertificateAvailable_ShouldRenewCertificate()
        {
            // arrange

            PersistenceService.GetPersistedSiteCertificateAsync().Returns(Task.FromResult(InvalidCert));

            var dtos = new [] { new ChallengeDto {
                                    Domains = new[] { "test.com" }, Token = "ping", Response = "pong"
                                } };
            var placedOrder = new PlacedOrder(dtos, Substitute.For <IOrderContext>(), Array.Empty <IChallengeContext>());

            LetsEncryptClient.PlaceOrder(SeqEq(new[] { "test.com" })).Returns(Task.FromResult(placedOrder));
            PersistenceService.PersistChallengesAsync(dtos).Returns(Task.CompletedTask);
            PersistenceService.DeleteChallengesAsync(dtos).Returns(Task.CompletedTask);

            var newCertBytes = SelfSignedCertificate.Make(DateTime.Now, DateTime.Now.AddDays(90)).RawData;

            LetsEncryptClient.FinalizeOrder(placedOrder).Returns(Task.FromResult(new PfxCertificate(newCertBytes)));

            var newCertificate = new LetsEncryptX509Certificate(newCertBytes) as IPersistableCertificate;

            PersistenceService.PersistSiteCertificateAsync(newCertificate).Returns(Task.CompletedTask);

            // act

            var output = await Sut.RenewCertificateIfNeeded(current : null);

            // assert

            output.Status.Should().Be(Renewed);
            ((LetsEncryptX509Certificate)output.Certificate).RawData.Should().BeEquivalentTo(newCertBytes);

            CertificateValidator.Received(1).IsCertificateValid(null);
            await PersistenceService.Received(1).GetPersistedSiteCertificateAsync();

            CertificateValidator.Received(1).IsCertificateValid(InvalidCert);
            await LetsEncryptClient.Received(1).PlaceOrder(SeqEq(new[] { "test.com" }));

            await PersistenceService.Received(1).PersistChallengesAsync(dtos);

            await PersistenceService.Received(1).DeleteChallengesAsync(dtos);

            await PersistenceService.Received(1).PersistChallengesAsync(dtos);

            await LetsEncryptClient.Received(1).FinalizeOrder(placedOrder);

            await LetsEncryptClientFactory.Received(1).GetClient();
        }