diff --git a/doc/source/building_images/build_expandable_disk.rst b/doc/source/building_images/build_expandable_disk.rst index 2e8dd5f2de1..49617fafb7f 100644 --- a/doc/source/building_images/build_expandable_disk.rst +++ b/doc/source/building_images/build_expandable_disk.rst @@ -183,18 +183,18 @@ a target system: scp pxeboot.{exc_image_base_name_disk}.x86_64-{exc_image_version}.initrd PXE_SERVER_IP:/srv/tftpboot/boot/initrd scp pxeboot.{exc_image_base_name_disk}.x86_64-{exc_image_version}.kernel PXE_SERVER_IP:/srv/tftpboot/boot/linux -3. Copy the disk image, MD5 file, system kernel, initrd and bootoptions to +3. Copy the disk image, SHA256 file, system kernel, initrd and bootoptions to the PXE boot server. Activation of the deployed system is done via `kexec` of the kernel and initrd provided here. - a) Copy system image and MD5 checksum: + a) Copy system image and SHA256 checksum: .. code:: bash scp {exc_image_base_name_disk}.x86_64-{exc_image_version}.xz PXE_SERVER_IP:/srv/tftpboot/image/ - scp {exc_image_base_name_disk}.x86_64-{exc_image_version}.md5 PXE_SERVER_IP:/srv/tftpboot/image/ + scp {exc_image_base_name_disk}.x86_64-{exc_image_version}.sha256 PXE_SERVER_IP:/srv/tftpboot/image/ b) Copy kernel, initrd and bootoptions used for booting the system via kexec: @@ -224,7 +224,7 @@ a target system: The location of the image is specified as a source URI that can point to any location supported by the `curl` command. {kiwi} uses `curl` to fetch - the data from this URI. This means that the image, MD5 file, system kernel + the data from this URI. This means that the image, checksum file, system kernel and initrd can be fetched from any server, and they do not need to be stored on the `PXE_SERVER`. @@ -425,4 +425,4 @@ The `initrd` child element of `installmedia` lists dracut modules. The element's `action` attribute determines whether the dracut module is omitted (`action="omit"`) or added (`action="add"`). Use `action="set"` to use only the listed modules and nothing else (that is, none of the dracut modules included by -default). \ No newline at end of file +default). diff --git a/doc/source/working_with_images/legacy_netboot_root_filesystem.rst b/doc/source/working_with_images/legacy_netboot_root_filesystem.rst index 0d144a6967b..e7862f9de84 100644 --- a/doc/source/working_with_images/legacy_netboot_root_filesystem.rst +++ b/doc/source/working_with_images/legacy_netboot_root_filesystem.rst @@ -90,12 +90,12 @@ system. As diskless client, a QEMU virtual machine is used. $ cp *.initrd /srv/tftpboot/boot/initrd $ cp *.kernel /srv/tftpboot/boot/linux -5. Copy the system image and its MD5 sum to :file:`/srv/tftpboot/image`: +5. Copy the system image and its SHA256 sum to :file:`/srv/tftpboot/image`: .. code:: bash $ cp {exc_image_base_name_pxe}.x86_64-{exc_image_version} /srv/tftpboot/image - $ cp {exc_image_base_name_pxe}.x86_64-{exc_image_version}.md5 /srv/tftpboot/image + $ cp {exc_image_base_name_pxe}.x86_64-{exc_image_version}.sha256 /srv/tftpboot/image 6. Adjust the PXE configuration file. The configuration file controls which kernel and initrd is @@ -317,7 +317,7 @@ CONF, the following setup is required: RELOAD_CONFIG=1 By default only configuration files which has changed according to -their md5sum value will be reloaded. With the above setup all files +their checksum value will be reloaded. With the above setup all files will be reloaded from the PXE server. The option only applies to configurations with a DISK/PART setup diff --git a/dracut/modules.d/90kiwi-dump/kiwi-dump-image.sh b/dracut/modules.d/90kiwi-dump/kiwi-dump-image.sh index 5c648f94ec3..06d48a8b533 100755 --- a/dracut/modules.d/90kiwi-dump/kiwi-dump-image.sh +++ b/dracut/modules.d/90kiwi-dump/kiwi-dump-image.sh @@ -305,7 +305,7 @@ function check_image_integrity { local progress=/dev/install_verify_progress local verify_text="Verifying ${image_target}" local title_text="Installation..." - local verify_result=/dumped_image.md5 + local verify_result=/dumped_image.sha256 kiwi_oemskipverify=$(bool "${kiwi_oemskipverify}") kiwi_oemsilentverify=$(bool "${kiwi_oemsilentverify}") if [ "${kiwi_oemskipverify}" = "true" ];then @@ -318,13 +318,13 @@ function check_image_integrity { setup_progress_fifo ${progress} ( pv --size $((blocks * blocksize)) --stop-at-size \ - -n "${image_target}" | md5sum - > ${verify_result} + -n "${image_target}" | sha256sum - > ${verify_result} ) 2>${progress} & run_progress_dialog "${verify_text}" "${title_text}" else # verify with silently blocked console head --bytes=$((blocks * blocksize)) "${image_target}" |\ - md5sum - > ${verify_result} + sha256sum - > ${verify_result} fi local checksum_dumped_image local checksum_fileref @@ -341,7 +341,7 @@ function get_local_image_source_files { local iso_mount_point=/run/install local image_mount_point=/run/image local image_source - local image_md5 + local image_sha256 mkdir -m 0755 -p "${iso_mount_point}" if ! mount -n "${iso_device}" "${iso_mount_point}"; then report_and_quit "Failed to mount install ISO device" @@ -351,14 +351,14 @@ function get_local_image_source_files { report_and_quit "Failed to mount install image squashfs filesystem" fi image_source="$(echo "${image_mount_point}"/*.raw)" - image_md5="$(echo "${image_mount_point}"/*.md5)" - echo "${image_source}|${image_md5}" + image_sha256="$(echo "${image_mount_point}"/*.sha256)" + echo "${image_source}|${image_sha256}" } function get_remote_image_source_files { local image_uri local install_dir=/run/install - local image_md5="${install_dir}/image.md5" + local image_sha256="${install_dir}/image.sha256" local metadata_dir="${install_dir}/boot/remote/loader" mkdir -p "${metadata_dir}" @@ -367,8 +367,8 @@ function get_remote_image_source_files { # make sure the protocol type is tftp for metadata files. There is no need for # complex protocol types on small files and for standard PXE boot operations # only tftp can be guaranteed - image_md5_uri=$( - echo "${image_uri}" | awk '{ gsub("\\.xz",".md5", $1); gsub("dolly:","tftp:", $1); print $1 }' + image_sha256_uri=$( + echo "${image_uri}" | awk '{ gsub("\\.xz",".sha256", $1); gsub("dolly:","tftp:", $1); print $1 }' ) image_initrd_uri=$( echo "${image_uri}" | awk '{ gsub("\\.xz",".initrd", $1); gsub("dolly:","tftp:", $1); print $1 }' @@ -381,15 +381,15 @@ function get_remote_image_source_files { awk '{ gsub("\\.xz",".config.bootoptions", $1); gsub("dolly:","tftp:", $1); print $1 }' ) - # if we can not access image_md5_uri, maybe network setup + # if we can not access image_sha256_uri, maybe network setup # by dracut did fail, so collect some additional info - if ! fetch_file "${image_md5_uri}" > "${image_md5}";then + if ! fetch_file "${image_sha256_uri}" > "${image_sha256}";then { echo "--- ip a ---"; ip a echo "--- ip r ---"; ip r } >> /tmp/fetch.info 2>&1 show_log_and_quit \ - "Failed to fetch ${image_md5_uri}" /tmp/fetch.info + "Failed to fetch ${image_sha256_uri}" /tmp/fetch.info fi if ! fetch_file "${image_kernel_uri}" > "${metadata_dir}/linux";then @@ -409,7 +409,7 @@ function get_remote_image_source_files { "Failed to fetch ${image_config_uri}" /tmp/fetch.info fi - echo "${image_uri}|${image_md5}" + echo "${image_uri}|${image_sha256}" } #====================================== diff --git a/dracut/modules.d/90kiwi-dump/module-setup.sh b/dracut/modules.d/90kiwi-dump/module-setup.sh index 1dd8e5135ad..7d6bf3ea840 100755 --- a/dracut/modules.d/90kiwi-dump/module-setup.sh +++ b/dracut/modules.d/90kiwi-dump/module-setup.sh @@ -21,7 +21,7 @@ install() { declare moddir=${moddir} declare systemdutildir=${systemdutildir} inst_multiple \ - tr lsblk dd md5sum head pv kexec basename awk kpartx + tr lsblk dd sha256sum head pv kexec basename awk kpartx inst_hook pre-udev 30 "${moddir}/kiwi-installer-genrules.sh" diff --git a/kiwi/builder/container.py b/kiwi/builder/container.py index 1f6d67b41d4..1e74cda798d 100644 --- a/kiwi/builder/container.py +++ b/kiwi/builder/container.py @@ -55,7 +55,7 @@ def __init__( self.requested_container_type = xml_state.get_build_type_name() self.delta_root = xml_state.build_type.get_delta_root() self.base_image = None - self.base_image_md5 = None + self.base_image_sha256 = None self.ensure_empty_tmpdirs = True self.container_config['xz_options'] = \ @@ -67,11 +67,11 @@ def __init__( if xml_state.get_derived_from_image_uri() and not self.delta_root: # The base image(all derived imports) is expected to be unpacked # by the kiwi prepare step and stored inside of the root_dir/image - # directory. In addition a md5 file of the image is expected too + # directory. In addition a sha256 file of the image is expected too self.base_image = Defaults.get_imported_root_image( self.root_dir ) - self.base_image_md5 = ''.join([self.base_image, '.md5']) + self.base_image_sha256 = ''.join([self.base_image, '.sha256']) if not os.path.exists(self.base_image): raise KiwiContainerBuilderError( @@ -79,10 +79,10 @@ def __init__( self.base_image ) ) - if not os.path.exists(self.base_image_md5): + if not os.path.exists(self.base_image_sha256): raise KiwiContainerBuilderError( - 'Base image MD5 sum {0} not found at'.format( - self.base_image_md5 + 'Base image SHA256 sum {0} not found at'.format( + self.base_image_sha256 ) ) @@ -131,7 +131,7 @@ def create(self) -> Result: container_setup.setup() else: checksum = Checksum(self.base_image) - if not checksum.matches(checksum.md5(), self.base_image_md5): + if not checksum.matches(checksum.sha256(), self.base_image_sha256): raise KiwiContainerBuilderError( 'base image file {0} checksum validation failed'.format( self.base_image diff --git a/kiwi/builder/install.py b/kiwi/builder/install.py index 40adc305a6d..81c81b229a8 100644 --- a/kiwi/builder/install.py +++ b/kiwi/builder/install.py @@ -119,8 +119,8 @@ def __init__( self.squashed_diskname = ''.join( [xml_state.xml_data.get_name(), '.raw'] ) - self.md5name = ''.join( - [xml_state.xml_data.get_name(), '.md5'] + self.sha256name = ''.join( + [xml_state.xml_data.get_name(), '.sha256'] ) self.xz_options = custom_args['xz_options'] if custom_args \ and 'xz_options' in custom_args else None @@ -174,7 +174,7 @@ def create_install_iso(self) -> None: prefix='kiwi_install_squashfs.', path=self.target_dir ).new_dir() checksum = Checksum(self.diskname) - checksum.md5(self.squashed_contents.name + '/' + self.md5name) + checksum.sha256(self.squashed_contents.name + '/' + self.sha256name) # the system image name is stored in a config file self._write_install_image_info_to_iso_image() @@ -291,14 +291,14 @@ def create_install_pxe_archive(self) -> None: # the system image transfer is checked against a checksum log.info('Creating disk image checksum') - pxe_md5_filename = ''.join( + pxe_sha256_filename = ''.join( [ self.pxe_dir.name, '/', - self.pxename, '.md5' + self.pxename, '.sha256' ] ) checksum = Checksum(self.diskname) - checksum.md5(pxe_md5_filename) + checksum.sha256(pxe_sha256_filename) # the install image name is stored in a config file if self.initrd_system == 'kiwi': diff --git a/kiwi/builder/kis.py b/kiwi/builder/kis.py index e02ae6555cb..ba6436c84c1 100644 --- a/kiwi/builder/kis.py +++ b/kiwi/builder/kis.py @@ -88,7 +88,7 @@ def __init__( self.image: str = '' self.append_file = ''.join([self.image_name, '.append']) self.archive_name = ''.join([self.image_name, '.tar']) - self.checksum_name = ''.join([self.image_name, '.md5']) + self.checksum_name = ''.join([self.image_name, '.sha256']) self.kernel_filename: str = '' self.hypervisor_filename: str = '' self.result = Result(xml_state) @@ -126,9 +126,9 @@ def create(self) -> Result: compress = Compress(self.image) self.image = compress.xz(self.xz_options) - log.info('Creating root filesystem MD5 checksum') + log.info('Creating root filesystem SHA256 checksum') checksum = Checksum(self.image) - checksum.md5(self.checksum_name) + checksum.sha256(self.checksum_name) # prepare initrd if self.boot_image_task.has_initrd_support(): diff --git a/kiwi/config/strip.xml b/kiwi/config/strip.xml index 025cc59b63e..a95a4eed5a3 100644 --- a/kiwi/config/strip.xml +++ b/kiwi/config/strip.xml @@ -179,7 +179,6 @@ - diff --git a/kiwi/schema/kiwi.rnc b/kiwi/schema/kiwi.rnc index 80db9bcde6c..9fcf499519b 100644 --- a/kiwi/schema/kiwi.rnc +++ b/kiwi/schema/kiwi.rnc @@ -713,7 +713,7 @@ div { k.oem-skip-verify.content = xsd:boolean k.oem-skip-verify.attlist = empty k.oem-skip-verify = - ## For oemboot driven images: do not perform the md5 + ## For oemboot driven images: do not perform the checksum ## verification process, true/false element oem-skip-verify { k.oem-skip-verify.attlist, @@ -1130,7 +1130,7 @@ div { ## Alias name to be used for this repository. This is an ## optional free-form text restricted to characters from the ## POSIX standard. If not set the source attribute - ## value is used and builds the alias name by running a md5 digest + ## value is used and builds the alias name by running a checksum digest ## of the defined URI of the repository. An alias name should be ## set if the source argument doesn't really explain what this ## repository contains. diff --git a/kiwi/schema/kiwi.rng b/kiwi/schema/kiwi.rng index ecb9bb46521..60618ccad37 100644 --- a/kiwi/schema/kiwi.rng +++ b/kiwi/schema/kiwi.rng @@ -1115,7 +1115,7 @@ dump process, true/false - For oemboot driven images: do not perform the md5 + For oemboot driven images: do not perform the checksum verification process, true/false @@ -1740,7 +1740,7 @@ loading of the container at first boot Alias name to be used for this repository. This is an optional free-form text restricted to characters from the POSIX standard. If not set the source attribute -value is used and builds the alias name by running a md5 digest +value is used and builds the alias name by running a checksum digest of the defined URI of the repository. An alias name should be set if the source argument doesn't really explain what this repository contains. diff --git a/kiwi/system/root_import/base.py b/kiwi/system/root_import/base.py index 738a4996105..65ea77dbd04 100644 --- a/kiwi/system/root_import/base.py +++ b/kiwi/system/root_import/base.py @@ -186,4 +186,4 @@ def sync_data(self): def _make_checksum(self, image): checksum = Checksum(image) - checksum.md5(''.join([image, '.md5'])) + checksum.sha256(''.join([image, '.sha256'])) diff --git a/kiwi/utils/checksum.py b/kiwi/utils/checksum.py index 3ba2f32ded9..21e52d85ff1 100644 --- a/kiwi/utils/checksum.py +++ b/kiwi/utils/checksum.py @@ -21,6 +21,7 @@ import encodings.ascii as encoding # project +from kiwi.api_helper import decommissioned from kiwi.utils.compress import Compress from kiwi.utils.primes import factors @@ -70,24 +71,9 @@ def matches(self, checksum, filename): return True return False + @decommissioned def md5(self, filename=None): - """ - Create md5 checksum - - :param str filename: filename for checksum - - :return: checksum - - :rtype: str - """ - md5_checksum = self._calculate_hash_hexdigest( - hashlib.md5(), self.source_filename - ) - if filename: - self._create_checksum_file( - md5_checksum, filename - ) - return md5_checksum + pass # pragma: no cover def sha256(self, filename=None): """ @@ -122,7 +108,7 @@ def _create_checksum_file(self, checksum, filename): os.path.getsize(compress.uncompressed_filename) ) checksum = self._calculate_hash_hexdigest( - hashlib.md5(), compress.uncompressed_filename + hashlib.sha256(), compress.uncompressed_filename ) else: blocks = self._block_list( diff --git a/test/unit/builder/container_test.py b/test/unit/builder/container_test.py index c93c2470b6c..8fab8ff514e 100644 --- a/test/unit/builder/container_test.py +++ b/test/unit/builder/container_test.py @@ -81,7 +81,7 @@ def test_init_derived_base_image_not_existing(self, mock_exists): ) @patch('os.path.exists') - def test_init_derived_base_image_md5_not_existing(self, mock_exists): + def test_init_derived_base_image_sha256_not_existing(self, mock_exists): exists_results = [False, False, True] def side_effect(self): @@ -210,7 +210,7 @@ def side_effect(filename): container.result = mock.Mock() checksum = mock.Mock() - checksum.md5 = mock.Mock( + checksum.sha256 = mock.Mock( return_value='checksumvalue' ) mock_checksum.return_value = checksum @@ -223,7 +223,7 @@ def side_effect(filename): mock_checksum.assert_called_once_with('root_dir/image/imported_root') checksum.matches.assert_called_once_with( - 'checksumvalue', 'root_dir/image/imported_root.md5' + 'checksumvalue', 'root_dir/image/imported_root.sha256' ) mock_image.new.assert_called_once_with( @@ -272,10 +272,10 @@ def side_effect(filename): ) @patch('kiwi.builder.container.Checksum') - def test_create_derived_with_different_md5(self, mock_md5): - md5 = mock.Mock() - md5.md5.return_value = 'diffchecksumvalue' - mock_md5.return_value = md5 + def test_create_derived_with_different_sha256(self, mock_sha256): + sha256 = mock.Mock() + sha256.sha256.return_value = 'diffchecksumvalue' + mock_sha256.return_value = sha256 m_open = mock_open(read_data='checksum data\n') with patch('builtins.open', m_open, create=True): @@ -286,7 +286,7 @@ def test_create_derived_with_different_md5(self, mock_md5): container.create() @patch('kiwi.builder.container.Checksum') - def test_create_derived_fail_open(self, mock_md5): + def test_create_derived_fail_open(self, mock_sha256): with patch('builtins.open') as m_open: m_open = mock_open() m_open.return_value.__enter__.side_effect = Exception( diff --git a/test/unit/builder/install_test.py b/test/unit/builder/install_test.py index a4351de4099..750a8e47313 100644 --- a/test/unit/builder/install_test.py +++ b/test/unit/builder/install_test.py @@ -163,8 +163,8 @@ def side_effect(prefix, path): self.setup.import_cdroot_files.assert_called_once_with('temp_media_dir') - self.checksum.md5.assert_called_once_with( - 'temp-squashfs/result-image.md5' + self.checksum.sha256.assert_called_once_with( + 'temp-squashfs/result-image.sha256' ) mock_copy.assert_called_once_with( 'root_dir/boot/initrd-kernel_version', @@ -296,7 +296,7 @@ def test_create_install_iso_no_hypervisor_found( @patch('kiwi.builder.install.Checksum') @patch('kiwi.builder.install.Compress') def test_create_install_pxe_no_kernel_found( - self, mock_compress, mock_md5, mock_command, mock_Temporary + self, mock_compress, mock_sha256, mock_command, mock_Temporary ): self.firmware.bios_mode.return_value = False mock_Temporary.return_value.new_dir.return_value.name = 'tmpdir' @@ -311,7 +311,7 @@ def test_create_install_pxe_no_kernel_found( @patch('kiwi.builder.install.Compress') @patch('kiwi.builder.install.os.symlink') def test_create_install_pxe_no_hypervisor_found( - self, mock_symlink, mock_compress, mock_md5, mock_command, + self, mock_symlink, mock_compress, mock_sha256, mock_command, mock_Temporary ): self.firmware.bios_mode.return_value = False @@ -331,7 +331,7 @@ def test_create_install_pxe_no_hypervisor_found( @patch('kiwi.builder.install.os.chmod') def test_create_install_pxe_archive( self, mock_chmod, mock_symlink, mock_copy, mock_compress, - mock_md5, mock_archive, mock_command, mock_Temporary + mock_sha256, mock_archive, mock_command, mock_Temporary ): mock_Temporary.return_value.new_dir.return_value.name = 'tmpdir' @@ -339,7 +339,7 @@ def test_create_install_pxe_archive( mock_archive.return_value = archive checksum = mock.Mock() - mock_md5.return_value = checksum + mock_sha256.return_value = checksum compress = mock.Mock() src = 'target_dir/result-image.x86_64-1.2.3.raw' @@ -357,11 +357,11 @@ def test_create_install_pxe_archive( assert mock_command.call_args_list[0] == call( ['mv', src, 'tmpdir/result-image.x86_64-1.2.3.xz'] ) - mock_md5.assert_called_once_with( + mock_sha256.assert_called_once_with( 'target_dir/result-image.x86_64-1.2.3.raw' ) - checksum.md5.assert_called_once_with( - 'tmpdir/result-image.x86_64-1.2.3.md5' + checksum.sha256.assert_called_once_with( + 'tmpdir/result-image.x86_64-1.2.3.sha256' ) assert m_open.call_args_list == [ call('initrd_dir/config.vmxsystem', 'w'), diff --git a/test/unit/builder/kis_test.py b/test/unit/builder/kis_test.py index 28a164fc180..0cd031591df 100644 --- a/test/unit/builder/kis_test.py +++ b/test/unit/builder/kis_test.py @@ -127,8 +127,8 @@ def test_create( 'myimage.fs', 'myimage' ) compress.xz.assert_called_once_with(None) - checksum.md5.assert_called_once_with( - 'target_dir/some-image.x86_64-1.2.3.md5' + checksum.sha256.assert_called_once_with( + 'target_dir/some-image.x86_64-1.2.3.sha256' ) self.boot_image_task.prepare.assert_called_once_with() self.setup.export_modprobe_setup.assert_called_once_with( diff --git a/test/unit/system/root_import/oci_test.py b/test/unit/system/root_import/oci_test.py index 25fb9b22b4d..50b87770f90 100644 --- a/test/unit/system/root_import/oci_test.py +++ b/test/unit/system/root_import/oci_test.py @@ -44,10 +44,10 @@ def test_failed_init(self, mock_path): @patch('kiwi.system.root_import.base.Checksum') @patch('kiwi.system.root_import.oci.Path.create') @patch('kiwi.system.root_import.oci.OCI') - def test_sync_data(self, mock_OCI, mock_path, mock_md5, mock_compress): + def test_sync_data(self, mock_OCI, mock_path, mock_sha256, mock_compress): oci = Mock() mock_OCI.new.return_value.__enter__.return_value = oci - mock_md5.return_value = Mock() + mock_sha256.return_value = Mock() uncompress = Mock() uncompress.get_format = Mock(return_value=None) @@ -61,7 +61,7 @@ def test_sync_data(self, mock_OCI, mock_path, mock_md5, mock_compress): oci.import_rootfs.assert_called_once_with( 'root_dir' ) - mock_md5.assert_called_once_with('root_dir/image/imported_root') + mock_sha256.assert_called_once_with('root_dir/image/imported_root') uncompress.get_format.assert_called_once_with() @patch('kiwi.system.root_import.oci.Compress') @@ -102,11 +102,11 @@ def test_overlay_data( @patch('kiwi.system.root_import.oci.Path.create') @patch('kiwi.system.root_import.oci.OCI') def test_sync_data_compressed_image( - self, mock_OCI, mock_path, mock_md5, mock_compress + self, mock_OCI, mock_path, mock_sha256, mock_compress ): oci = Mock() mock_OCI.new.return_value.__enter__.return_value = oci - mock_md5.return_value = Mock() + mock_sha256.return_value = Mock() uncompress = Mock() uncompress.get_format = Mock(return_value='xz') @@ -120,7 +120,7 @@ def test_sync_data_compressed_image( oci.import_rootfs.assert_called_once_with( 'root_dir' ) - mock_md5.assert_called_once_with('root_dir/image/imported_root') + mock_sha256.assert_called_once_with('root_dir/image/imported_root') uncompress.get_format.assert_called_once_with() uncompress.uncompress.assert_called_once_with(True) @@ -129,12 +129,12 @@ def test_sync_data_compressed_image( @patch('kiwi.system.root_import.oci.Path.create') @patch('kiwi.system.root_import.oci.OCI') def test_sync_data_unknown_uri( - self, mock_OCI, mock_path, mock_md5, mock_exists + self, mock_OCI, mock_path, mock_sha256, mock_exists ): mock_exists.return_value = True oci = Mock() mock_OCI.new.return_value.__enter__.return_value = oci - mock_md5.return_value = Mock() + mock_sha256.return_value = Mock() with patch.dict('os.environ', {'HOME': '../data'}): oci_import = RootImportOCI( 'root_dir', [Uri('docker:image:tag')], @@ -151,4 +151,4 @@ def test_sync_data_unknown_uri( oci.import_rootfs.assert_called_once_with( 'root_dir' ) - mock_md5.assert_called_once_with('root_dir/image/imported_root') + mock_sha256.assert_called_once_with('root_dir/image/imported_root') diff --git a/test/unit/utils/checksum_test.py b/test/unit/utils/checksum_test.py index c8f1d5a2b89..e08a0840743 100644 --- a/test/unit/utils/checksum_test.py +++ b/test/unit/utils/checksum_test.py @@ -56,9 +56,9 @@ def test_matches(self, mock_exists): @patch('kiwi.path.Path.which') @patch('kiwi.utils.checksum.Compress') - @patch('hashlib.md5') + @patch('hashlib.sha256') @patch('os.path.getsize') - def test_md5_xz(self, mock_size, mock_md5, mock_compress, mock_which): + def test_sha256_xz(self, mock_size, mock_sha256, mock_compress, mock_which): checksum = Mock checksum.uncompressed_filename = 'some-file-uncompressed' mock_which.return_value = 'factor' @@ -75,11 +75,11 @@ def test_md5_xz(self, mock_size, mock_md5, mock_compress, mock_which): return_value='xz' ) mock_size.return_value = 1343225856 - mock_md5.return_value = digest + mock_sha256.return_value = digest mock_compress.return_value = compress with patch('builtins.open', self.m_open, create=True): - self.checksum.md5('outfile') + self.checksum.sha256('outfile') assert self.m_open.call_args_list == [ call('some-file', 'rb'), @@ -92,10 +92,10 @@ def test_md5_xz(self, mock_size, mock_md5, mock_compress, mock_which): @patch('kiwi.path.Path.which') @patch('kiwi.utils.checksum.Compress') - @patch('hashlib.md5') + @patch('hashlib.sha256') @patch('os.path.getsize') - def test_md5( - self, mock_size, mock_md5, mock_compress, mock_which + def test_sha256_file( + self, mock_size, mock_sha256, mock_compress, mock_which ): mock_which.return_value = 'factor' compress = Mock() @@ -108,11 +108,11 @@ def test_md5( return_value=None ) mock_size.return_value = 1343225856 - mock_md5.return_value = digest + mock_sha256.return_value = digest mock_compress.return_value = compress with patch('builtins.open', self.m_open, create=True): - self.checksum.md5('outfile') + self.checksum.sha256('outfile') assert self.m_open.call_args_list == [ call('some-file', 'rb'), @@ -165,15 +165,3 @@ def test_sha256_plain(self, mock_sha256): with patch('builtins.open', self.m_open, create=True): assert self.checksum.sha256() == digest.hexdigest.return_value - - @patch('hashlib.md5') - def test_md5_plain(self, mock_md5): - digest = Mock() - digest.block_size = 1024 - digest.hexdigest = Mock( - return_value='sum' - ) - mock_md5.return_value = digest - - with patch('builtins.open', self.m_open, create=True): - assert self.checksum.md5() == digest.hexdigest.return_value