Esempio n. 1
0
        public async Task TestRunPreAndPostTasks()
        {
            var managedCertificate = GetMockManagedCertificate("PreDeploymentTask1", testSiteDomain);

            managedCertificate.LastRenewalStatus = RequestState.Success;

            managedCertificate.PreRequestTasks = new ObservableCollection <DeploymentTaskConfig> {
                GetMockTaskConfig("Pre Task 1"),
                GetMockTaskConfig("Pre Task 2")
            };

            managedCertificate.PostRequestTasks = new ObservableCollection <Config.DeploymentTaskConfig> {
                GetMockTaskConfig("Post Task 1"),
                GetMockTaskConfig("Post Task 2")
            };

            try
            {
                var result = await certifyManager.PerformCertificateRequest(_log, managedCertificate, skipRequest : true);

                Assert.AreEqual(result.Actions.Sum(s => s.Substeps.Count), 4);
                //ensure process success
                Assert.IsTrue(result.IsSuccess, "Result OK");
            }
            finally
            {
                await certifyManager.DeleteManagedCertificate(managedCertificate.Id);
            }
        }
        public async Task TestChallengeRequestHttp01()
        {
            var site = await iisManager.GetIISSiteById(_siteId);

            Assert.AreEqual(site.Name, testSiteName);

            var dummyManagedCertificate = new ManagedCertificate
            {
                Id            = Guid.NewGuid().ToString(),
                Name          = testSiteName,
                GroupId       = site.Id.ToString(),
                RequestConfig = new CertRequestConfig
                {
                    PrimaryDomain = testSiteDomain,
                    Challenges    = new ObservableCollection <CertRequestChallengeConfig>(
                        new List <CertRequestChallengeConfig>
                    {
                        new CertRequestChallengeConfig {
                            ChallengeType = "http-01"
                        }
                    }),
                    PerformAutoConfig                = true,
                    PerformAutomatedCertBinding      = true,
                    PerformChallengeFileCopy         = true,
                    PerformExtensionlessConfigChecks = true,
                    WebsiteRootPath = testSitePath
                },
                ItemType = ManagedCertificateType.SSL_LetsEncrypt_LocalIIS
            };

            var result = await certifyManager.PerformCertificateRequest(null, dummyManagedCertificate);

            //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 managedCertificates = await certifyManager.GetManagedCertificates();

            var managedCertificate = managedCertificates.FirstOrDefault(m => m.Id == dummyManagedCertificate.Id);

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

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

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

            Assert.IsTrue(fileExists);

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

            Assert.IsNotNull(certInfo);

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

            Assert.IsTrue(isRecentlyCreated);

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

            Assert.IsTrue(expiresInFuture);

            // remove managed site
            await certifyManager.DeleteManagedCertificate(managedCertificate.Id);
        }
        public async Task TestPreviewWildcard()
        {
            var testStr             = "abc7363";
            var hostname            = $"test-{testStr}.test." + PrimaryTestDomain;
            var wildcardDomain      = "*.test." + PrimaryTestDomain;
            var testPreviewSiteName = "TestPreview_" + testStr;

            if (await iisManager.SiteExists(testPreviewSiteName))
            {
                await iisManager.DeleteSite(testPreviewSiteName);
            }

            var site = await iisManager.CreateSite(testPreviewSiteName, hostname, PrimaryIISRoot, "DefaultAppPool", port : testSiteHttpPort);

            ManagedCertificate managedCertificate = null;
            X509Certificate2   certInfo           = null;

            try
            {
                var dummyManagedCertificate = new ManagedCertificate
                {
                    Id            = Guid.NewGuid().ToString(),
                    Name          = testPreviewSiteName,
                    GroupId       = site.Id.ToString(),
                    RequestConfig = new CertRequestConfig
                    {
                        PrimaryDomain                    = wildcardDomain,
                        PerformAutoConfig                = true,
                        PerformAutomatedCertBinding      = true,
                        PerformChallengeFileCopy         = true,
                        PerformExtensionlessConfigChecks = true,
                        Challenges = new ObservableCollection <CertRequestChallengeConfig>
                        {
                            new CertRequestChallengeConfig {
                                ChallengeType          = SupportedChallengeTypes.CHALLENGE_TYPE_DNS,
                                ChallengeProvider      = "DNS01.API.Route53",
                                ChallengeCredentialKey = _awsCredStorageKey
                            }
                        }
                    },
                    ItemType = ManagedCertificateType.SSL_LetsEncrypt_LocalIIS
                };

                var preview = await certifyManager.GeneratePreview(dummyManagedCertificate);

                var previewSummary = GetPreviewSummary(preview);
                System.Diagnostics.Debug.WriteLine(previewSummary);

                var deployStep = preview.Find(a => a.Category == "Deployment");
                Assert.IsTrue(deployStep.Substeps.Count == 1, "Only 1 binding deployment expected");
                Assert.IsTrue(deployStep.Substeps[0].Description == $"Add https binding | {testPreviewSiteName} | ***:443:{hostname} SNI**");
            }
            finally
            {
                // remove IIS site
                await iisManager.DeleteSite(testPreviewSiteName);

                // remove managed site
                if (managedCertificate != null)
                {
                    await certifyManager.DeleteManagedCertificate(managedCertificate.Id);
                }

                // cleanup certificate
                if (certInfo != null)
                {
                    CertificateManager.RemoveCertificate(certInfo);
                }
            }
        }