Skip to content

Commit

Permalink
fix http schema escaping when build url in webhook sender
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kolkov committed Apr 22, 2021
1 parent ca6019a commit fbcd900
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion senders/webhook/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ func buildRequestURL(template string, trigger moira.TriggerData, contact moira.C
moira.VariableTriggerID: trigger.ID,
}
for k, v := range templateVariables {
template = strings.Replace(template, k, url.PathEscape(v), -1)
value := url.PathEscape(v)
if k == moira.VariableContactValue &&
(strings.HasPrefix(v, "http:/") || strings.HasPrefix(v, "https://")) {
value = v
}
template = strings.Replace(template, k, value, -1)
}
return template
}
15 changes: 15 additions & 0 deletions senders/webhook/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ func TestBuildRequestURL(t *testing.T) {
})
}

var testContactWithUrl = moira.ContactData{
ID: "contactID",
Type: "contactType",
Value: "https://test/moirahook",
User: "contactUser",
Team: "contactTeam",
}

func TestBuildRequestURL_FromContactValueWithURL(t *testing.T) {
Convey("URL should contain variables values", t, func() {
actual := buildRequestURL("${contact_value}", testTrigger, testContactWithUrl)
So(actual, ShouldEqual, "https://test/moirahook")
})
}

func prepareStrings(actual, expected string) (string, string) {
return strings.Join(strings.Fields(actual), ""), strings.Join(strings.Fields(expected), "")
}

0 comments on commit fbcd900

Please sign in to comment.