Skip to content

Commit

Permalink
fix(proxy-error): Show warning message for http proxy (#1643)
Browse files Browse the repository at this point in the history
  • Loading branch information
abasha1234 authored Sep 17, 2024
1 parent 63b16de commit ea54cb2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
15 changes: 13 additions & 2 deletions internal/install/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -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:")
Expand Down
27 changes: 27 additions & 0 deletions internal/install/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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.")
}

}

0 comments on commit ea54cb2

Please sign in to comment.