Esempio n. 1
0
    def test_passed_based_on_signing_summary(self):
        """Test that the 'passed_auto_validation' flag is correctly added,
        based on signing summary."""

        result = annotate_validation_results(self.get_validation())
        assert result['passed_auto_validation'] is True

        validation = self.get_validation()
        validation['signing_summary'] = {
            'high': 0,
            'medium': 0,
            'low': 1,
            'trivial': 0
        }
        result = annotate_validation_results(validation)
        assert result['passed_auto_validation'] is False

        result = annotate_validation_results(
            (self.get_validation(), self.get_validation()))
        assert result['passed_auto_validation'] is True
        assert (result['signing_summary'] == {
            'high': 0,
            'medium': 0,
            'low': 0,
            'trivial': 0
        })
        assert (result['signing_ignored_summary'] == {
            'high': 0,
            'medium': 0,
            'low': 1,
            'trivial': 0
        })
Esempio n. 2
0
    def from_upload(cls,
                    upload,
                    version,
                    platform,
                    is_beta=False,
                    parsed_data=None):
        if parsed_data is None:
            parsed_data = {}
        addon = version.addon

        file_ = cls(version=version, platform=platform)
        upload.path = force_bytes(nfd_str(upload.path))
        ext = os.path.splitext(upload.path)[1]
        if ext == '.jar':
            ext = '.xpi'
        file_.filename = file_.generate_filename(extension=ext or '.xpi')
        # Size in bytes.
        file_.size = storage.size(upload.path)
        data = cls.get_jetpack_metadata(upload.path)
        if 'sdkVersion' in data and data['sdkVersion']:
            file_.jetpack_version = data['sdkVersion'][:10]
        file_.no_restart = parsed_data.get('no_restart', False)
        file_.strict_compatibility = parsed_data.get('strict_compatibility',
                                                     False)
        file_.is_multi_package = parsed_data.get('is_multi_package', False)
        file_.is_experiment = parsed_data.get('is_experiment', False)
        file_.is_webextension = parsed_data.get('is_webextension', False)

        if (is_beta and addon.status == amo.STATUS_PUBLIC
                and version.channel == amo.RELEASE_CHANNEL_LISTED):
            file_.status = amo.STATUS_BETA

        file_.hash = file_.generate_hash(upload.path)
        file_.original_hash = file_.hash

        if upload.validation:
            validation = json.loads(upload.validation)
            if validation['metadata'].get('requires_chrome'):
                file_.requires_chrome = True

        file_.save()

        log.debug('New file: %r from %r' % (file_, upload))
        # Move the uploaded file from the temp location.
        copy_stored_file(
            upload.path,
            os.path.join(version.path_prefix, nfd_str(file_.filename)))

        if upload.validation:
            # Import loop.
            from olympia.devhub.tasks import annotate_validation_results
            from olympia.devhub.utils import ValidationAnnotator

            validation = annotate_validation_results(validation)
            FileValidation.from_json(file_, validation)

            # Copy annotations from any previously approved file.
            ValidationAnnotator(file_).update_annotations()

        return file_
Esempio n. 3
0
    def test_single_validation(self):
        """Test that passing a single validation result works."""

        result = annotate_validation_results(self.get_validation())

        assert (result['messages'][0]['id'] ==
                self.VALIDATION['messages'][0]['id'])
Esempio n. 4
0
    def test_passed_based_on_signing_summary(self):
        """Test that the 'passed_auto_validation' flag is correctly added,
        based on signing summary."""

        result = annotate_validation_results(self.get_validation())
        assert result["passed_auto_validation"] is True

        validation = self.get_validation()
        validation["signing_summary"] = {"high": 0, "medium": 0, "low": 1, "trivial": 0}
        result = annotate_validation_results(validation)
        assert result["passed_auto_validation"] is False

        result = annotate_validation_results((self.get_validation(), self.get_validation()))
        assert result["passed_auto_validation"] is True
        assert result["signing_summary"] == {"high": 0, "medium": 0, "low": 0, "trivial": 0}
        assert result["signing_ignored_summary"] == {"high": 0, "medium": 0, "low": 1, "trivial": 0}
Esempio n. 5
0
    def test_multiple_validations(self):
        """Test that multiple validations, to be merged by
        ValidationComparator, work."""

        result = annotate_validation_results((self.get_validation(), self.get_validation()))

        assert result["messages"][0]["matched"] == self.VALIDATION["messages"][0]
Esempio n. 6
0
    def test_signing_summary_added(self):
        """Test that if a signing summary is missing, an empty one is
        added."""

        assert "signing_summary" not in self.VALIDATION

        result = annotate_validation_results(self.get_validation())
        assert result["signing_summary"] == {"high": 0, "medium": 0, "low": 0, "trivial": 0}
Esempio n. 7
0
    def from_upload(cls, upload, version, platform, is_beta=False,
                    parse_data={}):
        addon = version.addon

        file_ = cls(version=version, platform=platform)
        upload.path = smart_path(nfd_str(upload.path))
        ext = os.path.splitext(upload.path)[1]
        if ext == '.jar':
            ext = '.xpi'
        file_.filename = file_.generate_filename(extension=ext or '.xpi')
        # Size in bytes.
        file_.size = storage.size(upload.path)
        data = cls.get_jetpack_metadata(upload.path)
        if 'sdkVersion' in data and data['sdkVersion']:
            file_.jetpack_version = data['sdkVersion'][:10]
        if file_.jetpack_version:
            Tag(tag_text='jetpack').save_tag(addon)
        file_.no_restart = parse_data.get('no_restart', False)
        file_.strict_compatibility = parse_data.get('strict_compatibility',
                                                    False)
        file_.is_multi_package = parse_data.get('is_multi_package', False)
        file_.is_experiment = parse_data.get('is_experiment', False)
        file_.is_webextension = parse_data.get('is_webextension', False)

        if is_beta and addon.status == amo.STATUS_PUBLIC:
            file_.status = amo.STATUS_BETA

        file_.hash = file_.generate_hash(upload.path)
        file_.original_hash = file_.hash

        if upload.validation:
            validation = json.loads(upload.validation)
            if validation['metadata'].get('requires_chrome'):
                file_.requires_chrome = True

        file_.save()

        log.debug('New file: %r from %r' % (file_, upload))
        # Move the uploaded file from the temp location.
        destinations = [version.path_prefix]
        if file_.status in amo.MIRROR_STATUSES:
            destinations.append(version.mirror_path_prefix)
        for dest in destinations:
            copy_stored_file(upload.path,
                             os.path.join(dest, nfd_str(file_.filename)))

        if upload.validation:
            # Import loop.
            from olympia.devhub.tasks import annotate_validation_results
            from olympia.devhub.utils import ValidationAnnotator

            validation = annotate_validation_results(validation)
            FileValidation.from_json(file_, validation)

            # Copy annotations from any previously approved file.
            ValidationAnnotator(file_).update_annotations()

        return file_
Esempio n. 8
0
    def test_signing_summary_added(self):
        """Test that if a signing summary is missing, an empty one is
        added."""

        assert 'signing_summary' not in self.VALIDATION

        result = annotate_validation_results(self.get_validation())
        assert (result['signing_summary'] ==
                {'high': 0, 'medium': 0, 'low': 0, 'trivial': 0})
Esempio n. 9
0
    def test_multiple_validations(self):
        """Test that multiple validations, to be merged by
        ValidationComparator, work."""

        result = annotate_validation_results((self.get_validation(),
                                              self.get_validation()))

        assert (result['messages'][0]['matched'] ==
                self.VALIDATION['messages'][0])
Esempio n. 10
0
    def from_upload(cls, upload, version, platform, is_beta=False,
                    parsed_data=None):
        if parsed_data is None:
            parsed_data = {}
        addon = version.addon

        file_ = cls(version=version, platform=platform)
        upload.path = force_bytes(nfd_str(upload.path))
        ext = os.path.splitext(upload.path)[1]
        if ext == '.jar':
            ext = '.xpi'
        file_.filename = file_.generate_filename(extension=ext or '.xpi')
        # Size in bytes.
        file_.size = storage.size(upload.path)
        data = cls.get_jetpack_metadata(upload.path)
        if 'sdkVersion' in data and data['sdkVersion']:
            file_.jetpack_version = data['sdkVersion'][:10]
        file_.no_restart = parsed_data.get('no_restart', False)
        file_.strict_compatibility = parsed_data.get('strict_compatibility',
                                                     False)
        file_.is_multi_package = parsed_data.get('is_multi_package', False)
        file_.is_experiment = parsed_data.get('is_experiment', False)
        file_.is_webextension = parsed_data.get('is_webextension', False)

        if (is_beta and addon.status == amo.STATUS_PUBLIC and
                version.channel == amo.RELEASE_CHANNEL_LISTED):
            file_.status = amo.STATUS_BETA

        file_.hash = file_.generate_hash(upload.path)
        file_.original_hash = file_.hash

        if upload.validation:
            validation = json.loads(upload.validation)
            if validation['metadata'].get('requires_chrome'):
                file_.requires_chrome = True

        file_.save()

        log.debug('New file: %r from %r' % (file_, upload))
        # Move the uploaded file from the temp location.
        copy_stored_file(
            upload.path,
            os.path.join(version.path_prefix, nfd_str(file_.filename)))

        if upload.validation:
            # Import loop.
            from olympia.devhub.tasks import annotate_validation_results
            from olympia.devhub.utils import ValidationAnnotator

            validation = annotate_validation_results(validation)
            FileValidation.from_json(file_, validation)

            # Copy annotations from any previously approved file.
            ValidationAnnotator(file_).update_annotations()

        return file_
Esempio n. 11
0
    def test_passed_based_on_signing_summary(self):
        """Test that the 'passed_auto_validation' flag is correctly added,
        based on signing summary."""

        result = annotate_validation_results(self.get_validation())
        assert result['passed_auto_validation'] is True

        validation = self.get_validation()
        validation['signing_summary'] = {'high': 0, 'medium': 0, 'low': 1,
                                         'trivial': 0}
        result = annotate_validation_results(validation)
        assert result['passed_auto_validation'] is False

        result = annotate_validation_results((self.get_validation(),
                                              self.get_validation()))
        assert result['passed_auto_validation'] is True
        assert (result['signing_summary'] ==
                {'high': 0, 'medium': 0, 'low': 0, 'trivial': 0})
        assert (result['signing_ignored_summary'] ==
                {'high': 0, 'medium': 0, 'low': 1, 'trivial': 0})
Esempio n. 12
0
    def from_upload(cls,
                    upload,
                    version,
                    platform,
                    is_beta=False,
                    parse_data={}):
        addon = version.addon

        file_ = cls(version=version, platform=platform)
        upload.path = smart_path(nfd_str(upload.path))
        ext = os.path.splitext(upload.path)[1]
        if ext == '.jar':
            ext = '.xpi'
        file_.filename = file_.generate_filename(extension=ext or '.xpi')
        # Size in bytes.
        file_.size = storage.size(upload.path)
        data = cls.get_jetpack_metadata(upload.path)
        if 'sdkVersion' in data and data['sdkVersion']:
            file_.jetpack_version = data['sdkVersion'][:10]
        if file_.jetpack_version:
            Tag(tag_text='jetpack').save_tag(addon)
        file_.no_restart = parse_data.get('no_restart', False)
        file_.strict_compatibility = parse_data.get('strict_compatibility',
                                                    False)
        file_.is_multi_package = parse_data.get('is_multi_package', False)
        file_.is_experiment = parse_data.get('is_experiment', False)
        file_.is_webextension = parse_data.get('is_webextension', False)

        if is_beta and addon.status == amo.STATUS_PUBLIC:
            file_.status = amo.STATUS_BETA
        elif addon.trusted:
            # New files in trusted add-ons automatically receive the correct
            # approved status for their review class.
            if addon.status == amo.STATUS_PUBLIC:
                file_.status = amo.STATUS_PUBLIC
            elif addon.status in amo.LITE_STATUSES:
                file_.status = amo.STATUS_LITE

        file_.hash = file_.generate_hash(upload.path)
        file_.original_hash = file_.hash

        if upload.validation:
            validation = json.loads(upload.validation)
            if validation['metadata'].get('requires_chrome'):
                file_.requires_chrome = True

        file_.save()

        log.debug('New file: %r from %r' % (file_, upload))
        # Move the uploaded file from the temp location.
        destinations = [version.path_prefix]
        if file_.status in amo.MIRROR_STATUSES:
            destinations.append(version.mirror_path_prefix)
        for dest in destinations:
            copy_stored_file(upload.path,
                             os.path.join(dest, nfd_str(file_.filename)))

        if upload.validation:
            # Import loop.
            from olympia.devhub.tasks import annotate_validation_results
            from olympia.devhub.utils import ValidationAnnotator

            validation = annotate_validation_results(validation)
            FileValidation.from_json(file_, validation)

            # Copy annotations from any previously approved file.
            ValidationAnnotator(file_).update_annotations()

        return file_
Esempio n. 13
0
    def test_single_validation(self):
        """Test that passing a single validation result works."""

        result = annotate_validation_results(self.get_validation())

        assert result["messages"][0]["id"] == self.VALIDATION["messages"][0]["id"]