Beispiel #1
0
        public void Reset_Should_DisablePolicy()
        {
            // Act
            SslAcceptPolicy.Reset();

            // Assert
            Assert.False(SslAcceptPolicy.Enabled);
        }
Beispiel #2
0
        public void AcceptAll_Should_ThrowException_When_AlreadyEnabled()
        {
            // Arrange
            SslAcceptPolicy.Reset();
            SslAcceptPolicy.AcceptAll();

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

            // Act
            SslAcceptPolicy.AcceptAll();

            // Assert
            Assert.True(SslAcceptPolicy.Enabled);
        }
Beispiel #4
0
        public void Reset_Should_DisablePolicyAfterBeingEnabled()
        {
            // Arrange
            SslAcceptPolicy.Reset();
            SslAcceptPolicy.AcceptAll();

            // Act
            SslAcceptPolicy.Reset();

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

            // Act
            SslAcceptPolicy.AcceptAll();

            // Assert
            Assert.Equal(expected, SslAcceptPolicy.OriginalPolicy);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }