public void LoadCertificate_PemKeyDoesntMatchTheCertificateKey_Throws() { var loader = new CertificateConfigLoader(GetHostEnvironment()); var options = new CertificateConfigData { Path = TestResources.GetCertPath("https-aspnet.crt"), KeyPath = TestResources.GetCertPath("https-ecdsa.key") }; Assert.Throws <ArgumentException>(() => loader.LoadCertificate(options.AsConfigurationSection())); }
public void LoadCertificate_PemPathAndKeySpecifiedButPasswordIsMissing_Throws() { var loader = new CertificateConfigLoader(GetHostEnvironment()); var options = new CertificateConfigData { Path = TestResources.GetCertPath("https-aspnet.crt"), KeyPath = TestResources.GetCertPath("https-aspnet.key") }; Assert.Throws <ArgumentException>(() => loader.LoadCertificate(options.AsConfigurationSection())); }
public void LoadCertificate_PfxPasswordIsNotCorrect_Throws() { var loader = new CertificateConfigLoader(GetHostEnvironment()); var options = new CertificateConfigData { Path = TestResources.GetCertPath("aspnetdevcert.pfx"), Password = "******" }; Assert.ThrowsAny <CryptographicException>(() => loader.LoadCertificate(options.AsConfigurationSection())); }
public void LoadCertificate_PemPasswordIsIncorrect_Throws() { var loader = new CertificateConfigLoader(GetHostEnvironment()); var options = new CertificateConfigData { Path = TestResources.GetCertPath("https-aspnet.crt"), KeyPath = TestResources.GetCertPath("https-aspnet.key"), Password = "******" }; Assert.ThrowsAny <CryptographicException>(() => loader.LoadCertificate(options.AsConfigurationSection())); }
public void LoadCertificate_PfxPathAndPasswordSpecified_Success() { var loader = new CertificateConfigLoader(GetHostEnvironment()); var options = new CertificateConfigData { Path = TestResources.GetCertPath("aspnetdevcert.pfx"), Password = "******" }; var certificate = loader.LoadCertificate(options.AsConfigurationSection()); Assert.NotNull(certificate); Assert.Equal("7E2467E85A9FA8824F6A37469334AD1C", certificate.SerialNumber); }
public void LoadCertificate_PemLoadCertificate_Success(string certificateFile, string certificateKey, string password, string expectedSN) { var loader = new CertificateConfigLoader(GetHostEnvironment()); var options = new CertificateConfigData { Path = TestResources.GetCertPath(certificateFile), KeyPath = TestResources.GetCertPath(certificateKey), Password = password }; var certificate = loader.LoadCertificate(options.AsConfigurationSection()); Assert.Equal(expectedSN, certificate.SerialNumber); }
public void LoadCertificate_PfxFileNotFound_Throws() { var loader = new CertificateConfigLoader(GetHostEnvironment()); var options = new CertificateConfigData { Path = TestResources.GetCertPath("missingfile.pfx"), Password = "******" }; if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Assert.ThrowsAny <FileNotFoundException>(() => loader.LoadCertificate(options.AsConfigurationSection())); } else { Assert.ThrowsAny <CryptographicException>(() => loader.LoadCertificate(options.AsConfigurationSection())); } }