Files
karma/internal/alertmanager/model_test.go
Łukasz Mierzwa fd0eb46adf Sanitize Alertmanager URI before putting it in /alerts.json reponse
Alertmanager URI might contain basic auth username & password, we should replace password with 'xxx' in logs and and error messages.
Go will still print it in HTTP request errors, but that will be fixed in the next Go release - https://go-review.googlesource.com/c/go/+/102855
Fixes #259
2018-04-27 09:36:12 -07:00

63 lines
1.4 KiB
Go

package alertmanager
import (
"testing"
)
type uriTest struct {
rawURI string
proxy bool
publicURI string
}
var uriTests = []uriTest{
{
rawURI: "http://alertmanager.example.com",
proxy: false,
publicURI: "http://alertmanager.example.com",
},
{
rawURI: "http://alertmanager.example.com/foo",
proxy: false,
publicURI: "http://alertmanager.example.com/foo",
},
{
rawURI: "http://alertmanager.example.com",
proxy: true,
publicURI: "/proxy/alertmanager/test",
},
{
rawURI: "http://alertmanager.example.com/foo",
proxy: true,
publicURI: "/proxy/alertmanager/test",
},
{
rawURI: "http://user:pass@alertmanager.example.com",
proxy: false,
publicURI: "http://user:pass@alertmanager.example.com",
},
{
rawURI: "https://user:pass@alertmanager.example.com/foo",
proxy: false,
publicURI: "https://user:pass@alertmanager.example.com/foo",
},
{
rawURI: "http://user:pass@alertmanager.example.com",
proxy: true,
publicURI: "/proxy/alertmanager/test",
},
}
func TestAlertmanagerURI(t *testing.T) {
for _, test := range uriTests {
am, err := NewAlertmanager("test", test.rawURI, WithProxy(test.proxy))
if err != nil {
t.Error(err)
}
if am.publicURI() != test.publicURI {
t.Errorf("Public URI mismatch, expected '%s' => '%s', got '%s' (proxy: %v)",
test.rawURI, test.publicURI, am.publicURI(), test.proxy)
}
}
}