Example #1
0
 def setUp(self):
     super(TestValidateFile, self).setUp()
     assert self.client.login(username='******', password='******')
     self.user = UserProfile.objects.get(email='*****@*****.**')
     self.file = File.objects.get(pk=100456)
     # Move the file into place as if it were a real file
     with storage.open(self.file.file_path, 'w') as dest:
         copyfileobj(open(self.file_path('invalid-id-20101206.xpi')), dest)
     self.addon = self.file.version.addon
Example #2
0
 def test_preview_size(self):
     addon = Addon.objects.get(pk=3615)
     name = "non-animated.gif"
     form = forms.PreviewForm({"caption": "test", "upload_hash": name, "position": 1})
     with storage.open(os.path.join(self.dest, name), "w") as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid()
     form.save(addon)
     assert addon.previews.all()[0].sizes == ({u"image": [250, 297], u"thumbnail": [126, 150]})
Example #3
0
 def test_preview_modified(self, update_mock):
     addon = Addon.objects.get(pk=3615)
     name = "transparent.png"
     form = forms.PreviewForm({"caption": "test", "upload_hash": name, "position": 1})
     with storage.open(os.path.join(self.dest, name), "w") as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid()
     form.save(addon)
     assert update_mock.called
Example #4
0
 def setUp(self):
     super(TestValidateFile, self).setUp()
     assert self.client.login(email='*****@*****.**')
     self.user = UserProfile.objects.get(email='*****@*****.**')
     self.file = File.objects.get(pk=100456)
     # Move the file into place as if it were a real file
     with storage.open(self.file.file_path, 'w') as dest:
         copyfileobj(open(self.file_path('invalid-id-20101206.xpi')),
                     dest)
     self.addon = self.file.version.addon
 def test_preview_modified(self, update_mock):
     addon = Addon.objects.get(pk=3615)
     name = 'transparent.png'
     form = forms.PreviewForm({'caption': 'test', 'upload_hash': name,
                               'position': 1})
     with storage.open(os.path.join(self.dest, name), 'w') as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid()
     form.save(addon)
     assert update_mock.called
 def test_preview_modified(self, update_mock):
     addon = Addon.objects.get(pk=3615)
     name = 'transparent.png'
     form = forms.PreviewForm({'caption': 'test', 'upload_hash': name,
                               'position': 1})
     with storage.open(os.path.join(self.dest, name), 'w') as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid()
     form.save(addon)
     assert update_mock.called
 def test_preview_size(self):
     addon = Addon.objects.get(pk=3615)
     name = 'non-animated.gif'
     form = forms.PreviewForm({'caption': 'test', 'upload_hash': name,
                               'position': 1})
     with storage.open(os.path.join(self.dest, name), 'w') as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid()
     form.save(addon)
     assert addon.previews.all()[0].sizes == (
         {u'image': [250, 297], u'thumbnail': [126, 150]})
 def test_preview_size(self):
     addon = Addon.objects.get(pk=3615)
     name = 'non-animated.gif'
     form = forms.PreviewForm({'caption': 'test', 'upload_hash': name,
                               'position': 1})
     with storage.open(os.path.join(self.dest, name), 'w') as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid()
     form.save(addon)
     assert addon.previews.all()[0].sizes == (
         {u'image': [250, 297], u'thumbnail': [126, 150]})
Example #9
0
    def test_icon_modified(self, update_mock):
        name = 'transparent.png'
        form = forms.AddonFormMedia({'icon_upload_hash': name},
                                    request=self.request,
                                    instance=self.addon)

        dest = os.path.join(self.icon_path, name)
        with storage.open(dest, 'w') as f:
            copyfileobj(open(get_image_path(name)), f)
        assert form.is_valid()
        form.save(addon=self.addon)
        assert update_mock.called
    def test_icon_modified(self, update_mock):
        name = 'transparent.png'
        form = forms.AddonFormMedia({'icon_upload_hash': name},
                                    request=self.request,
                                    instance=self.addon)

        dest = os.path.join(self.icon_path, name)
        with storage.open(dest, 'w') as f:
            copyfileobj(open(get_image_path(name)), f)
        assert form.is_valid()
        form.save(addon=self.addon)
        assert update_mock.called
Example #11
0
    def upload(self, name):
        if os.path.splitext(name)[-1] not in ['.xml', '.xpi', '.jar', '.zip']:
            name = name + '.xpi'

        v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={},
                            signing_summary={'trivial': 0, 'low': 0,
                                             'medium': 0, 'high': 0},
                            passed_auto_validation=1))
        fname = nfd_str(self.xpi_path(name))
        if not storage.exists(fname):
            with storage.open(fname, 'w') as fs:
                copyfileobj(open(fname), fs)
        d = dict(path=fname, name=name,
                 hash='sha256:%s' % name, validation=v)
        return FileUpload.objects.create(**d)
Example #12
0
    def upload(self, name):
        # Add in `.xpi` if the filename doesn't have a valid file extension.
        if os.path.splitext(name)[-1] not in EXTENSIONS:
            name = name + '.xpi'

        v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={},
                            signing_summary={'trivial': 0, 'low': 0,
                                             'medium': 0, 'high': 0},
                            passed_auto_validation=1))
        fname = nfd_str(self.xpi_path(name))
        if not storage.exists(fname):
            with storage.open(fname, 'w') as fs:
                copyfileobj(open(fname), fs)
        d = dict(path=fname, name=name,
                 hash='sha256:%s' % name, validation=v)
        return FileUpload.objects.create(**d)
Example #13
0
    def upload(self, name):
        # Add in `.xpi` if the filename doesn't have a valid file extension.
        if os.path.splitext(name)[-1] not in EXTENSIONS:
            name = name + '.xpi'

        validation_data = json.dumps({
            'errors': 0,
            'warnings': 1,
            'notices': 2,
            'metadata': {},
        })
        fname = nfd_str(self.xpi_path(name))
        if not storage.exists(fname):
            with storage.open(fname, 'w') as fs:
                copyfileobj(open(fname), fs)
        data = {
            'path': fname,
            'name': name,
            'hash': 'sha256:%s' % name,
            'validation': validation_data
        }
        return FileUpload.objects.create(**data)
Example #14
0
    def upload(self, name):
        # Add in `.xpi` if the filename doesn't have a valid file extension.
        if os.path.splitext(name)[-1] not in EXTENSIONS:
            name = name + '.xpi'

        validation_data = json.dumps({
            'errors': 0,
            'warnings': 1,
            'notices': 2,
            'metadata': {},
        })
        fname = nfd_str(self.xpi_path(name))
        if not storage.exists(fname):
            with storage.open(fname, 'w') as fs:
                copyfileobj(open(fname), fs)
        data = {
            'path': fname,
            'name': name,
            'hash': 'sha256:%s' % name,
            'validation': validation_data
        }
        return FileUpload.objects.create(**data)
Example #15
0
def run_validator(path, for_appversions=None, test_all_tiers=False,
                  overrides=None, compat=False, listed=True):
    """A pre-configured wrapper around the addon validator.

    *file_path*
        Path to addon / extension file to validate.

    *for_appversions=None*
        An optional dict of application versions to validate this addon
        for. The key is an application GUID and its value is a list of
        versions.

    *test_all_tiers=False*
        When False (default) the validator will not continue if it
        encounters fatal errors.  When True, all tests in all tiers are run.
        See bug 615426 for discussion on this default.

    *overrides=None*
        Normally the validator gets info from the manifest but there are a
        few things we need to override. See validator for supported overrides.
        Example: {'targetapp_maxVersion': {'<app guid>': '<version>'}}

    *compat=False*
        Set this to `True` when performing a bulk validation. This allows the
        validator to ignore certain tests that should not be run during bulk
        validation (see bug 735841).

    *listed=True*
        If the addon is unlisted, treat it as if it was a self hosted one
        (don't fail on the presence of an updateURL).

    To validate the addon for compatibility with Firefox 5 and 6,
    you'd pass in::

        for_appversions={amo.FIREFOX.guid: ['5.0.*', '6.0.*']}

    Not all application versions will have a set of registered
    compatibility tests.
    """
    if not settings.VALIDATE_ADDONS:
        # This should only ever be set on development instances.
        # Don't run the validator, just return a skeleton passing result set.
        results = deepcopy(amo.VALIDATOR_SKELETON_RESULTS)
        results['metadata']['listed'] = listed
        return json.dumps(results)

    from validator.validate import validate

    apps = dump_apps.Command.JSON_PATH
    if not os.path.exists(apps):
        call_command('dump_apps')

    with NamedTemporaryFile(suffix='_' + os.path.basename(path)) as temp:
        if path and not os.path.exists(path) and storage.exists(path):
            # This file doesn't exist locally. Write it to our
            # currently-open temp file and switch to that path.
            copyfileobj(storage.open(path), temp.file)
            path = temp.name

        with statsd.timer('devhub.validator'):
            json_result = validate(
                path,
                for_appversions=for_appversions,
                format='json',
                # When False, this flag says to stop testing after one
                # tier fails.
                determined=test_all_tiers,
                approved_applications=apps,
                spidermonkey=settings.SPIDERMONKEY,
                overrides=overrides,
                compat_test=compat,
                listed=listed
            )

        track_validation_stats(json_result)

        return json_result
Example #16
0
def run_validator(path, for_appversions=None, test_all_tiers=False,
                  overrides=None, compat=False, listed=True):
    """A pre-configured wrapper around the addon validator.

    *file_path*
        Path to addon / extension file to validate.

    *for_appversions=None*
        An optional dict of application versions to validate this addon
        for. The key is an application GUID and its value is a list of
        versions.

    *test_all_tiers=False*
        When False (default) the validator will not continue if it
        encounters fatal errors.  When True, all tests in all tiers are run.
        See bug 615426 for discussion on this default.

    *overrides=None*
        Normally the validator gets info from the manifest but there are a
        few things we need to override. See validator for supported overrides.
        Example: {'targetapp_maxVersion': {'<app guid>': '<version>'}}

    *compat=False*
        Set this to `True` when performing a bulk validation. This allows the
        validator to ignore certain tests that should not be run during bulk
        validation (see bug 735841).

    *listed=True*
        If the addon is unlisted, treat it as if it was a self hosted one
        (don't fail on the presence of an updateURL).

    To validate the addon for compatibility with Firefox 5 and 6,
    you'd pass in::

        for_appversions={amo.FIREFOX.guid: ['5.0.*', '6.0.*']}

    Not all application versions will have a set of registered
    compatibility tests.
    """
    from validator.validate import validate

    apps = dump_apps.Command.JSON_PATH
    if not os.path.exists(apps):
        call_command('dump_apps')

    with NamedTemporaryFile(suffix='_' + os.path.basename(path)) as temp:
        if path and not os.path.exists(path) and storage.exists(path):
            # This file doesn't exist locally. Write it to our
            # currently-open temp file and switch to that path.
            copyfileobj(storage.open(path), temp.file)
            path = temp.name

        with statsd.timer('devhub.validator'):
            json_result = validate(
                path,
                for_appversions=for_appversions,
                format='json',
                # When False, this flag says to stop testing after one
                # tier fails.
                determined=test_all_tiers,
                approved_applications=apps,
                spidermonkey=settings.SPIDERMONKEY,
                overrides=overrides,
                compat_test=compat,
                listed=listed
            )

        track_validation_stats(json_result)

        return json_result