summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-09-28 14:21:02 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-09-28 14:21:02 -0700
commit72fc1f762e5c5df563380e9ed90bfaba131e811b (patch)
tree2420fd4938324bedc739ec4e1573a4211a12a02f /tests
parent5233b6edb70702476463b47c06cb02b3c7f74c51 (diff)
parentd285a0463b6d16487eb5859373ccfd27eaec8b90 (diff)
downloadvyos-cloud-init-72fc1f762e5c5df563380e9ed90bfaba131e811b.tar.gz
vyos-cloud-init-72fc1f762e5c5df563380e9ed90bfaba131e811b.zip
Sync with head and fix conflicts.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_util.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 15fcbd26..96962b91 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -1,5 +1,6 @@
import os
import stat
+import yaml
from mocker import MockerTestCase
from unittest import TestCase
@@ -268,4 +269,42 @@ class TestGetCmdline(TestCase):
os.environ['DEBUG_PROC_CMDLINE'] = 'abcd 123'
self.assertEqual(os.environ['DEBUG_PROC_CMDLINE'], util.get_cmdline())
+
+class TestLoadYaml(TestCase):
+ mydefault = "7b03a8ebace993d806255121073fed52"
+
+ def test_simple(self):
+ mydata = {'1': "one", '2': "two"}
+ self.assertEqual(util.load_yaml(yaml.dump(mydata)), mydata)
+
+ def test_nonallowed_returns_default(self):
+ # for now, anything not in the allowed list just returns the default.
+ myyaml = yaml.dump({'1': "one"})
+ self.assertEqual(util.load_yaml(blob=myyaml,
+ default=self.mydefault,
+ allowed=(str,)),
+ self.mydefault)
+
+ def test_bogus_returns_default(self):
+ badyaml = "1\n 2:"
+ self.assertEqual(util.load_yaml(blob=badyaml,
+ default=self.mydefault),
+ self.mydefault)
+
+ def test_unsafe_types(self):
+ # should not load complex types
+ unsafe_yaml = yaml.dump((1, 2, 3,))
+ self.assertEqual(util.load_yaml(blob=unsafe_yaml,
+ default=self.mydefault),
+ self.mydefault)
+
+ def test_python_unicode(self):
+ # complex type of python/unicde is explicitly allowed
+ myobj = {'1': unicode("FOOBAR")}
+ safe_yaml = yaml.dump(myobj)
+ self.assertEqual(util.load_yaml(blob=safe_yaml,
+ default=self.mydefault),
+ myobj)
+
+
# vi: ts=4 expandtab