Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/taskgraph/util/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,14 @@ def verify_routes_notification_filters(
)


# https://docs.taskcluster.net/docs/reference/core/index#valid-characters
INDEX_NAMESPACE_RE = re.compile(r"^([a-zA-Z0-9_!~*'()%-]+\.)*[a-zA-Z0-9_!~*'()%-]+$")


@verifications.add("full_task_graph")
def verify_index_route(task, taskgraph, scratch_pad, graph_config, parameters):
"""
This function ensures that routes do not contain forward slashes.
This function ensures that index routes would create valid taskcluster index paths
"""
if task is None:
return
Expand All @@ -247,11 +251,13 @@ def verify_index_route(task, taskgraph, scratch_pad, graph_config, parameters):
route_prefix = "index."

for route in routes:
# Check for invalid / in the index route
if route.startswith(route_prefix) and "/" in route:
raise Exception(
f"{task.label} has invalid route with forward slash: {route}"
)
if route.startswith(route_prefix):
namespace = route[len(route_prefix) :]
if not INDEX_NAMESPACE_RE.match(namespace):
raise Exception(
f"{task.label} has invalid index route namespace: {route}. "
f"Namespace must match {INDEX_NAMESPACE_RE.pattern}"
)


@verifications.add("full_task_graph")
Expand Down
33 changes: 33 additions & 0 deletions test/test_util_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ def make_task_treeherder(label, symbol, platform="linux/opt"):
pytest.raises(DeprecationWarning),
id="routes_notfication_filter: deprecated",
),
pytest.param(
"verify_index_route",
make_graph(
make_task(
"valid_route",
task_def={"routes": ["index.example.v2.latest.taskgraph.decision"]},
),
),
does_not_raise(),
id="verify_index_route: valid route",
),
pytest.param(
"verify_index_route",
make_graph(
Expand All @@ -226,6 +237,28 @@ def make_task_treeherder(label, symbol, platform="linux/opt"):
pytest.raises(Exception),
id="verify_index_route: invalid slash in route",
),
pytest.param(
"verify_index_route",
make_graph(
make_task(
"invalid_plus",
task_def={"routes": ["index.example.1.0+hotfix1.latest"]},
),
),
pytest.raises(Exception),
id="verify_index_route: invalid plus in route",
),
pytest.param(
"verify_index_route",
make_graph(
make_task(
"invalid_space",
task_def={"routes": ["index.example.some namespace.latest"]},
),
),
pytest.raises(Exception),
id="verify_index_route: invalid space in route",
),
pytest.param(
"verify_task_dependencies",
make_graph(
Expand Down
Loading