Skip to content

Commit

Permalink
fix url check and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarconLP committed Oct 18, 2024
1 parent 4316315 commit dec5a2e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
icon_url="/static/services/microsoft-teams.png",
category=["Customer Success"],
hog="""
// We'll need to check if the url starts with this string instead
if (not inputs.webhookUrl like 'https://%.webhook.office.com/webhookb2/') {
if (not match(inputs.webhookUrl, '^https://[^/]+.webhook.office.com/webhookb2/.*')) {
throw Error('Invalid url');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,19 @@ def test_only_run_for_valid_url(self):
assert (
e.value.message == "Invalid url" # type: ignore[attr-defined]
)

def test_only_allow_teams_url(self):
for url, allowed in [
["https://max.webhook.office.com/webhookb2/abc", True],
["https://webhook.site/def", False],
["https://webhook.site/def#https://max.webhook.office.com/webhookb2/abc", False],
]:
if allowed:
self.run_function(inputs=self._inputs(webhookUrl=url))
assert len(self.get_mock_fetch_calls()) == 1
else:
with pytest.raises(Exception) as e:
self.run_function(inputs=self._inputs(webhookUrl=url))
assert (
e.value.message == "Invalid url" # type: ignore[attr-defined]
)

0 comments on commit dec5a2e

Please sign in to comment.