Пример #1
0
        public async Task TestChallengeRequestHttp01()
        {
            var site = iisManager.GetSiteByDomain(testSiteDomain);

            Assert.AreEqual(site.Name, testSiteName);

            var dummyManagedSite = new ManagedSite
            {
                Id            = Guid.NewGuid().ToString(),
                Name          = testSiteName,
                GroupId       = site.Id.ToString(),
                RequestConfig = new CertRequestConfig
                {
                    PrimaryDomain                    = testSiteDomain,
                    ChallengeType                    = "http-01",
                    PerformAutoConfig                = true,
                    PerformAutomatedCertBinding      = true,
                    PerformChallengeFileCopy         = true,
                    PerformExtensionlessConfigChecks = true,
                    WebsiteRootPath                  = testSitePath
                },
                ItemType = ManagedItemType.SSL_LetsEncrypt_LocalIIS
            };

            var result = await certifyManager.PerformCertificateRequest(dummyManagedSite);

            //ensure cert request was successful
            Assert.IsTrue(result.IsSuccess, "Certificate Request Not Completed");

            //check details of cert, subject alternative name should include domain and expiry must be great than 89 days in the future
            var managedSites = await certifyManager.GetManagedSites();

            var managedSite = managedSites.FirstOrDefault(m => m.Id == dummyManagedSite.Id);

            //emsure we have a new managed site
            Assert.IsNotNull(managedSite);

            //have cert file details
            Assert.IsNotNull(managedSite.CertificatePath);

            var fileExists = System.IO.File.Exists(managedSite.CertificatePath);

            Assert.IsTrue(fileExists);

            //check cert is correct
            var certInfo = CertificateManager.LoadCertificate(managedSite.CertificatePath);

            Assert.IsNotNull(certInfo);

            bool isRecentlyCreated = Math.Abs((DateTime.UtcNow - certInfo.NotBefore).TotalDays) < 2;

            Assert.IsTrue(isRecentlyCreated);

            bool expiresInFuture = (certInfo.NotAfter - DateTime.UtcNow).TotalDays >= 89;

            Assert.IsTrue(expiresInFuture);

            // remove managed site
            await certifyManager.DeleteManagedSite(managedSite.Id);
        }