From ea54cb29a8c0d1d1efa16f85b4bf935d21bd73f7 Mon Sep 17 00:00:00 2001 From: Ahmed Basha <127721368+abasha1234@users.noreply.github.com> Date: Tue, 17 Sep 2024 10:31:37 +0530 Subject: [PATCH] fix(proxy-error): Show warning message for http proxy (#1643) --- internal/install/command.go | 15 +++++++++++++-- internal/install/command_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/internal/install/command.go b/internal/install/command.go index f85cf351c..78e18d558 100644 --- a/internal/install/command.go +++ b/internal/install/command.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "strings" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -147,10 +148,20 @@ func checkNetwork() error { } err := client.NRClient.TestEndpoints() - if err != nil { + + proxyConfig := httpproxy.FromEnvironment() + + if err == nil { if IsProxyConfigured() { - proxyConfig := httpproxy.FromEnvironment() + if strings.Contains(strings.ToLower(proxyConfig.HTTPSProxy), "http") && !strings.Contains(strings.ToLower(proxyConfig.HTTPSProxy), "https") { + log.Warn("Please ensure the HTTPS_PROXY environment variable is set when using a proxy server.") + log.Warn("New Relic CLI exclusively supports https proxy, not http for security reasons.") + } + } + } + if err != nil { + if IsProxyConfigured() { log.Warn("Proxy settings have been configured, but we are still unable to connect to the New Relic platform.") log.Warn("You may need to adjust your proxy environment variables or configure your proxy to allow the specified domain.") log.Warn("Current proxy config:") diff --git a/internal/install/command_test.go b/internal/install/command_test.go index 2529e6015..9ea0ffbee 100644 --- a/internal/install/command_test.go +++ b/internal/install/command_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "os" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -94,3 +95,29 @@ func initSegmentMockServer() *httptest.Server { })) return server } + +func TestProxyNetwork(t *testing.T) { + + proxyConfig := struct { + HTTPSProxy string + HTTPProxy string + }{ + HTTPSProxy: "http://localhost:3128", + HTTPProxy: "http://localhost:8080", + } + + // Validate HTTPSProxy + if strings.HasPrefix(proxyConfig.HTTPSProxy, "http://") { + t.Log("New Relic CLI exclusively supports https proxy, not http for security reasons.") + } else if strings.HasPrefix(proxyConfig.HTTPSProxy, "https://") { + // Do nothing + } else { + t.Log("Invalid proxy provided") + } + + // Validate HTTPProxy + if strings.HasPrefix(proxyConfig.HTTPProxy, "http://") { + t.Log("If you need to use a proxy, consider setting the HTTPS_PROXY environment variable, then try again. New Relic CLI exclusively supports https proxy.") + } + +}