forked from GithubBackups/healthchecks
Validate channel identifiers as UUIDs
This commit is contained in:
parent
d064112c16
commit
66bc5cd7c2
@ -152,6 +152,17 @@ class UpdateCheckTestCase(BaseTestCase):
|
|||||||
self.check.refresh_from_db()
|
self.check.refresh_from_db()
|
||||||
self.assertEqual(self.check.channel_set.count(), 0)
|
self.assertEqual(self.check.channel_set.count(), 0)
|
||||||
|
|
||||||
|
def test_it_rejects_non_uuid_channel_code(self):
|
||||||
|
r = self.post(self.check.code, {
|
||||||
|
"api_key": "X" * 32,
|
||||||
|
"channels": "foo"
|
||||||
|
})
|
||||||
|
|
||||||
|
self.assertEqual(r.status_code, 400)
|
||||||
|
|
||||||
|
self.check.refresh_from_db()
|
||||||
|
self.assertEqual(self.check.channel_set.count(), 0)
|
||||||
|
|
||||||
def test_it_rejects_non_string_channels_key(self):
|
def test_it_rejects_non_string_channels_key(self):
|
||||||
r = self.post(self.check.code, {
|
r = self.post(self.check.code, {
|
||||||
"api_key": "X" * 32,
|
"api_key": "X" * 32,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from datetime import timedelta as td
|
from datetime import timedelta as td
|
||||||
|
import uuid
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import SuspiciousOperation
|
from django.core.exceptions import SuspiciousOperation
|
||||||
@ -87,6 +88,11 @@ def _update(check, spec):
|
|||||||
else:
|
else:
|
||||||
channels = []
|
channels = []
|
||||||
for chunk in spec["channels"].split(","):
|
for chunk in spec["channels"].split(","):
|
||||||
|
try:
|
||||||
|
chunk = uuid.UUID(chunk)
|
||||||
|
except ValueError:
|
||||||
|
raise SuspiciousOperation("Invalid channel identifier")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
channel = Channel.objects.get(code=chunk)
|
channel = Channel.objects.get(code=chunk)
|
||||||
channels.append(channel)
|
channels.append(channel)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user