Ejemplo n.º 1
0
    def block_multiple_versions(self):
        # self.version and self.files won't point to the versions we want to
        # modify in this action, so set them to None before finding the right
        # versions.
        self.version = None
        self.files = None
        action_id = amo.LOG.REJECT_VERSION
        timestamp = datetime.now()
        min_version = ('0', 0)
        max_version = ('*', 0)
        for version in self.data['versions']:
            files = version.files.all()
            self.set_files(amo.STATUS_DISABLED, files, hide_disabled_file=True)
            self.log_action(action_id,
                            version=version,
                            files=files,
                            timestamp=timestamp)
            if self.human_review:
                # Unset needs_human_review on rejected versions, we consider
                # that the reviewer looked at them before disabling.
                if version.needs_human_review:
                    version.update(needs_human_review=False)
            version_int = addon_version_int(version.version)
            if not min_version[1] or version_int < min_version[1]:
                min_version = (version, version_int)
            if not max_version[1] or version_int > max_version[1]:
                max_version = (version, version_int)
        log.info(
            'Making %s versions %s disabled' %
            (self.addon, ', '.join(str(v.pk) for v in self.data['versions'])))

        params = f'?min={min_version[0].pk}&max={max_version[0].pk}'
        self.redirect_url = (
            reverse('admin:blocklist_block_addaddon', args=(self.addon.pk, )) +
            params)
Ejemplo n.º 2
0
def test_addon_version_int_hash():
    assert addon_version_int('3.5.0a1pre2') == 0x30005000000000000102
    assert addon_version_int('') == 0x2000010
    assert addon_version_int('0') == 0x2000010
    assert addon_version_int('*') == 0xFFFF0000000000002000010
    assert addon_version_int(MAX_VERSION_PART) == 0xFFFF0000000000002000010
    assert addon_version_int('*.65535.65535.65535') == (
        0xFFFFFFFFFFFFFFFF2000010)
    assert addon_version_int('*.65535.65635.65535a65535pre9') == (
        0xFFFFFFFFFFFFFFFF0FFFF09)
Ejemplo n.º 3
0
    def block_multiple_versions(self):
        min_version = ('0', 0)
        max_version = ('*', 0)
        for version in self.data['versions']:
            version_int = addon_version_int(version.version)
            if not min_version[1] or version_int < min_version[1]:
                min_version = (version, version_int)
            if not max_version[1] or version_int > max_version[1]:
                max_version = (version, version_int)

        params = f'?min={min_version[0].pk}&max={max_version[0].pk}'
        self.redirect_url = (
            reverse('admin:blocklist_block_addaddon', args=(self.addon.pk,)) +
            params)
Ejemplo n.º 4
0
 def min_version_vint(self):
     return addon_version_int(self.min_version)
Ejemplo n.º 5
0
 def clean(self):
     min_vint = addon_version_int(self.min_version)
     max_vint = addon_version_int(self.max_version)
     if min_vint > max_vint:
         raise ValidationError(
             _('Min version can not be greater than Max version'))
Ejemplo n.º 6
0
 def is_version_blocked(self, version):
     version_vint = addon_version_int(version)
     return (version_vint >= self.min_version_vint
             and version_vint <= self.max_version_vint)
Ejemplo n.º 7
0
def test_addon_version_int_compare():
    assert addon_version_int('3.6.*') == addon_version_int('3.6.65535')
    assert addon_version_int('3.6.*') > addon_version_int('3.6.8')
    assert addon_version_int('*') == addon_version_int('65535')
    assert addon_version_int('*') == addon_version_int('65536')  # over max.
    assert addon_version_int('98.*') < addon_version_int('*')
    assert addon_version_int('65534.*') < addon_version_int('*')
    assert addon_version_int('5.*') == addon_version_int('5.65535')
    assert addon_version_int('5.*') > addon_version_int('5.0.*')