Adds support for all MIME Content-Transfer-Encodings

According to [1], Content-Transfer-Encoding can have one of the
following values (case insensitive): "BASE64" / "QUOTED-PRINTABLE" /
"8BIT"   / "7BIT" / "BINARY" / x-token.
Values "8bit", "7bit", and "binary" all imply that NO encoding has been
performed.
"x-token" refers to a custom implementation that can be done, where the
encoding agent and the decoding agent must agree upon. This case is not
addressed by the patch.
"QUOTED-PRINTABLE" and "base64" encodings are addressed by this patch,
and the decoding is performed for all the multipart content types
currently supported.

[1]https://www.w3.org/Protocols/rfc1341/5_Content-Transfer-Encoding.html

Change-Id: Iac29f3a287bd478f7f0b55d9911ae47f3a5890fb
Closes-Bug: #1696420
This commit is contained in:
Paula Madalina Crismaru 2017-06-13 14:25:45 +03:00
parent 68a9ae57d4
commit 2a5cd3a412
6 changed files with 7 additions and 7 deletions

View File

@ -134,7 +134,7 @@ class UserDataPlugin(base.BasePlugin):
LOG.debug("Calling user part handler for content type: %s" %
content_type)
handler_func(None, content_type, part.get_filename(),
part.get_payload())
part.get_payload(decode=True))
else:
user_data_plugin = user_data_plugins.get(content_type)
if not user_data_plugin:

View File

@ -105,5 +105,5 @@ class CloudConfigPlugin(base.BaseUserDataPlugin):
return executor.execute()
def process(self, part):
payload = part.get_payload()
payload = part.get_payload(decode=True)
return self.process_non_multipart(payload)

View File

@ -40,10 +40,10 @@ class HeatPlugin(base.BaseUserDataPlugin):
file_name = os.path.join(CONF.heat_config_dir, part.get_filename())
self._check_dir(file_name)
encoding.write_file(file_name, part.get_payload())
payload = part.get_payload(decode=True)
encoding.write_file(file_name, payload)
if part.get_filename() == self._heat_user_data_filename:
payload = part.get_payload()
# Normalize the payload to bytes, since `execute_user_data_script`
# operates on bytes and `get_payload` returns a string on
# Python 3.

View File

@ -29,7 +29,7 @@ class PartHandlerPlugin(base.BaseUserDataPlugin):
def process(self, part):
temp_dir = tempfile.gettempdir()
part_handler_path = os.path.join(temp_dir, part.get_filename())
encoding.write_file(part_handler_path, part.get_payload())
encoding.write_file(part_handler_path, part.get_payload(decode=True))
part_handler = classloader.ClassLoader().load_module(part_handler_path)

View File

@ -36,7 +36,7 @@ class ShellScriptPlugin(base.BaseUserDataPlugin):
target_path = os.path.join(tempfile.gettempdir(), file_name)
try:
encoding.write_file(target_path, part.get_payload())
encoding.write_file(target_path, part.get_payload(decode=True))
return fileexecutils.exec_file(target_path)
except Exception as ex:

View File

@ -63,7 +63,7 @@ class ShellScriptPluginTests(unittest.TestCase):
mock_write_file.assert_called_once_with(
fake_target, mock_part.get_payload.return_value)
mock_exec_file.assert_called_once_with(fake_target)
mock_part.get_payload.assert_called_once_with()
mock_part.get_payload.assert_called_once_with(decode=True)
mock_gettempdir.assert_called_once_with()
if not exception:
self.assertEqual('fake response', response)