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-07 15:02:10 +0100
commit94570a3c4338d344e9d3ca0759c61a6b2d3ba1c1 (patch)
tree0feb2621e1bfafd679c92613e272afdb83b6ed7c
parent2f545d57b982d97638951bca7facb45f43f63169 (diff)
downloadbuildstream-94570a3c4338d344e9d3ca0759c61a6b2d3ba1c1.tar.gz
Add element node validations
-rw-r--r--buildstream/_loader.py9
-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, 30 insertions, 0 deletions
diff --git a/buildstream/_loader.py b/buildstream/_loader.py
index 72b7ed3fd..b7a1ccb26 100644
--- a/buildstream/_loader.py
+++ b/buildstream/_loader.py
@@ -211,6 +211,15 @@ 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',
+ 'choice'
+ ])
+
# Process arch conditionals
resolve_arch(self.data, self.host_arch, self.target_arch)
diff --git a/tests/loader/basics.py b/tests/loader/basics.py
index 4830702df..99f5edbd7 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_YAML)
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