Skip to content

Commit

Permalink
Allow multiple valid webhook URL FQDNs
Browse files Browse the repository at this point in the history
Based on research/testing, it appears that both of these two
FQDNs are interchangeable:

- outlook.office.com
- outlook.office365.com

This commit makes the following changes to accept either
FQDN as a valid webhook prefix:

- update the isValidWebhookURL validation
  function to accept either one as a valid webhook prefix

- update the TestTeamsClientSend table test to include
  outlook.office365.com variations of existing test cases
  specific to outlook.office.com

refs dasrick#3
  • Loading branch information
atc0005 committed Mar 26, 2020
1 parent feea812 commit 937b5c8
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 937b5c8

Please sign in to comment.