Пример #1
0
 def test_invalid_origins_multiple_matches_same_pattern(self):
     DeniedInstallOrigin.objects.create(hostname_pattern='bar.com')
     DeniedInstallOrigin.objects.create(hostname_pattern='foo.*')
     results = deepcopy(VALIDATOR_SKELETON_RESULTS)
     data = {
         'install_origins': [
             'https://example.com',
             'https://foo.fr',
             'https://foo.com',
         ]
     }
     return_value = annotate_validation_results(results, data)
     assert return_value == results
     assert results['errors'] == 2
     assert results['messages'][0] == {
         'tier': 1,
         'type': 'error',
         'id': ['validation', 'messages', ''],
         'message': 'The install origin https://foo.fr is not permitted.',
         'description': [],
         'compatibility_type': None,
     }
     assert results['messages'][1] == {
         'tier': 1,
         'type': 'error',
         'id': ['validation', 'messages', ''],
         'message': 'The install origin https://foo.com is not permitted.',
         'description': [],
         'compatibility_type': None,
     }
Пример #2
0
 def test_allowed_origins_multiple(self):
     DeniedInstallOrigin.objects.create(hostname_pattern='foo.com')
     results = deepcopy(VALIDATOR_SKELETON_RESULTS)
     data = {'install_origins': ['https://bar.com', 'https://example.com']}
     return_value = annotate_validation_results(results, data)
     assert return_value == results
     assert results['errors'] == 0
     assert len(results['messages']) == 0
Пример #3
0
 def test_empty_parsed_data(self):
     DeniedInstallOrigin.objects.create(hostname_pattern='foo.com')
     results = deepcopy(VALIDATOR_SKELETON_RESULTS)
     data = {}
     return_value = annotate_validation_results(results, data)
     assert return_value == results
     assert results['errors'] == 0
     assert len(results['messages']) == 0
Пример #4
0
def validate_file_path(path, channel):
    """Run the validator against a file at the given path, and return the
    results, which should be a json string.

    Should only be called directly by `validate_upload` or `validate_file`
    tasks.

    Search plugins don't call the linter but get linted by
    `annotate_search_plugin_validation`.

    All legacy extensions (including dictionaries, themes etc) are unsupported.
    """
    if path.endswith('.xml'):
        # search plugins are validated directly by addons-server
        # so that we don't have to call the linter or validator
        results = deepcopy(amo.VALIDATOR_SKELETON_RESULTS)
        annotations.annotate_search_plugin_restriction(results=results,
                                                       file_path=path,
                                                       channel=channel)
        return json.dumps(results)

    parsed_data = {}
    try:
        parsed_data = parse_addon(path, minimal=True)
    except NoManifestFound:
        # If no manifest is found the linter will pick it up and
        # will know what message to return to the developer.
        pass
    except InvalidManifest:
        # Similarly, if we can't parse the manifest, let the linter pick that
        # up.
        pass

    log.info('Running linter on %s', path)
    results = run_addons_linter(path, channel=channel)
    annotations.annotate_validation_results(results, parsed_data)
    return json.dumps(results)