Browse Source

API rejects too long check names

pull/109/head
Pēteris Caune 8 years ago
parent
commit
52cd2a9c8e
4 changed files with 12 additions and 2 deletions
  1. +2
    -2
      hc/api/schemas.py
  2. +4
    -0
      hc/api/tests/test_create_check.py
  3. +2
    -0
      hc/lib/jsonschema.py
  4. +4
    -0
      hc/lib/tests/test_jsonschema.py

+ 2
- 2
hc/api/schemas.py View File

@ -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"},


+ 4
- 0
hc/api/tests/test_create_check.py View File

@ -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()


+ 2
- 0
hc/lib/jsonschema.py View File

@ -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):


+ 4
- 0
hc/lib/tests/test_jsonschema.py View File

@ -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…
Cancel
Save