diff --git a/send.go b/send.go index 146c570..9f104ab 100644 --- a/send.go +++ b/send.go @@ -82,9 +82,11 @@ func isValidWebhookURL(webhookURL string) (bool, error) { return false, err } // only pass MS teams webhook URLs - hasPrefix := strings.HasPrefix(webhookURL, "https://outlook.office.com/webhook/") - if !hasPrefix { - err = errors.New("unvalid ms teams webhook url") + switch { + case strings.HasPrefix(webhookURL, "https://outlook.office.com/webhook/"): + case strings.HasPrefix(webhookURL, "https://outlook.office365.com/webhook/"): + default: + err = errors.New("invalid ms teams webhook url") return false, err } return true, nil diff --git a/send_test.go b/send_test.go index 370f4a6..c049b98 100644 --- a/send_test.go +++ b/send_test.go @@ -33,7 +33,7 @@ func TestTeamsClientSend(t *testing.T) { resError: nil, error: &url.Error{}, }, - // invalid webhookURL - missing pefix in (https://outlook.office.com...) URL + // invalid webhookURL - missing prefix in webhook URL { reqURL: "", reqMsg: emptyMessage, @@ -49,6 +49,14 @@ func TestTeamsClientSend(t *testing.T) { resError: errors.New("pling"), error: &url.Error{}, }, + // invalid httpClient.Do call + { + reqURL: "https://outlook.office365.com/webhook/xxx", + reqMsg: emptyMessage, + resStatus: 200, + resError: errors.New("pling"), + error: &url.Error{}, + }, // invalid response status code { reqURL: "https://outlook.office.com/webhook/xxx", @@ -57,6 +65,14 @@ func TestTeamsClientSend(t *testing.T) { resError: nil, error: errors.New(""), }, + // invalid response status code + { + reqURL: "https://outlook.office365.com/webhook/xxx", + reqMsg: emptyMessage, + resStatus: 400, + resError: nil, + error: errors.New(""), + }, // valid { reqURL: "https://outlook.office.com/webhook/xxx", @@ -65,6 +81,14 @@ func TestTeamsClientSend(t *testing.T) { resError: nil, error: nil, }, + // valid + { + reqURL: "https://outlook.office365.com/webhook/xxx", + reqMsg: emptyMessage, + resStatus: 200, + resError: nil, + error: nil, + }, } for _, test := range tests { client := NewTestClient(func(req *http.Request) (*http.Response, error) {