Ejemplo n.º 1
0
 def test_preview_size(self):
     name = "non-animated.gif"
     form = forms.PreviewForm({"caption": "test", "upload_hash": name, "position": 1})
     with storage.open(os.path.join(self.dest, name), "wb") as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid(), form.errors
     form.save(self.addon)
     eq_(self.addon.previews.all()[0].sizes, {u"image": [250, 297], u"thumbnail": [180, 214]})
Ejemplo n.º 2
0
 def setUp(self):
     self.webapp_path = tempfile.mktemp(suffix='.webapp')
     with storage.open(self.webapp_path, 'wb') as f:
         copyfileobj(open(os.path.join(os.path.dirname(__file__),
                                       'addons', 'mozball.webapp')),
                     f)
     self.tmp_files = []
     self.manifest = dict(name=u'Ivan Krsti\u0107', version=u'1.0',
                          description=u'summary')
Ejemplo n.º 3
0
 def setUp(self):
     self.webapp_path = tempfile.mktemp(suffix='.webapp')
     with storage.open(self.webapp_path, 'wb') as f:
         copyfileobj(open(os.path.join(os.path.dirname(__file__),
                                       'addons', 'mozball.webapp')),
                     f)
     self.tmp_files = []
     self.manifest = dict(name=u'Ivan Krsti\u0107', version=u'1.0',
                          description=u'summary')
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
0
 def upload(self, name):
     v = json.dumps(dict(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)
     d = dict(path=fname, name='%s.xpi' % name,
              hash='sha256:%s' % name, validation=v)
     return FileUpload.objects.create(**d)
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
0
 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name,
                               'position': 1})
     with storage.open(os.path.join(self.dest, name), 'wb') as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid(), form.errors
     form.save(self.addon)
     eq_(self.addon.previews.all()[0].sizes,
         {u'image': [250, 297], u'thumbnail': [180, 214]})
Ejemplo n.º 10
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
Ejemplo n.º 11
0
 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name,
                               'position': 1})
     with storage.open(os.path.join(self.dest, name), 'wb') as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid(), form.errors
     form.save(self.addon)
     eq_(self.addon.previews.all()[0].sizes,
         {u'image': [250, 297], u'thumbnail': [100, 119]})
Ejemplo n.º 12
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)
     eq_(addon.previews.all()[0].sizes,
         {u'image': [250, 297], u'thumbnail': [126, 150]})
Ejemplo n.º 13
0
    def upload(self, name):
        if os.path.splitext(name)[-1] not in [".xml", ".xpi", ".jar"]:
            name = name + ".xpi"

        v = json.dumps(dict(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)
        d = dict(path=fname, name=name, hash="sha256:%s" % name, validation=v)
        return FileUpload.objects.create(**d)
Ejemplo n.º 14
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)
     eq_(addon.previews.all()[0].sizes,
         {u'image': [250, 297], u'thumbnail': [126, 150]})
Ejemplo n.º 15
0
    def upload(self, name):
        if os.path.splitext(name)[-1] not in ['.xml', '.xpi', '.jar']:
            name = name + '.xpi'

        v = json.dumps(dict(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)
        d = dict(path=fname, name=name, hash='sha256:%s' % name, validation=v)
        return FileUpload.objects.create(**d)
Ejemplo n.º 16
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
Ejemplo n.º 17
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
Ejemplo n.º 18
0
    def upload(self, name):
        if os.path.splitext(name)[-1] not in ['.xml', '.xpi', '.jar']:
            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)
Ejemplo n.º 19
0
def run_validator(file_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 install.rdf 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')

    path = file_path
    if path and not os.path.exists(path) and storage.exists(path):
        path = tempfile.mktemp(suffix='_' + os.path.basename(file_path))
        with open(path, 'wb') as f:
            copyfileobj(storage.open(file_path), f)
        temp = True
    else:
        temp = False
    try:
        with statsd.timer('devhub.validator'):
            return 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,
                            timeout=settings.VALIDATOR_TIMEOUT,
                            compat_test=compat,
                            listed=listed)
    finally:
        if temp:
            os.remove(path)
Ejemplo n.º 20
0
 def packaged_copy_over(self, dest, name):
     with storage.open(dest, 'wb') as f:
         copyfileobj(open(self.packaged_app_path(name)), f)
Ejemplo n.º 21
0
 def manifest_copy_over(self, dest, name):
     with storage.open(dest, 'wb') as f:
         copyfileobj(open(self.manifest_path(name)), f)
Ejemplo n.º 22
0
 def manifest_copy_over(self, dest, name):
     with storage.open(dest, 'wb') as f:
         copyfileobj(open(self.manifest_path(name)), f)
Ejemplo n.º 23
0
def run_validator(file_path, for_appversions=None, test_all_tiers=False,
                  overrides=None):
    """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 install.rdf but there are a
        few things we need to override. See validator for supported overrides.
        Example: {'targetapp_maxVersion': {'<app guid>': '<version>'}}

    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

    # TODO(Kumar) remove this when validator is fixed, see bug 620503
    from validator.testcases import scripting
    scripting.SPIDERMONKEY_INSTALLATION = settings.SPIDERMONKEY
    import validator.constants
    validator.constants.SPIDERMONKEY_INSTALLATION = settings.SPIDERMONKEY

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

    path = file_path
    if path and not os.path.exists(path) and storage.exists(path):
        path = tempfile.mktemp(suffix='_' + os.path.basename(file_path))
        with open(path, 'wb') as f:
            copyfileobj(storage.open(file_path), f)
        temp = True
    else:
        temp = False
    try:
        with statsd.timer('devhub.validator'):
            return 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,
                            timeout=settings.VALIDATOR_TIMEOUT)
    finally:
        if temp:
            os.remove(path)
Ejemplo n.º 24
0
 def packaged_copy_over(self, dest, name):
     with storage.open(dest, 'wb') as f:
         copyfileobj(open(self.packaged_app_path(name)), f)
Ejemplo n.º 25
0
def run_validator(file_path,
                  for_appversions=None,
                  test_all_tiers=False,
                  overrides=None,
                  compat=False):
    """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 install.rdf 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).

    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')

    path = file_path
    if path and not os.path.exists(path) and storage.exists(path):
        path = tempfile.mktemp(suffix='_' + os.path.basename(file_path))
        with open(path, 'wb') as f:
            copyfileobj(storage.open(file_path), f)
        temp = True
    else:
        temp = False
    try:
        with statsd.timer('devhub.validator'):
            return 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,
                timeout=settings.VALIDATOR_TIMEOUT,
                compat_test=compat)
    finally:
        if temp:
            os.remove(path)
Ejemplo n.º 26
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 install.rdf 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
Ejemplo n.º 27
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 install.rdf 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