summaryrefslogtreecommitdiff
path: root/tests/unittests/test_data.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2018-06-13 12:54:43 -0400
committerScott Moser <smoser@brickies.net>2018-06-13 12:54:43 -0400
commitfaa6f07e9de4058083a5f69ed508b6e24bd53b23 (patch)
treeadbe18f27c27fc01d1744633a09745810802b694 /tests/unittests/test_data.py
parent171378613ef4de3c1bb4170a10ec1748ac62f39f (diff)
downloadvyos-cloud-init-faa6f07e9de4058083a5f69ed508b6e24bd53b23.tar.gz
vyos-cloud-init-faa6f07e9de4058083a5f69ed508b6e24bd53b23.zip
Be more safe on string/bytes when writing multipart user-data to disk.
When creating the multipart mime message that is written as user-data.txt.i, cloud-init losing data on conversion to some things as a string. LP: #1768600 Author: Scott Moser <smoser@ubuntu.com> Co-Authored-By: Chad Smith <chad.smith@canonical.com>
Diffstat (limited to 'tests/unittests/test_data.py')
-rw-r--r--tests/unittests/test_data.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/unittests/test_data.py b/tests/unittests/test_data.py
index 91d35cb8..3efe7adf 100644
--- a/tests/unittests/test_data.py
+++ b/tests/unittests/test_data.py
@@ -606,8 +606,10 @@ class TestUDProcess(helpers.ResourceUsingTestCase):
class TestConvertString(helpers.TestCase):
+
def test_handles_binary_non_utf8_decodable(self):
- blob = b'\x32\x99'
+ """Printable unicode (not utf8-decodable) is safely converted."""
+ blob = b'#!/bin/bash\necho \xc3\x84\n'
msg = ud.convert_string(blob)
self.assertEqual(blob, msg.get_payload(decode=True))
@@ -621,6 +623,13 @@ class TestConvertString(helpers.TestCase):
msg = ud.convert_string(text)
self.assertEqual(text, msg.get_payload(decode=False))
+ def test_handle_mime_parts(self):
+ """Mime parts are properly returned as a mime message."""
+ message = MIMEBase("text", "plain")
+ message.set_payload("Just text")
+ msg = ud.convert_string(str(message))
+ self.assertEqual("Just text", msg.get_payload(decode=False))
+
class TestFetchBaseConfig(helpers.TestCase):
def test_only_builtin_gets_builtin(self):