ifttt: Ensure topic and body are strings, and not dicts / arrays.

This commit is contained in:
Alex Vandiver 2021-12-13 11:06:21 -08:00 committed by Alex Vandiver
parent 850bc4cc81
commit 5ccbd0eade
4 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,4 @@
{
"topic": "Email sent from email@email.com",
"content": {"wrong": "example"}
}

View File

@ -0,0 +1,4 @@
{
"topic": {"wrong": "example"},
"content": "Email subject: Subject"
}

View File

@ -28,3 +28,15 @@ class IFTTTHookTests(WebhookTestCase):
payload = self.get_body("invalid_payload_with_missing_content")
result = self.client_post(self.url, payload, content_type="application/json")
self.assert_json_error(result, "Content can't be empty")
def test_ifttt_when_topic_is_dict(self) -> None:
self.url = self.build_webhook_url()
payload = self.get_body("invalid_payload_with_dict_topic")
result = self.client_post(self.url, payload, content_type="application/json")
self.assert_json_error(result, "Topic must be a string")
def test_ifttt_when_content_is_dict(self) -> None:
self.url = self.build_webhook_url()
payload = self.get_body("invalid_payload_with_dict_content")
result = self.client_post(self.url, payload, content_type="application/json")
self.assert_json_error(result, "Content must be a string")

View File

@ -29,5 +29,11 @@ def api_iftt_app_webhook(
if content is None:
raise JsonableError(_("Content can't be empty"))
if not isinstance(topic, str):
raise JsonableError(_("Topic must be a string"))
if not isinstance(content, str):
raise JsonableError(_("Content must be a string"))
check_send_webhook_message(request, user_profile, topic, content)
return json_success()