Added check if an input file is a binary while joining templates. fixed #16

master
Иванов Денис 3 years ago
parent 19513d4891
commit 2ef9da05f7

@ -1028,8 +1028,12 @@ class TemplateExecutor:
or os.path.exists(input_path)):
# Если входной файл просто не из архива, или из архива
# и при этом существует -- используем его
with open(input_path, 'r') as input_file:
input_text = input_file.read()
try:
with open(input_path, 'r') as input_file:
input_text = input_file.read()
except UnicodeDecodeError:
raise TemplateExecutorError(
"can not join binary files.")
else:
# В противном случае используем пустой файл.
# TODO Подумать.

@ -3042,6 +3042,27 @@ AttributeError: module 'os' has no attribute 'suspicious_attribute'
out_text = out_file.read()
assert out_text == expected_output
def test_error_while_using_not_text_file_as_input_file_for_append_join(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_join_file_testfiles/file_19')
source_path = join_paths(CHROOT_PATH,
'/etc/append_join_file_testfiles/logo.png')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'source': source_path,
'format': 'raw'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
'/path/to/template',
template_text='',
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
with pytest.raises(TemplateExecutorError):
template_executor._append_join_file(template_wrapper)
def test_to_remove_changed_testfiles(self):
shutil.rmtree(os.path.join(CHROOT_PATH, 'etc'))
shutil.rmtree(os.path.join(CHROOT_PATH, 'unprotected'))

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Loading…
Cancel
Save