示例#1
0
        public void TestProtocol()
        {
            var connection = new ConnectionParams();

            connection.Protocol = null;
            Assert.Equal(connection.Protocol, "http");
            Assert.Null(connection.GetProtocol(null));
            Assert.Equal(connection.GetProtocol("https"), "https");
            connection.Protocol = "https";

            Assert.Equal(connection.Protocol, "https");
        }
        private void ValidateConnection(string correlationId, ConnectionParams connection)
        {
            if (connection == null)
            {
                throw new ConfigException(correlationId, "NO_CONNECTION", "HTTP connection is not set");
            }

            var uri = connection.Uri;

            if (!string.IsNullOrEmpty(uri))
            {
                return;
            }

            var protocol = connection.GetProtocol("http");

            if ("http" != protocol)
            {
                throw new ConfigException(
                          correlationId, "WRONG_PROTOCOL", "Protocol is not supported by REST connection")
                      .WithDetails("protocol", protocol);
            }

            var host = connection.Host;

            if (host == null)
            {
                throw new ConfigException(correlationId, "NO_HOST", "Connection host is not set");
            }

            var port = connection.Port;

            if (port == 0)
            {
                throw new ConfigException(correlationId, "NO_PORT", "Connection port is not set");
            }
        }
示例#3
0
        private void ValidateConnection(string correlationId, ConnectionParams connection, CredentialParams credential)
        {
            if (connection == null)
            {
                throw new ConfigException(correlationId, "NO_CONNECTION", "HTTP connection is not set");
            }

            var uri = connection.Uri;

            if (!string.IsNullOrEmpty(uri))
            {
                return;
            }

            var protocol = connection.GetProtocol("http");

            if ("http" != protocol && "https" != protocol)
            {
                throw new ConfigException(
                          correlationId, "WRONG_PROTOCOL", "Protocol is not supported by REST connection")
                      .WithDetails("protocol", protocol);
            }

            var host = connection.Host;

            if (host == null)
            {
                throw new ConfigException(correlationId, "NO_HOST", "Connection host is not set");
            }

            var port = connection.Port;

            if (port == 0)
            {
                throw new ConfigException(correlationId, "NO_PORT", "Connection port is not set");
            }

            // Check HTTPS credentials
            if (protocol == "https")
            {
                // Check for credential
                if (credential == null)
                {
                    throw new ConfigException(
                              correlationId, "NO_CREDENTIAL", "SSL certificates are not configured for HTTPS protocol");
                }

                // Sometimes when we use https we are on an internal network and do not want to have to deal with security.
                // When we need a https connection and we don't want to pass credentials, set the value 'no_credentials_needed' in the config yml credentials section
                if (credential.GetAsNullableString("internal_network") == null)
                {
                    if (credential.GetAsNullableString("ssl_password") == null)
                    {
                        throw new ConfigException(
                                  correlationId, "NO_SSL_PASSWORD", "SSL password is not configured in credentials");
                    }

                    if (credential.GetAsNullableString("ssl_pfx_file") == null)
                    {
                        throw new ConfigException(
                                  correlationId, "NO_SSL_PFX_FILE", "SSL pfx file is not configured in credentials");
                    }
                }
            }
        }