@@ -23,7 +23,7 @@ func TestSignal(t *testing.T) {
2323 }))
2424 defer srv .Close ()
2525
26- s := NewSignal (srv .URL , "+33616400522" , []string {"+33689816957" , "+33616400522" })
26+ s := NewSignal (srv .URL , "+33616400522" , []string {"+33689816957" , "+33616400522" }, "" , "" , "" )
2727 if err := s .Send (context .Background (), "[Gjallar] DOWN: web" , "web — boom" ); err != nil {
2828 t .Fatal (err )
2929 }
@@ -43,6 +43,36 @@ func TestSignal(t *testing.T) {
4343 }
4444}
4545
46+ func TestSignalAuth (t * testing.T ) {
47+ var auth string
48+ srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
49+ auth = r .Header .Get ("Authorization" )
50+ w .WriteHeader (201 )
51+ }))
52+ defer srv .Close ()
53+
54+ // Bearer takes precedence.
55+ s := NewSignal (srv .URL , "+336" , []string {"+337" }, "tok123" , "u" , "p" )
56+ s .Send (context .Background (), "t" , "m" )
57+ if auth != "Bearer tok123" {
58+ t .Errorf ("bearer: got %q" , auth )
59+ }
60+
61+ // Basic when no token.
62+ s = NewSignal (srv .URL , "+336" , []string {"+337" }, "" , "user" , "pass" )
63+ s .Send (context .Background (), "t" , "m" )
64+ if ! strings .HasPrefix (auth , "Basic " ) {
65+ t .Errorf ("basic: got %q" , auth )
66+ }
67+
68+ // No auth when nothing configured.
69+ s = NewSignal (srv .URL , "+336" , []string {"+337" }, "" , "" , "" )
70+ s .Send (context .Background (), "t" , "m" )
71+ if auth != "" {
72+ t .Errorf ("no-auth: got %q" , auth )
73+ }
74+ }
75+
4676func TestBuildNotifiersSignal (t * testing.T ) {
4777 ns , err := BuildNotifiers (map [string ]config.Alert {
4878 "sig" : {Type : "signal" , URL : "http://h/v2/send" , Number : "+336" , Recipients : []string {"+337" }},
0 commit comments