Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions prometheus-to-sd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 6 additions & 17 deletions prometheus-to-sd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"},
}

Expand All @@ -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")
}
}