Example #1
0
    def test_package_hash(self):
        with open('hash-test.txt', 'w') as f:
            f.write('I should find some lorem text' * 123)

        digest = ('cb44ec613a594f3b20e46b768c5ee780e0a9b66ac'
                  '6d5ac1468ca4d3635c4aa9b')
        assert digest == get_package_hashes('hash-test.txt')
Example #2
0
    def _write_update_to_disk(self):  # pragma: no cover
        # Writes updated binary to disk
        log.debug('Writing update to disk')
        filename_key = '{}*{}*{}*{}*{}'.format(settings.UPDATES_KEY, self.name,
                                               self.highest_version,
                                               self.platform, 'filename')

        filename = self.star_access_update_data.get(filename_key)
        if filename is None:
            raise PatcherError('Filename missing in version file')

        with jms_utils.paths.ChDir(self.update_folder):
            try:
                with open(filename, 'wb') as f:
                    f.write(self.new_binary)
                log.debug('Wrote update file')
            except IOError:
                # Removes file if it got created
                if os.path.exists(filename):
                    os.remove(filename)
                log.error('Failed to open file for writing')
                raise PatcherError('Failed to open file for writing')
            else:
                file_info = self._current_file_info(self.name,
                                                    self.highest_version)

                new_file_hash = file_info['file_hash']
                log.debug('checking file hash match')
                if new_file_hash != get_package_hashes(filename):
                    log.error('File hash does not match')
                    os.remove(filename)
                    raise PatcherError('Bad hash on patched file')
Example #3
0
    def _write_update_to_disk(self):  # pragma: no cover
        # Writes updated binary to disk
        log.debug('Writing update to disk')
        filename_key = '{}*{}*{}*{}*{}'.format(settings.UPDATES_KEY, self.name,
                                               self.highest_version,
                                               self.platform,
                                               'filename')

        filename = self.star_access_update_data.get(filename_key)
        if filename is None:
            raise PatcherError('Filename missing in version file')

        with jms_utils.paths.ChDir(self.update_folder):
            try:
                with open(filename, 'wb') as f:
                    f.write(self.new_binary)
                log.debug('Wrote update file')
            except IOError:
                # Removes file if it got created
                if os.path.exists(filename):
                    os.remove(filename)
                log.error('Failed to open file for writing')
                raise PatcherError('Failed to open file for writing')
            else:
                file_info = self._current_file_info(self.name,
                                                    self.highest_version)

                new_file_hash = file_info['file_hash']
                log.debug('checking file hash match')
                if new_file_hash != get_package_hashes(filename):
                    log.error('File hash does not match')
                    os.remove(filename)
                    raise PatcherError('Bad hash on patched file')
Example #4
0
    def _verify_installed_binary(self):
        # Verifies latest downloaded archive against known hash
        log.debug('Checking for current installed binary to patch')

        with jms_utils.paths.ChDir(self.update_folder):
            if not os.path.exists(self.current_filename):
                log.debug('Cannot find archive to patch')
                return False

            installed_file_hash = get_package_hashes(self.current_filename)
            if self.current_file_hash != installed_file_hash:
                log.debug('Binary hash mismatch')
                return False
            # Read binary into memory to begin patching
            with open(self.current_filename, 'rb') as f:
                self.og_binary = f.read()
        log.debug('Binary found and verified')
        return True
Example #5
0
    def _verify_installed_binary(self):
        # Verifies latest downloaded archive against known hash
        log.debug('Checking for current installed binary to patch')

        with jms_utils.paths.ChDir(self.update_folder):
            if not os.path.exists(self.current_filename):
                log.debug('Cannot find archive to patch')
                return False

            installed_file_hash = get_package_hashes(self.current_filename)
            if self.current_file_hash != installed_file_hash:
                log.debug('Binary hash mismatch')
                return False
            # Read binary into memory to begin patching
            with open(self.current_filename, 'rb') as f:
                self.og_binary = f.read()
        log.debug('Binary found and verified')
        return True
Example #6
0
 def test_package_hash(self, hasher):
     digest = ('cb44ec613a594f3b20e46b768c5ee780e0a9b66ac'
               '6d5ac1468ca4d3635c4aa9b')
     assert digest == get_package_hashes('hash-test.txt')
Example #7
0
 def test_package_hash(self, hasher):
     digest = ('cb44ec613a594f3b20e46b768c5ee780e0a9b66ac'
               '6d5ac1468ca4d3635c4aa9b')
     assert digest == get_package_hashes('hash-test.txt')