Skip to content

Commit

Permalink
Fix issue in MS Teams webhook URL validation #18
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Oct 18, 2024
1 parent c314666 commit 818e15c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## [0.0.12]

- [#18](https://github.com/playwright-community/playwright-msteams-reporter/issues/18): Fix issue in MS Teams webhook URL validation

## [0.0.11]

- [#15](https://github.com/playwright-community/playwright-msteams-reporter/pull/15): New option `shouldRun` to control when to report based on suite values
Expand Down
19 changes: 19 additions & 0 deletions src/utils/validateWebhookUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ describe("validateWebhookUrl", () => {
)
).toBe(true);
});

it("Valid MS Teams webhook URL with a number 1", () => {
expect(
validateWebhookUrl(
"https://tenant9.webhook.office.com/webhookb2/0daed572-448a-4d0a-8ea8-b6a49e4625b3@b32d3268-2794-435f-865f-ab4779cae11e/IncomingWebhook/3814d9fc895847eb92cba3be342f1ce9/0ed480cd-fb54-4931-90da-1df7a1181c66/V2oHGgdElj-mUr4VOwzCnl8lvZhVHqSyqAkJRaCMi9QOI1",
"msteams"
)
).toBe(true);
});

it("Valid MS Teams webhook URL with a number 2", () => {
expect(
validateWebhookUrl(
"https://tenant2share.webhook.office.com/webhookb2/0daed572-448a-4d0a-8ea8-b6a49e4625b3@b32d3268-2794-435f-865f-ab4779cae11e/IncomingWebhook/3814d9fc895847eb92cba3be342f1ce9/0ed480cd-fb54-4931-90da-1df7a1181c66/V2oHGgdElj-mUr4VOwzCnl8lvZhVHqSyqAkJRaCMi9QOI1",
"msteams"
)
).toBe(true);
});

it("Invalid if MS Teams webhook URL is passed as Power Automate webhook URL", () => {
expect(
validateWebhookUrl(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/validateWebhookUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const validateWebhookUrl = (
} else if (type === "msteams") {
// https://tenant.webhook.office.com/webhookb2/{uuid}@{uuid}/IncomingWebhook/{id}/{uuid}
const webhook_pattern =
/^https:\/\/[a-zA-Z]+.webhook.office.com\/webhookb2\/[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?\S+\/IncomingWebhook\/[a-zA-Z0-9]+\/[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?/;
/^https:\/\/[a-zA-Z0-9]+.webhook.office.com\/webhookb2\/[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?\S+\/IncomingWebhook\/[a-zA-Z0-9]+\/[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?/;

return webhook_pattern.test(webhookUrl);
} else {
Expand Down

0 comments on commit 818e15c

Please sign in to comment.