forked from GithubBackups/healthchecks
API rejects too long check names
This commit is contained in:
parent
5a533441b5
commit
52cd2a9c8e
@ -1,8 +1,8 @@
|
|||||||
check = {
|
check = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"name": {"type": "string"},
|
"name": {"type": "string", "maxLength": 100},
|
||||||
"tags": {"type": "string"},
|
"tags": {"type": "string", "maxLength": 500},
|
||||||
"timeout": {"type": "number", "minimum": 60, "maximum": 604800},
|
"timeout": {"type": "number", "minimum": 60, "maximum": 604800},
|
||||||
"grace": {"type": "number", "minimum": 60, "maximum": 604800},
|
"grace": {"type": "number", "minimum": 60, "maximum": 604800},
|
||||||
"channels": {"type": "string"},
|
"channels": {"type": "string"},
|
||||||
|
@ -111,6 +111,10 @@ class CreateCheckTestCase(BaseTestCase):
|
|||||||
self.post({"api_key": "abc", "name": False},
|
self.post({"api_key": "abc", "name": False},
|
||||||
expected_fragment="name is not a string")
|
expected_fragment="name is not a string")
|
||||||
|
|
||||||
|
def test_it_rejects_long_name(self):
|
||||||
|
self.post({"api_key": "abc", "name": "01234567890" * 20},
|
||||||
|
expected_fragment="name is too long")
|
||||||
|
|
||||||
def test_unique_accepts_only_whitelisted_values(self):
|
def test_unique_accepts_only_whitelisted_values(self):
|
||||||
existing = Check(user=self.alice, name="Foo")
|
existing = Check(user=self.alice, name="Foo")
|
||||||
existing.save()
|
existing.save()
|
||||||
|
@ -15,6 +15,8 @@ def validate(obj, schema, obj_name="value"):
|
|||||||
if schema.get("type") == "string":
|
if schema.get("type") == "string":
|
||||||
if not isinstance(obj, string_types):
|
if not isinstance(obj, string_types):
|
||||||
raise ValidationError("%s is not a string" % obj_name)
|
raise ValidationError("%s is not a string" % obj_name)
|
||||||
|
if "maxLength" in schema and len(obj) > schema["maxLength"]:
|
||||||
|
raise ValidationError("%s is too long" % obj_name)
|
||||||
|
|
||||||
elif schema.get("type") == "number":
|
elif schema.get("type") == "number":
|
||||||
if not isinstance(obj, int):
|
if not isinstance(obj, int):
|
||||||
|
@ -12,6 +12,10 @@ class JsonSchemaTestCase(TestCase):
|
|||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
validate(123, {"type": "string"})
|
validate(123, {"type": "string"})
|
||||||
|
|
||||||
|
def test_it_checks_string_length(self):
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
validate("abcd", {"type": "string", "maxLength": 3})
|
||||||
|
|
||||||
def test_it_validates_numbers(self):
|
def test_it_validates_numbers(self):
|
||||||
validate(123, {"type": "number", "minimum": 0, "maximum": 1000})
|
validate(123, {"type": "number", "minimum": 0, "maximum": 1000})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user