private static int CleanHttpsCertificates(IReporter reporter) { var manager = new CertificateManager(); try { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { reporter.Output("Cleaning HTTPS development certificates from the machine. A prompt might get " + "displayed to confirm the removal of some of the certificates."); } if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { reporter.Output("Cleaning HTTPS development certificates from the machine. This operation might " + "require elevated privileges. If that is the case, a prompt for credentials will be displayed."); } manager.CleanupHttpsCertificates(); reporter.Verbose("HTTPS development certificates successfully removed from the machine."); return(Success); } catch (Exception e) { reporter.Error("There was an error trying to clean HTTPS development certificates on this machine."); reporter.Error(e.Message); return(ErrorCleaningUpCertificates); } }
public void EnsureAspNetCoreHttpsDevelopmentCertificate_CanRemoveCertificates() { var manager = new CertificateManager(); DateTimeOffset now = DateTimeOffset.UtcNow; now = new DateTimeOffset(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, 0, now.Offset); manager.EnsureAspNetCoreHttpsDevelopmentCertificate(now, now.AddYears(1), path: null, trust: true, subject: TestCertificateSubject); manager.CleanupHttpsCertificates(TestCertificateSubject); Assert.Empty(manager.ListCertificates(CertificatePurpose.HTTPS, StoreName.My, StoreLocation.CurrentUser, isValid: false).Where(c => c.Subject == TestCertificateSubject)); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Assert.Empty(manager.ListCertificates(CertificatePurpose.HTTPS, StoreName.Root, StoreLocation.CurrentUser, isValid: false).Where(c => c.Subject == TestCertificateSubject)); } }