diff options
author | Scott Moser <smoser@ubuntu.com> | 2016-06-22 10:08:29 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2016-06-22 10:08:29 -0400 |
commit | 9f7ce5f090689b664ffce7e0b4ac78bfeafd1a79 (patch) | |
tree | 9831898dbfe7767d750227bd5d748713260f1586 /tests/unittests | |
parent | a919f6e6ee3bfaf489411a4452fc708061b1239f (diff) | |
parent | 7a39cb35f54be3d91ab0985a96fcb3663f20124c (diff) | |
download | vyos-cloud-init-9f7ce5f090689b664ffce7e0b4ac78bfeafd1a79.tar.gz vyos-cloud-init-9f7ce5f090689b664ffce7e0b4ac78bfeafd1a79.zip |
user_data: fix error when user-data is not utf-8 decodable
when user-data was not decodable, cloud-init would raise exception.
This also changes the signature of user_data.convert_string.
The 'headers' argument was never used, and woudl have been broken
if it was, as it was expected to be a dictionary but then was
passed in with *headers.
LP: #1532072
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_data.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/unittests/test_data.py b/tests/unittests/test_data.py index 1923e2af..13db8a4c 100644 --- a/tests/unittests/test_data.py +++ b/tests/unittests/test_data.py @@ -557,3 +557,20 @@ class TestUDProcess(helpers.ResourceUsingTestCase): ud_proc = ud.UserDataProcessor(self.getCloudPaths()) message = ud_proc.process(msg) self.assertTrue(count_messages(message) == 1) + + +class TestConvertString(helpers.TestCase): + def test_handles_binary_non_utf8_decodable(self): + blob = b'\x32\x99' + msg = ud.convert_string(blob) + self.assertEqual(blob, msg.get_payload(decode=True)) + + def test_handles_binary_utf8_decodable(self): + blob = b'\x32\x32' + msg = ud.convert_string(blob) + self.assertEqual(blob, msg.get_payload(decode=True)) + + def test_handle_headers(self): + text = "hi mom" + msg = ud.convert_string(text) + self.assertEqual(text, msg.get_payload(decode=False)) |