Example #1
0
        public void HttpSelfHostConfiguration_UserNamePasswordValidator_PropagatesToBinding(
            string address,
            HttpBindingSecurityMode mode
            )
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            UserNamePasswordValidator validator = new Mock <UserNamePasswordValidator>().Object;
            HttpSelfHostConfiguration config    = new HttpSelfHostConfiguration(address)
            {
                UserNamePasswordValidator = validator
            };

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);

            // Assert
            Assert.NotNull(parameters);
            ServiceCredentials serviceCredentials = parameters.Find <ServiceCredentials>();

            Assert.NotNull(serviceCredentials);
            Assert.Equal(
                HttpClientCredentialType.Basic,
                binding.Security.Transport.ClientCredentialType
                );
            Assert.Equal(mode, binding.Security.Mode);
        }
 /// <summary>
 /// Validates the specified <paramref name="value"/> and throws an <see cref="InvalidEnumArgumentException"/>
 /// exception if not valid.
 /// </summary>
 /// <param name="value">The value to validate.</param>
 /// <param name="parameterName">Name of the parameter to use if throwing exception.</param>
 public static void Validate(HttpBindingSecurityMode value, string parameterName)
 {
     if (!IsDefined(value))
     {
         throw Error.InvalidEnumArgument(parameterName, (int)value, _httpBindingSecurityMode);
     }
 }
 /// <summary>
 /// Validates the specified <paramref name="value"/> and throws an <see cref="InvalidEnumArgumentException"/>
 /// exception if not valid.
 /// </summary>
 /// <param name="value">The value to validate.</param>
 /// <param name="parameterName">Name of the parameter to use if throwing exception.</param>
 public static void Validate(HttpBindingSecurityMode value, string parameterName)
 {
     if (!IsDefined(value))
     {
         throw Error.InvalidEnumArgument(parameterName, (int)value, typeof(HttpBindingSecurityMode));
     }
 }
Example #4
0
        public void HttpSelfHostConfiguration_CorrectClientCredentialType_WithX509CertificateValidator_Works(
            string address,
            HttpBindingSecurityMode mode,
            HttpClientCredentialType clientCredentialType
            )
        {
            // Arrange
            GC.KeepAlive(mode); // Mark parameter as used. See xUnit1026, [Theory] method doesn't use all parameters.
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                X509CertificateValidator = new Mock <X509CertificateValidator>().Object
            };

            config.ClientCredentialType = clientCredentialType;

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);
        }
Example #5
0
        public void HttpSelfHostConfiguration_ClientCredentialType_PropagatesToHttpBinding(
            string address,
            HttpBindingSecurityMode mode,
            HttpClientCredentialType clientCredentialType
            )
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                ClientCredentialType = clientCredentialType
            };

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);

            Assert.Equal(clientCredentialType, binding.Security.Transport.ClientCredentialType);
            Assert.Equal(mode, binding.Security.Mode);
        }
Example #6
0
        public void HttpSelfHostConfiguration_CorrectClientCredentialType_WithUsernamePasswordValidator_Works(
            string address,
            HttpBindingSecurityMode mode,
            HttpClientCredentialType clientCredentialType
            )
        {
            // Arrange
            GC.KeepAlive(mode); // Mark parameter as used. See xUnit1026, [Theory] method doesn't use all parameters.
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                UserNamePasswordValidator = new CustomUsernamePasswordValidator()
            };

            config.ClientCredentialType = clientCredentialType;

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);
        }
Example #7
0
 /// <summary>
 /// Creates a new instance of the <see cref="HttpBindingSecurity"/> class.
 /// </summary>
 public HttpBindingSecurity()
 {
     this.mode = DefaultMode;
     this.transportSecurity = new HttpTransportSecurity();
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpBinding"/> class with the
 /// type of security used by the binding explicitly specified.
 /// </summary>
 /// <param name="securityMode">The value of <see cref="HttpBindingSecurityMode"/> that
 /// specifies the type of security that is used to configure a service endpoint using the
 /// <see cref="HttpBinding"/> binding.
 /// </param>
 public HttpBinding(HttpBindingSecurityMode securityMode)
     : this()
 {
     _security.Mode = securityMode;
 }
Example #9
0
 /// <summary>
 /// Creates a new instance of the <see cref="HttpBindingSecurity"/> class.
 /// </summary>
 public HttpBindingSecurity()
 {
     _mode = DefaultMode;
     _transportSecurity = new HttpTransportSecurity();
 }
        public void HttpSelfHostConfiguration_UserNamePasswordValidator_PropagatesToBinding(string address, HttpBindingSecurityMode mode)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            UserNamePasswordValidator validator = new Mock<UserNamePasswordValidator>().Object;
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                UserNamePasswordValidator = validator
            };

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);

            // Assert
            Assert.NotNull(parameters);
            ServiceCredentials serviceCredentials = parameters.Find<ServiceCredentials>();
            Assert.NotNull(serviceCredentials);
            Assert.Equal(HttpClientCredentialType.Basic, binding.Security.Transport.ClientCredentialType);
            Assert.Equal(mode, binding.Security.Mode);
        }
        public void HttpSelfHostConfiguration_CorrectClientCredentialType_WithX509CertificateValidator_Works(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                X509CertificateValidator = new Mock<X509CertificateValidator>().Object
            };

            config.ClientCredentialType = clientCredentialType;

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);
        }
Example #12
0
        public void HttpSelfHostConfiguration_WrongClientCredentialType_WithX509CertificateValidator_Throws(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                X509CertificateValidator = new Mock <X509CertificateValidator>().Object
            };

            config.ClientCredentialType = clientCredentialType;

            Assert.Throws <InvalidOperationException>(() =>
            {
                // Act
                BindingParameterCollection parameters = config.ConfigureBinding(binding);
            });
        }
 /// <summary>
 /// Determines whether the specified <paramref name="value"/> is defined by the <see cref="HttpBindingSecurityMode"/>
 /// enumeration.
 /// </summary>
 /// <param name="value">The value to test.</param>
 /// <returns><c>true</c> if <paramref name="value"/> is a valid <see cref="HttpBindingSecurityMode"/> value; otherwise<c> false</c>.</returns>
 public static bool IsDefined(HttpBindingSecurityMode value)
 {
     return(value == HttpBindingSecurityMode.None ||
            value == HttpBindingSecurityMode.Transport ||
            value == HttpBindingSecurityMode.TransportCredentialOnly);
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpBinding"/> class with the 
 /// type of security used by the binding explicitly specified.
 /// </summary>
 /// <param name="securityMode">The value of <see cref="HttpBindingSecurityMode"/> that 
 /// specifies the type of security that is used to configure a service endpoint using the
 /// <see cref="HttpBinding"/> binding.
 /// </param>
 public HttpBinding(HttpBindingSecurityMode securityMode)
     : this()
 {
     _security.Mode = securityMode;
 }
        public void HttpSelfHostConfiguration_ClientCredentialType_PropagatesToHttpBinding(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                ClientCredentialType = clientCredentialType
            };

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);

            Assert.Equal(clientCredentialType, binding.Security.Transport.ClientCredentialType);
            Assert.Equal(mode, binding.Security.Mode);
        }
        public void HttpSelfHostConfiguration_UseWindowsAuth_PropagatesToHttpBinding(string address, HttpBindingSecurityMode mode)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                UseWindowsAuthentication = true
            };

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);

            // Assert
            Assert.NotNull(parameters);
            ServiceCredentials serviceCredentials = parameters.Find<ServiceCredentials>();
            Assert.NotNull(serviceCredentials);
            Assert.Equal(HttpClientCredentialType.Windows, binding.Security.Transport.ClientCredentialType);
            Assert.Equal(mode, binding.Security.Mode);
        }
        public void HttpSelfHostConfiguration_UseWindowsAuth_PropagatesToHttpBinding(string address, HttpBindingSecurityMode mode)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                UseWindowsAuthentication = true
            };

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);

            // Assert
            Assert.NotNull(parameters);
            ServiceCredentials serviceCredentials = parameters.Find <ServiceCredentials>();

            Assert.NotNull(serviceCredentials);
            Assert.Equal(HttpClientCredentialType.Windows, binding.Security.Transport.ClientCredentialType);
            Assert.Equal(mode, binding.Security.Mode);
        }
 /// <summary>
 /// Creates a new instance of the <see cref="HttpBindingSecurity"/> class.
 /// </summary>
 public HttpBindingSecurity()
 {
     _mode = DefaultMode;
     _transportSecurity = new HttpTransportSecurity();
 }
Example #19
0
        public void HttpSelfHostConfiguration_CorrectClientCredentialType_WithX509CertificateValidator_Works(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                X509CertificateValidator = new Mock <X509CertificateValidator>().Object
            };

            config.ClientCredentialType = clientCredentialType;

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);
        }
 /// <summary>
 /// Determines whether the specified <paramref name="value"/> is defined by the <see cref="HttpBindingSecurityMode"/>
 /// enumeration.
 /// </summary>
 /// <param name="value">The value to test.</param>
 /// <returns><c>true</c> if <paramref name="value"/> is a valid <see cref="HttpBindingSecurityMode"/> value; otherwise<c> false</c>.</returns>
 public static bool IsDefined(HttpBindingSecurityMode value)
 {
     return value == HttpBindingSecurityMode.None ||
            value == HttpBindingSecurityMode.Transport ||
            value == HttpBindingSecurityMode.TransportCredentialOnly;
 }
Example #21
0
        public void HttpSelfHostConfiguration_WrongClientCredentialType_WithUsernamePasswordValidator_Throws(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                UserNamePasswordValidator = new CustomUsernamePasswordValidator()
            };

            config.ClientCredentialType = clientCredentialType;

            Assert.Throws <InvalidOperationException>(() =>
            {
                // Act
                BindingParameterCollection parameters = config.ConfigureBinding(binding);
            });
        }
        public void HttpSelfHostConfiguration_WrongClientCredentialType_WithX509CertificateValidator_Throws(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                X509CertificateValidator = new Mock<X509CertificateValidator>().Object
            };

            config.ClientCredentialType = clientCredentialType;

            Assert.Throws<InvalidOperationException>(() =>
            {
                // Act
                BindingParameterCollection parameters = config.ConfigureBinding(binding);
            });
        }
        public void HttpSelfHostConfiguration_WrongClientCredentialType_WithUsernamePasswordValidator_Throws(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                UserNamePasswordValidator = new CustomUsernamePasswordValidator()
            };

            config.ClientCredentialType = clientCredentialType;

            Assert.Throws<InvalidOperationException>(() =>
                {
                    // Act
                    BindingParameterCollection parameters = config.ConfigureBinding(binding);
                });
        }
Example #24
0
        public void HttpSelfHostConfiguration_CorrectClientCredentialType_WithUsernamePasswordValidator_Works(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                UserNamePasswordValidator = new CustomUsernamePasswordValidator()
            };

            config.ClientCredentialType = clientCredentialType;

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);
        }
Example #25
0
 /// <summary>
 /// Creates a new instance of the <see cref="HttpBindingSecurity"/> class.
 /// </summary>
 public HttpBindingSecurity()
 {
     this.mode = DefaultMode;
     this.transportSecurity = new HttpTransportSecurity();
 }
        public void HttpSelfHostConfiguration_CorrectClientCredentialType_WithUsernamePasswordValidator_Works(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType)
        {
            // Arrange
            HttpBinding binding = new HttpBinding();
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address)
            {
                UserNamePasswordValidator = new CustomUsernamePasswordValidator()
            };

            config.ClientCredentialType = clientCredentialType;

            // Act
            BindingParameterCollection parameters = config.ConfigureBinding(binding);
        }