Skip to content
Snippets Groups Projects
Commit 99160dd0 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Check that artifact IDs are UUIDs in recipes

parent 6e916183
No related branches found
No related tags found
1 merge request!1902Vore Ponos server-side code
import re
from collections import namedtuple
from uuid import UUID
import yaml
from django.core.validators import URLValidator
......@@ -56,6 +57,10 @@ def validate_task(task, top_env):
if "artifact" in task:
assert isinstance(task["artifact"], str), "Task artifact should be a string"
try:
UUID(task["artifact"])
except (TypeError, ValueError):
raise AssertionError("Task artifact should be a valid UUID string")
if "requires_gpu" in task:
assert isinstance(
......
from textwrap import dedent
from django.test import TestCase
from ponos.recipe import parse_recipe
# List of (broken recipe, expected AssertionError message) tuples
ERROR_CASES = [
("[]", "Recipe should be a dict"),
("tasks: {}", "No tasks"),
("tasks: [{image: lol}]", "Tasks should be a dict"),
("tasks: {a: {}, '': {}}", "Tasks should have non-blank slugs"),
("tasks: {a: []}", "Task should be a dict"),
("tasks: {a: {}}", "Missing image"),
(
"""
tasks:
lol:
image: blah
artifact: 42
""",
"Task artifact should be a string",
),
(
"""
tasks:
lol:
image: blah
artifact: philosophers_stone
""",
"Task artifact should be a valid UUID string",
),
]
class TestRecipe(TestCase):
def test_recipe_errors(self):
for recipe, expected_message in ERROR_CASES:
with self.subTest(recipe=recipe), self.assertRaisesMessage(
AssertionError, expected_message
):
parse_recipe(dedent(recipe))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment