diff --git a/prometheus-to-sd/main.go b/prometheus-to-sd/main.go index 061c363b3..6ee06f247 100644 --- a/prometheus-to-sd/main.go +++ b/prometheus-to-sd/main.go @@ -293,10 +293,6 @@ func getEndpoint(input string) (string, error) { if err != nil { return "", fmt.Errorf("Failed to parse api override: %v", err) } - hostname := u.Hostname() - if hostname != "googleapis.com" && !strings.HasSuffix(hostname, ".googleapis.com") { - return "", fmt.Errorf("untrusted endpoint %q: must be a googleapis.com domain", hostname) - } port := u.Port() if port == "" { switch u.Scheme { diff --git a/prometheus-to-sd/main_test.go b/prometheus-to-sd/main_test.go index 44f9cf8cb..ec460b8ee 100644 --- a/prometheus-to-sd/main_test.go +++ b/prometheus-to-sd/main_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestGetEndpointTrusted(t *testing.T) { +func TestGetEndpoint(t *testing.T) { tests := []struct { input string expected string @@ -31,6 +31,11 @@ func TestGetEndpointTrusted(t *testing.T) { {"monitoring.googleapis.com:443", "monitoring.googleapis.com:443"}, {"https://monitoring.googleapis.com", "monitoring.googleapis.com:443"}, {"http://test-monitoring.sandbox.googleapis.com:80", "test-monitoring.sandbox.googleapis.com:80"}, + {"https://monitoring.apis-tpczero.goog/", "monitoring.apis-tpczero.goog:443"}, + {"monitoring.apis-tpczero.goog", "monitoring.apis-tpczero.goog:443"}, + {"http://test-monitoring.sandbox.googleapis.com:80", "test-monitoring.sandbox.googleapis.com:80"}, + {"http://127.0.0.1:8080", "127.0.0.1:8080"}, + {"localhost:8080", "localhost:8080"}, {"googleapis.com", "googleapis.com:443"}, } @@ -41,19 +46,3 @@ func TestGetEndpointTrusted(t *testing.T) { } } } - -func TestGetEndpointUntrusted(t *testing.T) { - tests := []string{ - "attacker.com", - "https://attacker.com", - "monitoring.googleapis.com.attacker.com", - "https://attacker.com/?foo=.googleapis.com", - "http://127.0.0.1:8080", - } - - for _, tc := range tests { - _, err := getEndpoint(tc) - assert.Error(t, err, "input: %s", tc) - assert.Contains(t, err.Error(), "untrusted endpoint") - } -}