示例#1
0
        public void ParseCertificatesResponseInvalidCertificateShouldThrow()
        {
            ServerCertificateResponse cert = new ServerCertificateResponse()
            {
                Certificate = "InvalidCert"
            };

            Assert.Throws <InvalidOperationException>(() => CertificateHelper.ParseCertificateResponse(cert));
        }
        public void ParseCertificatesResponseInvalidCertificateShouldThrow()
        {
            var response = new CertificateResponse()
            {
                Certificate = "InvalidCert",
            };

            Assert.Throws <InvalidOperationException>(() => CertificateHelper.ParseCertificateResponse(response));
        }
示例#3
0
        public void ParseCertificatesResponseInvalidKeyShouldThrow()
        {
            var response = new ServerCertificateResponse()
            {
                Certificate = TestCertificateHelper.CertificatePem,
                PrivateKey  = "InvalidKey"
            };

            Assert.Throws <InvalidOperationException>(() => CertificateHelper.ParseCertificateResponse(response));
        }
        public void ParseCertificatesResponseInvalidKeyShouldThrow()
        {
            var response = new CertificateResponse()
            {
                Certificate = TestCertificateHelper.CertificatePem,
                Expiration  = DateTime.UtcNow.AddDays(1),
                PrivateKey  = new PrivateKey()
                {
                    Bytes = "InvalidKey"
                }
            };

            Assert.Throws <InvalidOperationException>(() => CertificateHelper.ParseCertificateResponse(response));
        }
示例#5
0
        public void ParseCertificatesResponseShouldReturnCert()
        {
            TestCertificateHelper.GenerateSelfSignedCert("top secret").Export(X509ContentType.Cert);
            var response = new ServerCertificateResponse()
            {
                Certificate = $"{TestCertificateHelper.CertificatePem}\n{TestCertificateHelper.CertificatePem}",
                PrivateKey  = TestCertificateHelper.PrivateKeyPem
            };

            (X509Certificate2 cert, IEnumerable <X509Certificate2> chain) = CertificateHelper.ParseCertificateResponse(response);

            var expected = new X509Certificate2(Encoding.UTF8.GetBytes(TestCertificateHelper.CertificatePem));

            Assert.Equal(expected, cert);
            Assert.True(cert.HasPrivateKey);
            Assert.Single(chain);
            Assert.Equal(expected, chain.First());
        }
        public void ParseCertificatesResponseShouldReturnCert()
        {
            TestCertificateHelper.GenerateSelfSignedCert("top secret").Export(X509ContentType.Cert);
            var response = new CertificateResponse()
            {
                Certificate = $"{TestCertificateHelper.CertificatePem}\n{TestCertificateHelper.CertificatePem}",
                Expiration  = DateTime.UtcNow.AddDays(1),
                PrivateKey  = new PrivateKey()
                {
                    Bytes = TestCertificateHelper.PrivateKeyPem
                }
            };

            (X509Certificate2 cert, IEnumerable <X509Certificate2> chain) = CertificateHelper.ParseCertificateResponse(response);

            var expected = new X509Certificate2(Encoding.UTF8.GetBytes(TestCertificateHelper.CertificatePem));

            Assert.Equal(expected, cert);
            Assert.True(cert.HasPrivateKey);
            Assert.Equal(chain.Count(), 1);
            Assert.Equal(expected, chain.First());
        }