Пример #1
0
    def test_download_successful_invalid_checksum_verification(
            self, mock_copy, mock_verify_size, mock_verify_checksum,
            mock_open):
        self.config.get.return_value = True

        mock_verify_checksum.side_effect = verification.VerificationException(
            'bad')
        content_listener = listener.PackageListener(self, self.metadata_files)

        self.assertRaises(verification.VerificationException,
                          content_listener.download_succeeded, self.report)

        mock_verify_checksum.assert_called_once()
        self.assertFalse(self.progress_report['content'].success.called)
Пример #2
0
    def test_download_successful_invalid_checksum_verification(
            self, mock_copy, mock_verify_size, mock_validate_checksumtype,
            mock_verify_checksum, mock_open):
        self.config.get.return_value = True
        self.report.data = models.RPM()

        mock_verify_checksum.side_effect = verification.VerificationException(
            'bad')
        content_listener = listener.PackageListener(self, self.metadata_files)

        with self.assertRaises(verification.VerificationException) as cm:
            content_listener.download_succeeded(self.report)

        self.assertEqual(cm.exception.args[0], 'bad')
        mock_verify_checksum.assert_called_once()
        self.assertFalse(self.progress_report['content'].success.called)
Пример #3
0
    def test_download_successful_invalid_file_size(self, mock_copy,
                                                   mock_verify_size,
                                                   mock_verify_checksum,
                                                   mock_open):
        self.sync_call_config.get.return_value = True

        mock_verify_size.side_effect = verification.VerificationException(
            22)  # seed the size found
        content_listener = listener.ContentListener(self.sync_conduit,
                                                    self.progress_report,
                                                    self.sync_call_config,
                                                    self.metadata_files)

        content_listener.download_succeeded(self.report)

        mock_verify_size.assert_called_once()
        self.assertFalse(self.progress_report['content'].success.called)
Пример #4
0
    def test_put_file_incorrect_size(self, _mkdir, shutil, tempfile, close,
                                     remove, rename):
        path_in = '/tmp/test'
        temp_destination = '/some/file/path'
        unit = Mock(id='123', storage_path='/tmp/storage')
        storage = FileStorage()
        tempfile.mkstemp.return_value = ('fd', temp_destination)
        unit.verify_size.side_effect = verification.VerificationException(22)

        # test
        self.assertRaises(verification.VerificationException, storage.put,
                          unit, path_in)

        # validation
        _mkdir.assert_called_once_with(os.path.dirname(unit.storage_path))
        tempfile.mkstemp.assert_called_once_with(
            dir=os.path.dirname(unit.storage_path))
        close.assert_called_once_with('fd')
        shutil.copy.assert_called_once_with(path_in, temp_destination)
        unit.verify_size.assert_called_once_with(temp_destination)
        remove.assert_called_once_with(temp_destination)
        self.assertFalse(rename.called)
Пример #5
0
    def _verify_checksum(self, unit, location):
        """
        Verifies the checksum of the given unit if the sync is configured to do so.
        If the verification fails, the error is noted in this instance's progress
        report and the error is re-raised.

        :param unit: domain model instance of the package that was downloaded
        :type  unit: pulp_rpm.plugins.db.models.NonMetadataPackage
        :param location: location of the unit that needs to be verified
        :type  location: str

        :raises verification.VerificationException: if the checksum of the content is incorrect
        """

        if not self.sync.config.get(importer_constants.KEY_VALIDATE):
            return

        with open(location) as fp:
            sums = util.calculate_checksums(
                fp, [util.TYPE_MD5, util.TYPE_SHA1, util.TYPE_SHA256])

        if sums[unit.checksumtype] != unit.checksum:
            error_report = {
                constants.NAME: unit.name,
                constants.ERROR_CODE: constants.ERROR_CHECKSUM_VERIFICATION,
                constants.CHECKSUM_TYPE: unit.checksumtype,
                constants.ERROR_KEY_CHECKSUM_EXPECTED: unit.checksum,
                constants.ERROR_KEY_CHECKSUM_ACTUAL: sums[unit.checksumtype]
            }
            self.sync.progress_report['content'].failure(unit, error_report)
            # I don't know why the argument is the calculated sum, but that's the pre-existing
            # behavior in pulp.server.util.verify_checksum
            raise verification.VerificationException(sums[unit.checksumtype])
        else:
            # The unit will be saved later in the workflow, after the file is moved into place.
            unit.checksums.update(sums)