コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);

            Assert.NotNull(certificate);
            Assert.Equal("7E2467E85A9FA8824F6A37469334AD1C", certificate.SerialNumber);
        }
コード例 #6
0
        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);

            Assert.Equal(expectedSN, certificate.SerialNumber);
        }
コード例 #7
0
        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));
            }
            else
            {
                Assert.ThrowsAny <CryptographicException>(() => loader.LoadCertificate(options));
            }
        }