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