示例#1
0
        public void AcceptAll_Should_ThrowException_When_AlreadyEnabled()
        {
            // Arrange
            SslAcceptPolicy.Reset();
            SslAcceptPolicy.AcceptAll();

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => SslAcceptPolicy.AcceptAll());
        }
示例#2
0
        public void AcceptAll_Should_EnablePolicy()
        {
            // Arrange
            SslAcceptPolicy.Reset();

            // Act
            SslAcceptPolicy.AcceptAll();

            // Assert
            Assert.True(SslAcceptPolicy.Enabled);
        }
示例#3
0
        public void Reset_Should_DisablePolicyAfterBeingEnabled()
        {
            // Arrange
            SslAcceptPolicy.Reset();
            SslAcceptPolicy.AcceptAll();

            // Act
            SslAcceptPolicy.Reset();

            // Assert
            Assert.False(SslAcceptPolicy.Enabled);
        }
示例#4
0
        public void OriginalPolicy_Should_ContainOriginalPolicy_When_AcceptAllIsEnabled()
        {
            // Arrange
            SslAcceptPolicy.Reset();
            var expected = ServicePointManager.ServerCertificateValidationCallback;

            // Act
            SslAcceptPolicy.AcceptAll();

            // Assert
            Assert.Equal(expected, SslAcceptPolicy.OriginalPolicy);
        }
示例#5
0
        public void AcceptAll_Should_EnableAllCertificatedToBeAccepted()
        {
            // Arrange
            SslAcceptPolicy.Reset();
            var expected = typeof(SslAcceptPolicy.AcceptCertificatePolicy).Name;

            // Act
            SslAcceptPolicy.AcceptAll();
            var actual = ServicePointManager.ServerCertificateValidationCallback.Method.DeclaringType.Name;

            // Assert
            Assert.Equal(expected, actual);
        }
示例#6
0
        public void Reset_Should_PutOriginalPolicy_When_OneExisted()
        {
            // Arrange
            SslAcceptPolicy.Reset();
            ServicePointManager.ServerCertificateValidationCallback = AnotherCertificatePolicy.Validate;
            var expected = typeof(AnotherCertificatePolicy).Name;

            // Act
            SslAcceptPolicy.AcceptAll();
            SslAcceptPolicy.Reset();
            var actual = ServicePointManager.ServerCertificateValidationCallback.Method.DeclaringType.Name;

            // Assert
            Assert.Equal(expected, actual);
        }
示例#7
0
        public void AcceptAll_Should_AllowSelfSignedCertificate()
        {
            // Arrange
            SslAcceptPolicy.Reset();
            var cert  = LoadCertificate();
            var chain = new X509Chain();

            SslAcceptPolicy.AcceptAll();

            // Act
            var actual = ServicePointManager.ServerCertificateValidationCallback.Invoke(
                this,
                cert,
                chain,
                SslPolicyErrors.None);

            // Assert
            Assert.True(actual);
        }