Example #1
0
    def test_sign_file_multi_package(self):
        fpath = 'src/olympia/files/fixtures/files/multi-package.xpi'
        with amo.tests.copy_file(fpath, self.file_.file_path, overwrite=True):
            self.file_.update(is_multi_package=True)
            self.assert_not_signed()

            packaged.sign_file(self.file_, settings.SIGNING_SERVER)
            self.assert_not_signed()
            # The multi-package itself isn't signed.
            assert not packaged.is_signed(self.file_.file_path)
            # The internal extensions aren't either.
            folder = tempfile.mkdtemp()
            try:
                extract_xpi(self.file_.file_path, folder)
                # The extension isn't.
                assert not packaged.is_signed(
                    os.path.join(folder, 'random_extension.xpi'))
                # And the theme isn't either.
                assert not packaged.is_signed(
                    os.path.join(folder, 'random_theme.xpi'))
            finally:
                amo.utils.rm_local_tmp_dir(folder)
Example #2
0
    def test_sign_file_multi_package(self):
        fpath = 'src/olympia/files/fixtures/files/multi-package.xpi'
        with amo.tests.copy_file(fpath, self.file_.file_path, overwrite=True):
            self.file_.update(is_multi_package=True)
            self.assert_not_signed()

            packaged.sign_file(self.file_, settings.SIGNING_SERVER)
            self.assert_not_signed()
            # The multi-package itself isn't signed.
            assert not packaged.is_signed(self.file_.file_path)
            # The internal extensions aren't either.
            folder = tempfile.mkdtemp()
            try:
                extract_xpi(self.file_.file_path, folder)
                # The extension isn't.
                assert not packaged.is_signed(
                    os.path.join(folder, 'random_extension.xpi'))
                # And the theme isn't either.
                assert not packaged.is_signed(
                    os.path.join(folder, 'random_theme.xpi'))
            finally:
                amo.utils.rm_local_tmp_dir(folder)
Example #3
0
    def extract(self):
        """
        Will make all the directories and expand the files.
        Raises error on nasty files.

        :returns: `True` if successfully extracted,
                  `False` in case of an existing lock.
        """
        with self.lock() as locked:
            if locked:
                if self.is_extracted():
                    # Be vigilent with existing files. It's better to delete
                    # and re-extract than to trust whatever we have
                    # lying around.
                    task_log.warning(
                        'cleaning up %s as there were files lying around' %
                        self.dest)
                    self.cleanup()

                try:
                    os.makedirs(self.dest)
                except OSError, err:
                    task_log.error('Error (%s) creating directories %s' %
                                   (err, self.dest))
                    raise

                if self.is_search_engine() and self.src.endswith('.xml'):
                    copyfileobj(
                        storage.open(self.src),
                        open(os.path.join(self.dest, self.file.filename), 'w'))
                else:
                    try:
                        extract_xpi(self.src, self.dest, expand=True)
                    except Exception, err:
                        task_log.error('Error (%s) extracting %s' %
                                       (err, self.src))
                        raise
Example #4
0
    def extract(self):
        """
        Will make all the directories and extract the files.
        Raises error on nasty files.

        :returns: `True` if successfully extracted,
                  `False` in case of an existing lock.
        """
        lock = atomic_lock(
            settings.TMP_PATH, 'file-viewer-%s' % self.file.pk,
            lifetime=LOCKED_LIFETIME)

        with lock as lock_attained:
            if lock_attained:
                if self.is_extracted():
                    # Be vigilent with existing files. It's better to delete
                    # and re-extract than to trust whatever we have
                    # lying around.
                    task_log.warning(
                        'cleaning up %s as there were files lying around'
                        % self.dest)
                    self.cleanup()

                try:
                    os.makedirs(self.dest)
                except OSError as err:
                    task_log.error(
                        'Error (%s) creating directories %s'
                        % (err, self.dest))
                    raise

                if self.is_search_engine() and self.src.endswith('.xml'):
                    shutil.copyfileobj(
                        storage.open(self.src, 'rb'),
                        open(
                            os.path.join(self.dest, self.file.filename), 'wb'))
                else:
                    try:
                        extracted_files = extract_xpi(self.src, self.dest)
                        self._verify_files(extracted_files)
                    except Exception as err:
                        task_log.error(
                            'Error (%s) extracting %s' % (err, self.src))
                        raise

        return lock_attained
    def extract(self):
        """
        Will make all the directories and extract the files.
        Raises error on nasty files.

        :returns: `True` if successfully extracted,
                  `False` in case of an existing lock.
        """
        lock = atomic_lock(
            settings.TMP_PATH, 'file-viewer-%s' % self.file.pk,
            lifetime=LOCKED_LIFETIME)

        with lock as lock_attained:
            if lock_attained:
                if self.is_extracted():
                    # Be vigilent with existing files. It's better to delete
                    # and re-extract than to trust whatever we have
                    # lying around.
                    task_log.warning(
                        'cleaning up %s as there were files lying around'
                        % self.dest)
                    self.cleanup()

                try:
                    os.makedirs(self.dest)
                except OSError as err:
                    task_log.error(
                        'Error (%s) creating directories %s'
                        % (err, self.dest))
                    raise

                if self.is_search_engine() and self.src.endswith('.xml'):
                    shutil.copyfileobj(
                        storage.open(self.src, 'rb'),
                        open(
                            os.path.join(self.dest, self.file.filename), 'wb'))
                else:
                    try:
                        extracted_files = extract_xpi(self.src, self.dest)
                        self._verify_files(extracted_files)
                    except Exception as err:
                        task_log.error(
                            'Error (%s) extracting %s' % (err, self.src))
                        raise

        return lock_attained
Example #6
0
        try:
            os.makedirs(os.path.dirname(self.dest))
        except OSError, err:
            pass

        if self.is_search_engine() and self.src.endswith('.xml'):
            try:
                os.makedirs(self.dest)
            except OSError, err:
                pass
            copyfileobj(storage.open(self.src),
                        open(os.path.join(self.dest,
                                          self.file.filename), 'w'))
        else:
            try:
                extract_xpi(self.src, self.dest, expand=True)
            except Exception, err:
                task_log.error('Error (%s) extracting %s' % (err, self.src))
                raise

    def cleanup(self):
        if os.path.exists(self.dest):
            rm_local_tmp_dir(self.dest)

    def is_search_engine(self):
        """Is our file for a search engine?"""
        return self.file.version.addon.type == amo.ADDON_SEARCH

    def is_extracted(self):
        """If the file has been extracted or not."""
        return (os.path.exists(self.dest) and not
Example #7
0
        """
        try:
            os.makedirs(os.path.dirname(self.dest))
        except OSError, err:
            pass

        if self.is_search_engine() and self.src.endswith('.xml'):
            try:
                os.makedirs(self.dest)
            except OSError, err:
                pass
            copyfileobj(storage.open(self.src),
                        open(os.path.join(self.dest, self.file.filename), 'w'))
        else:
            try:
                extract_xpi(self.src, self.dest, expand=True)
            except Exception, err:
                task_log.error('Error (%s) extracting %s' % (err, self.src))
                raise

    def cleanup(self):
        if os.path.exists(self.dest):
            rm_local_tmp_dir(self.dest)

    def is_search_engine(self):
        """Is our file for a search engine?"""
        return self.file.version.addon.type == amo.ADDON_SEARCH

    def is_extracted(self):
        """If the file has been extracted or not."""
        return (os.path.exists(self.dest)