示例#1
0
        public void Verify()
        {
            // Verify basic fields.

            var cert = new TlsCertificate();

            cert.Hosts.Add("foo.com");
            cert.ValidFrom  = DateTime.UtcNow - TimeSpan.FromMinutes(5);
            cert.ValidUntil = DateTime.UtcNow + TimeSpan.FromMinutes(5);

            Assert.True(cert.IsValidDate());
            Assert.True(cert.IsValidDate(DateTime.UtcNow));
            Assert.True(cert.IsValidDate(cert.ValidFrom));
            Assert.True(cert.IsValidDate(cert.ValidUntil));

            Assert.True(cert.IsValidHost("foo.com"));
            Assert.False(cert.IsValidHost("bar.com"));

            // Verify wildcard certs.

            cert.Hosts.Add("*.foo.com");

            Assert.True(cert.IsValidHost("foo.com"));
            Assert.False(cert.IsValidHost("bar.com"));
            Assert.True(cert.IsValidHost("test.foo.com"));
            Assert.True(cert.IsValidHost("bar.foo.com"));
            Assert.False(cert.IsValidHost("foobar.test.foo.com"));

            // Verify SAN certs with different hosts.

            cert.Hosts.Clear();
            cert.Hosts.Add("foo.com");
            cert.Hosts.Add("bar.com");
            cert.Hosts.Add("foobar.com");

            Assert.True(cert.IsValidHost("foo.com"));
            Assert.True(cert.IsValidHost("bar.com"));
            Assert.True(cert.IsValidHost("foobar.com"));
            Assert.False(cert.IsValidHost("test.foo.com"));
        }