Browse Source

Don't allow adding webhook integrations with both URLs blank

pull/320/head
Pēteris Caune 5 years ago
parent
commit
38ed309a3c
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 25 additions and 0 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +9
    -0
      hc/front/forms.py
  3. +15
    -0
      hc/front/tests/test_add_webhook.py

+ 1
- 0
CHANGELOG.md 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
- For webhook integration, validate each header line separately
- 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


+ 9
- 0
hc/front/forms.py View File

@ -122,6 +122,15 @@ class AddWebhookForm(forms.Form):
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):
return json.dumps(dict(self.cleaned_data), sort_keys=True)


+ 15
- 0
hc/front/tests/test_add_webhook.py View File

@ -144,3 +144,18 @@ class AddWebhookTestCase(BaseTestCase):
c = Channel.objects.get()
self.assertEqual(c.down_webhook_spec["headers"], {"test": "123"})
def test_it_rejects_both_empty(self):
self.client.login(username="[email protected]", 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)

Loading…
Cancel
Save