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); }
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); } }
private async void btnRequestCertificate_Click(object sender, EventArgs e) { if (lstSites.SelectedItem == null) { MessageBox.Show("No IIS site selected"); return; } //prevent further clicks on request button btnRequestCertificate.Enabled = false; ShowProgressBar(); this.Cursor = Cursors.WaitCursor; var managedSite = GetUpdatedManagedSiteSettings(); //store the updated settings siteManager.UpdatedManagedSite(managedSite); //perform the certificate validations and request process var certifyManager = new CertifyManager(); var result = await certifyManager.PerformCertificateRequest(VaultManager, managedSite); if (!result.IsSuccess) { MessageBox.Show(result.ErrorMessage); } else { MessageBox.Show("Certificate Request Completed"); } this.Cursor = Cursors.Default; }
private async void button1_Click(object sender, EventArgs e) { if (this.selectedSite != null) { var certifyManager = new CertifyManager(); var vaultManager = GetParentMainForm().VaultManager; siteManager.LoadSettings(); var result = await certifyManager.PerformCertificateRequest(vaultManager, this.selectedSite); if (!result.IsSuccess) { MessageBox.Show("Failed to request a new certificate."); } else { MessageBox.Show("Certificate request completed."); } } }
public async void BeginCertificateRequest(string managedItemId) { //begin request process var managedSite = ManagedSites.FirstOrDefault(s => s.Id == managedItemId); if (managedSite != null) { MainUITabIndex = (int)MainWindow.PrimaryUITabs.CurrentProgress; //add request to observable list of progress state RequestProgressState progressState = new RequestProgressState(); progressState.ManagedItem = managedSite; //begin monitoring progress BeginTrackingProgress(progressState); var progressIndicator = new Progress <RequestProgressState>(progressState.ProgressReport); var result = await certifyManager.PerformCertificateRequest(null, managedSite, progressIndicator); if (progressIndicator != null) { var progress = (IProgress <RequestProgressState>)progressIndicator; if (result.IsSuccess) { progress.Report(new RequestProgressState { CurrentState = RequestState.Success, Message = result.Message }); } else { progress.Report(new RequestProgressState { CurrentState = RequestState.Error, Message = result.Message }); } } } }