summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.co.uk>2017-09-06 17:50:24 +0100
committerTristan Maat <tristan.maat@codethink.co.uk>2017-09-14 10:51:48 +0100
commitf0cf37a3fb3a7c9c5a405c63df09363a33f49577 (patch)
tree27e454431c856a9398d2fccf7f5fad52f0136b6c
parent06b4d3aeae88a30d922cd044feaf9f255946fe55 (diff)
downloadbuildstream-f0cf37a3fb3a7c9c5a405c63df09363a33f49577.tar.gz
Add element node validations
-rw-r--r--buildstream/_loader.py10
-rw-r--r--tests/loader/basics.py12
-rw-r--r--tests/loader/basics/onefile/elements/invalidkey.bst3
-rw-r--r--tests/loader/basics/onefile/elements/invalidsourcekey.bst6
4 files changed, 31 insertions, 0 deletions
diff --git a/buildstream/_loader.py b/buildstream/_loader.py
index 72b7ed3fd..a2e0b4f91 100644
--- a/buildstream/_loader.py
+++ b/buildstream/_loader.py
@@ -211,6 +211,14 @@ class LoadElement():
# These are shared with the owning Loader object
self.basedir = basedir
+ # Ensure the root node is valid
+ _yaml.validate_node(self.data, [
+ 'kind', 'depends', 'sources',
+ 'variables', 'environment',
+ 'config', 'public', 'description',
+ 'arches', 'variants', 'host-arches'
+ ])
+
# Process arch conditionals
resolve_arch(self.data, self.host_arch, self.target_arch)
@@ -370,6 +378,8 @@ def extract_depends_from_node(owner, data):
dependency = Dependency(owner, dep, filename=dep, provenance=dep_provenance)
elif isinstance(dep, Mapping):
+ _yaml.validate_node(dep, ['filename', 'type', 'variant'])
+
# Make variant optional, for this we set it to None after
variant = _yaml.node_get(dep, str, Symbol.VARIANT, default_value="")
if not variant:
diff --git a/tests/loader/basics.py b/tests/loader/basics.py
index 4830702df..ef2a2158a 100644
--- a/tests/loader/basics.py
+++ b/tests/loader/basics.py
@@ -72,3 +72,15 @@ def test_fail_fullpath_target(datafiles):
loader = Loader(basedir, fullpath, None, None, None, [])
assert (exc.value.reason == LoadErrorReason.INVALID_DATA)
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'onefile'))
+def test_invalid_key(datafiles):
+
+ basedir = os.path.join(datafiles.dirname, datafiles.basename)
+ loader = Loader(basedir, 'elements/invalidkey.bst', None, None, None, [])
+
+ with pytest.raises(LoadError) as exc:
+ element = loader.load()
+
+ assert (exc.value.reason == LoadErrorReason.INVALID_DATA)
diff --git a/tests/loader/basics/onefile/elements/invalidkey.bst b/tests/loader/basics/onefile/elements/invalidkey.bst
new file mode 100644
index 000000000..5674ab7bd
--- /dev/null
+++ b/tests/loader/basics/onefile/elements/invalidkey.bst
@@ -0,0 +1,3 @@
+kind: pony
+description: This is the pony
+wings: blue
diff --git a/tests/loader/basics/onefile/elements/invalidsourcekey.bst b/tests/loader/basics/onefile/elements/invalidsourcekey.bst
new file mode 100644
index 000000000..5677af347
--- /dev/null
+++ b/tests/loader/basics/onefile/elements/invalidsourcekey.bst
@@ -0,0 +1,6 @@
+kind: pony
+description: This is the pony
+sources:
+ - kind: ponyland
+ url: ptp://pw.ponies.p/
+ weather: great