diff --git a/calculate/templates/template_processor.py b/calculate/templates/template_processor.py index e8289ce..16b3bc0 100644 --- a/calculate/templates/template_processor.py +++ b/calculate/templates/template_processor.py @@ -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 Подумать. diff --git a/tests/templates/test_template_executor.py b/tests/templates/test_template_executor.py index c4facf3..dc82da4 100644 --- a/tests/templates/test_template_executor.py +++ b/tests/templates/test_template_executor.py @@ -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')) diff --git a/tests/templates/testfiles/test_executor_root/etc.backup/append_join_file_testfiles/logo.png b/tests/templates/testfiles/test_executor_root/etc.backup/append_join_file_testfiles/logo.png new file mode 100644 index 0000000..c1de580 Binary files /dev/null and b/tests/templates/testfiles/test_executor_root/etc.backup/append_join_file_testfiles/logo.png differ