Skip to content

Commit

Permalink
Merge pull request #5 from atc0005/i3-allow-multiple-valid-webhook-fqdns
Browse files Browse the repository at this point in the history
Allow multiple valid webhook URL FQDNs
  • Loading branch information
dasrick authored Mar 26, 2020
2 parents feea812 + 937b5c8 commit 97487a6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
8 changes: 5 additions & 3 deletions send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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) {
Expand Down

0 comments on commit 97487a6

Please sign in to comment.