Don't allow adding webhook integrations with both URLs blank

This commit is contained in:
Pēteris Caune 2019-12-27 17:13:44 +02:00
parent 84a4de32cc
commit 38ed309a3c
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
3 changed files with 25 additions and 0 deletions

View File

@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
- Unsubscribe links serve a form, and require HTTP POST to actually unsubscribe - Unsubscribe links serve a form, and require HTTP POST to actually unsubscribe
- For webhook integration, validate each header line separately - For webhook integration, validate each header line separately
- Fix "Send Test Notification" for webhooks that only fire on checks going up - Fix "Send Test Notification" for webhooks that only fire on checks going up
- Don't allow adding webhook integrations with both URLs blank
## v1.11.0 - 2019-11-22 ## v1.11.0 - 2019-11-22

View File

@ -122,6 +122,15 @@ class AddWebhookForm(forms.Form):
max_length=1000, required=False, validators=[WebhookValidator()] max_length=1000, required=False, validators=[WebhookValidator()]
) )
def clean(self):
super().clean()
url_down = self.cleaned_data.get("url_down")
url_up = self.cleaned_data.get("url_up")
if not url_down and not url_up:
self.add_error("url_down", "Enter a valid URL.")
def get_value(self): def get_value(self):
return json.dumps(dict(self.cleaned_data), sort_keys=True) return json.dumps(dict(self.cleaned_data), sort_keys=True)

View File

@ -144,3 +144,18 @@ class AddWebhookTestCase(BaseTestCase):
c = Channel.objects.get() c = Channel.objects.get()
self.assertEqual(c.down_webhook_spec["headers"], {"test": "123"}) self.assertEqual(c.down_webhook_spec["headers"], {"test": "123"})
def test_it_rejects_both_empty(self):
self.client.login(username="alice@example.org", password="password")
form = {
"method_down": "GET",
"url_down": "",
"method_up": "GET",
"url_up": "",
}
r = self.client.post(self.url, form)
self.assertContains(r, "Enter a valid URL.")
self.assertEqual(Channel.objects.count(), 0)