Skip to content

Commit ca50f1f

Browse files
committed
Harden extract_default_job_options_from_process_graph
related to #366 and Open-EO/openeo-aggregator#173
1 parent 205247b commit ca50f1f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

openeo_driver/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.126.0a1"
1+
__version__ = "0.126.1a1"

openeo_driver/processgraph.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import requests
66

7-
from openeo_driver.errors import OpenEOApiException
7+
from openeo_driver.errors import OpenEOApiException, ProcessGraphInvalidException
88
from openeo_driver.util.http import is_http_url
99

1010
_log = logging.getLogger(__name__)
@@ -142,6 +142,8 @@ def extract_default_job_options_from_process_graph(
142142

143143
job_options = []
144144
for node in process_graph.values():
145+
if not (isinstance(node, dict) and "process_id" in node and "arguments" in node):
146+
raise ProcessGraphInvalidException
145147
namespace = node.get("namespace")
146148
process_id = node["process_id"]
147149
if is_http_url(namespace):

tests/test_processgraph.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from openeo_driver.errors import OpenEOApiException
1+
from openeo_driver.errors import OpenEOApiException, ProcessGraphInvalidException
22
from openeo_driver.processgraph import (
33
get_process_definition_from_url,
44
extract_default_job_options_from_process_graph,
@@ -99,3 +99,15 @@ def test_extract_default_job_options_from_process_graph(requests_mock):
9999
assert extract_default_job_options_from_process_graph(pg, processing_mode="synchronous") == {
100100
"cpu": "green",
101101
}
102+
103+
104+
@pytest.mark.parametrize(
105+
"pg",
106+
[
107+
{"garbage": "yez"},
108+
{"almost": {"procezz_id": "add", "arguments": {"x": "nope"}}},
109+
],
110+
)
111+
def test_extract_default_job_options_from_process_graph_garbage(pg):
112+
with pytest.raises(ProcessGraphInvalidException):
113+
extract_default_job_options_from_process_graph(ProcessGraphFlatDict(pg))

0 commit comments

Comments
 (0)