diff --git a/transport/client.go b/transport/client.go index 5e97ff1e..e2692858 100644 --- a/transport/client.go +++ b/transport/client.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "net" + "net/url" "sync" "time" @@ -215,9 +216,25 @@ func (c *Client) handleError(err error) error { func (c *Client) Test(d testing.Driver) { d.Run("logstash: "+c.host, func(d testing.Driver) { + if c.config.Proxy.URL != "" { + d.Run("proxy", func(d testing.Driver) { + url, err1 := url.Parse(c.config.Proxy.URL) + d.Fatal("parse url", err1) + dialer := TestNetDialer(d, c.config.Timeout) + _, err2 := dialer.Dial("tcp", url.Host) + d.Fatal("dial up", err2) + }) + } + d.Run("connection", func(d testing.Driver) { - netDialer := TestNetDialer(d, c.config.Timeout) - _, err := netDialer.Dial("tcp", c.host) + var dialer Dialer + if c.config.Proxy.URL == "" { + dialer = TestNetDialer(d, c.config.Timeout) + } else { + dialer = NetDialer(c.config.Timeout) + dialer = TestProxyDialer(d, dialer, c.config.Proxy, c.config.Timeout) + } + _, err := dialer.Dial("tcp", c.host) d.Fatal("dial up", err) }) @@ -225,9 +242,12 @@ func (c *Client) Test(d testing.Driver) { d.Warn("TLS", "secure connection disabled") } else { d.Run("TLS", func(d testing.Driver) { - netDialer := NetDialer(c.config.Timeout) - tlsDialer := TestTLSDialer(d, netDialer, c.config.TLS, c.config.Timeout) - _, err := tlsDialer.Dial("tcp", c.host) + dialer := NetDialer(c.config.Timeout) + if c.config.Proxy.URL != "" { + dialer = TestProxyDialer(d, dialer, c.config.Proxy, c.config.Timeout) + } + dialer = TestTLSDialer(d, dialer, c.config.TLS, c.config.Timeout) + _, err := dialer.Dial("tcp", c.host) d.Fatal("dial up", err) }) } diff --git a/transport/proxy.go b/transport/proxy.go index 3c3dbf65..d9bcaeb8 100644 --- a/transport/proxy.go +++ b/transport/proxy.go @@ -20,10 +20,12 @@ package transport import ( "net" "net/url" + "time" "golang.org/x/net/proxy" "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/testing" ) // ProxyConfig holds the configuration information required to proxy @@ -97,3 +99,14 @@ func ProxyDialer(log *logp.Logger, config *ProxyConfig, forward Dialer) (Dialer, return DialWith(dialer, network, host, addresses, port) }), nil } + +func TestProxyDialer( + d testing.Driver, + forward Dialer, + config *ProxyConfig, + timeout time.Duration, +) Dialer { + dialer, err := ProxyDialer(logp.L(), config, forward) + d.Fatal("proxy", err) + return dialer +}