2020-07-20 19:59:28 +02:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
|
|
|
2021-12-16 21:34:08 +01:00
|
|
|
class CanarytokensHookTests(WebhookTestCase):
|
2021-02-12 08:20:45 +01:00
|
|
|
STREAM_NAME = "canarytoken"
|
2020-07-20 19:59:28 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/canarytoken?stream={stream}&api_key={api_key}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "canarytoken"
|
2020-07-20 19:59:28 +02:00
|
|
|
|
|
|
|
def test_canarytoken_new(self) -> None:
|
|
|
|
expected_message = (
|
|
|
|
"**:alert: Canarytoken has been triggered on 2020-06-09 14:04:39!**\n\n"
|
|
|
|
"Congrats! The newly saved webhook works \n\n"
|
|
|
|
"[Manage this canarytoken](http://example.com/test/url/for/webhook)"
|
|
|
|
)
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"canarytoken_new",
|
|
|
|
"canarytoken alert",
|
2020-07-20 19:59:28 +02:00
|
|
|
expected_message,
|
2020-08-23 15:49:24 +02:00
|
|
|
content_type="application/x-www-form-urlencoded",
|
2020-07-20 19:59:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_canarytoken_real(self) -> None:
|
|
|
|
expected_message = (
|
|
|
|
"**:alert: Canarytoken has been triggered on 2020-06-09 14:04:47 "
|
|
|
|
"(UTC)!**\n\n"
|
|
|
|
"Canarytoken example \n\n"
|
|
|
|
"[Manage this canarytoken]"
|
|
|
|
"(https://canarytokens.org/manage?token=foo&auth=bar)"
|
|
|
|
)
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"canarytoken_real",
|
|
|
|
"canarytoken alert",
|
2020-07-20 19:59:28 +02:00
|
|
|
expected_message,
|
2020-08-23 15:49:24 +02:00
|
|
|
content_type="application/x-www-form-urlencoded",
|
2020-07-20 19:59:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_canarytoken_with_specific_topic(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
self.url = self.build_webhook_url(topic="foo")
|
2020-07-20 19:59:28 +02:00
|
|
|
expected_message = (
|
|
|
|
"**:alert: Canarytoken has been triggered on 2020-06-09 14:04:47 "
|
|
|
|
"(UTC)!**\n\n"
|
|
|
|
"Canarytoken example \n\n"
|
|
|
|
"[Manage this canarytoken]"
|
|
|
|
"(https://canarytokens.org/manage?token=foo&auth=bar)"
|
|
|
|
)
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"canarytoken_real",
|
|
|
|
"foo",
|
2020-07-20 19:59:28 +02:00
|
|
|
expected_message,
|
2020-08-23 15:49:24 +02:00
|
|
|
content_type="application/x-www-form-urlencoded",
|
2020-07-20 19:59:28 +02:00
|
|
|
)
|