mirror of
https://github.com/prometheus/alertmanager
synced 2025-02-16 10:37:09 +00:00
Trim contents of slack api urls from files (#2929)
* Trim contents of slack api urls from files Signed-off-by: Sarah Brofeldt <sarah@qtr.dk> * notify/slack: fix test imports Signed-off-by: Simon Pasquier <spasquie@redhat.com> Signed-off-by: Sarah Brofeldt <sarah@qtr.dk> Signed-off-by: Simon Pasquier <spasquie@redhat.com> Co-authored-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
a862b7f4b4
commit
565d73da5e
@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
@ -194,7 +195,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
u = string(content)
|
||||
u = strings.TrimSpace(string(content))
|
||||
}
|
||||
|
||||
resp, err := notify.PostJSON(ctx, n.client, u, &buf)
|
||||
|
@ -15,6 +15,7 @@ package slack
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@ -80,3 +81,25 @@ func TestGettingSlackURLFromFile(t *testing.T) {
|
||||
|
||||
test.AssertNotifyLeaksNoSecret(ctx, t, notifier, u.String())
|
||||
}
|
||||
|
||||
func TestTrimmingSlackURLFromFile(t *testing.T) {
|
||||
ctx, u, fn := test.GetContextWithCancelingURL()
|
||||
defer fn()
|
||||
|
||||
f, err := ioutil.TempFile("", "slack_test_newline")
|
||||
require.NoError(t, err, "creating temp file failed")
|
||||
_, err = f.WriteString(u.String() + "\n\n")
|
||||
require.NoError(t, err, "writing to temp file failed")
|
||||
|
||||
notifier, err := New(
|
||||
&config.SlackConfig{
|
||||
APIURLFile: f.Name(),
|
||||
HTTPConfig: &commoncfg.HTTPClientConfig{},
|
||||
},
|
||||
test.CreateTmpl(t),
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
test.AssertNotifyLeaksNoSecret(ctx, t, notifier, u.String())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user