Exemplo n.º 1
0
def test_subpackage_metadata_preserved():
    """Tests that metadata is preserved for sub-packages."""

    xpi1 = open('tests/resources/jetpack/jetpack-1.16-outdated.xpi')
    xpi2 = MockXPI(
        {'thing.xpi': 'tests/resources/jetpack/jetpack-1.16-outdated.xpi'})

    err1 = ErrorBundle()
    err1.detected_type = PACKAGE_EXTENSION

    err2 = ErrorBundle()
    err2.detected_type = PACKAGE_EXTENSION

    submain.test_package(err1, xpi1, 'jetpack-1.16-outdated.xpi')
    content.test_packed_packages(err2, xpi2)

    assert 'sub_packages' in err2.metadata
    assert err1.metadata == err2.metadata['sub_packages'].get('thing.xpi')
def test_package_corrupt_again(test_inner_package):
    'Tests the test_package function fails with a corrupt file'

    err = ErrorBundle()
    with open('tests/resources/corrupt.xpi') as pkg:
        submain.test_package(err, pkg, pkg.name)

    assert not test_inner_package.called
    assert err.failed()
Exemplo n.º 3
0
def test_type():
    """
    Test that detected type is being stored properly in the error bundle.
    """

    bundle = ErrorBundle()

    bundle.detected_type = 5
    assert bundle.detected_type == 5
Exemplo n.º 4
0
def test_hidden_files(test_input):
    """Tests that hidden files are reported."""

    err = ErrorBundle()
    err.supported_versions = {}
    mock_package = MockXPI(test_input)
    content.test_packed_packages(err, mock_package)
    print err.print_summary(verbose=True)
    assert err.failed()
Exemplo n.º 5
0
def test_json_compatibility():
    """Test compatibility elements in the JSON output."""

    err = ErrorBundle()
    err.notice(err_id='m1',
               notice='Compat error',
               description='Compatibility error 1',
               compatibility_type='error')

    err.notice(err_id='m2',
               notice='Compat error',
               description='Compatibility error 2',
               compatibility_type='error')

    err.warning(err_id='m3',
                warning='Compat notice',
                description='Compatibility notice 1',
                compatibility_type='notice')

    err.warning(err_id='m4',
                warning='Compat warning',
                description='Compatibility warning 1',
                compatibility_type='warning')

    err.warning(err_id='m5',
                warning='Compat warning',
                description='Compatibility warning 1',
                compatibility_type='warning')

    err.error(err_id='foo',
              error='Something else',
              description='An error that has nothign to do with compatibility')

    results = err.render_json()
    jdata = json.loads(results)

    assert 'compatibility_summary' in jdata
    nose.tools.eq_(jdata['compatibility_summary'], {
        'errors': 2,
        'warnings': 2,
        'notices': 1
    })
    reference = {
        'm1': 'error',
        'm2': 'error',
        'm3': 'notice',
        'm4': 'warning',
        'm5': 'warning'
    }

    assert 'messages' in jdata and len(jdata['messages'])
    for message in jdata['messages']:
        if message['id'] in reference:
            print(message['id'], reference[message['id']],
                  message['compatibility_type'])
            nose.tools.eq_(reference[message['id']],
                           message['compatibility_type'])
Exemplo n.º 6
0
def test_json_compatibility():
    """Test compatibility elements in the JSON output."""

    err = ErrorBundle()
    err.notice(err_id="m1",
               notice="Compat error",
               description="Compatibility error 1",
               compatibility_type="error")

    err.notice(err_id="m2",
               notice="Compat error",
               description="Compatibility error 2",
               compatibility_type="error")

    err.warning(err_id="m3",
                warning="Compat notice",
                description="Compatibility notice 1",
                compatibility_type="notice")

    err.warning(err_id="m4",
                warning="Compat warning",
                description="Compatibility warning 1",
                compatibility_type="warning")

    err.warning(err_id="m5",
                warning="Compat warning",
                description="Compatibility warning 1",
                compatibility_type="warning")

    err.error(err_id="foo",
              error="Something else",
              description="An error that has nothign to do with compatibility")

    results = err.render_json()
    jdata = json.loads(results)

    assert "compatibility_summary" in jdata
    nose.tools.eq_(jdata["compatibility_summary"], {
        "errors": 2,
        "warnings": 2,
        "notices": 1
    })
    reference = {
        "m1": "error",
        "m2": "error",
        "m3": "notice",
        "m4": "warning",
        "m5": "warning"
    }

    assert "messages" in jdata and len(jdata["messages"])
    for message in jdata["messages"]:
        if message["id"] in reference:
            print(message["id"], reference[message["id"]],
                  message["compatibility_type"])
            nose.tools.eq_(reference[message["id"]],
                           message["compatibility_type"])
def test_pass():
    """Test that standard category subjects pass."""

    c = ChromeManifest('category foo bar', 'chrome.manifest')
    err = ErrorBundle()
    err.save_resource('chrome.manifest', c)

    tc_chromemanifest.test_categories(err)
    assert not err.failed()
Exemplo n.º 8
0
def test_subpackage():
    'Test a package with localization that should pass validation.'

    err = ErrorBundle()
    err.detected_type = PACKAGE_DICTIONARY
    assert l10n.test_xpi(err, None) is None
    err.detected_type = PACKAGE_EXTENSION
    err.push_state()
    assert l10n.test_xpi(err, None) is None
def test_package_pass(test_inner_package):
    'Tests the test_package function with simple data'

    err = ErrorBundle()
    with open('tests/resources/submain/install_rdf.xpi') as pkg:
        submain.test_package(err, pkg, pkg.name)

    assert not err.failed()
    assert err.get_resource('has_install_rdf')
    assert submain.test_inner_package.called
def test_package_extension_bad_expectation(test_inner_package):
    'Tests the test_package function with an odd extension'

    err = ErrorBundle()
    with open('tests/resources/submain/install_rdf.jar') as pkg:
        submain.test_package(err, pkg, pkg.name, PACKAGE_SEARCHPROV)

    assert test_inner_package.called
    assert err.failed()
    assert err.errors[0]['id'] == ('main', 'test_package', 'unexpected_type')
def test_package_extension_expectation(test_inner_package):
    'Tests the test_package function with an odd extension'

    err = ErrorBundle()
    with open('tests/resources/submain/install_rdf.jar') as pkg:
        submain.test_package(err, pkg, pkg.name, PACKAGE_ANY)

    assert submain.test_inner_package.called
    assert not err.failed()
    assert err.get_resource('has_install_rdf')
Exemplo n.º 12
0
def test_jar_subpackage_bad():
    "Tests JAR files that are bad subpackages."

    err = ErrorBundle()
    mock_package = MockXPI(
        {"chrome/subpackage.jar": "tests/resources/content/junk.xpi"})

    result = content.test_packed_packages(err, mock_package)
    print result
    assert err.failed()
Exemplo n.º 13
0
def test_list_locales():
    "Tests that the appropriate locales are listed for a package"

    err = ErrorBundle()
    assert _list_locales(err) is None

    err.save_resource(
        "chrome.manifest",
        MockManifest([("locale", "foo", "bar"), ("locale", "abc", "def")]))
    assert len(_list_locales(err)) == 2

    err = ErrorBundle()
    result = _list_locales(
        err,
        MockXPI({
            "chrome.manifest":
            "tests/resources/chromemanifest/chrome.manifest"
        }))
    assert result
Exemplo n.º 14
0
def test_list_locales():
    'Tests that the appropriate locales are listed for a package'

    err = ErrorBundle()
    assert _list_locales(err) is None

    err.save_resource(
        'chrome.manifest',
        MockManifest([('locale', 'foo', 'bar'), ('locale', 'abc', 'def')]))
    assert len(_list_locales(err)) == 2

    err = ErrorBundle()
    result = _list_locales(
        err,
        MockXPI({
            'chrome.manifest':
            'tests/resources/chromemanifest/chrome.manifest'
        }))
    assert result
Exemplo n.º 15
0
def test_unsigned_xpi():
    """Test that unsigned packages don't raise warning"""
    x = MockXPI()

    err = ErrorBundle()
    err.supported_versions = {}

    content.test_signed_xpi(err, x)

    assert not err.failed()
def _do_test_raw(rdf, listed=True, overrides=None):
    err = ErrorBundle(listed=listed)
    err.overrides = overrides
    rdf = RDFParser(err, rdf.strip())
    err.save_resource("has_install_rdf", True)
    err.save_resource("install_rdf", rdf)

    targetapp.test_targetedapplications(err)
    print err.print_summary()
    return err
def test_doctype():
    "Asserts that install.rdf files with doctypes break validation"

    err = ErrorBundle()
    xpi = MockXPIManager(
            {"install.rdf": "tests/resources/installrdf/doctype.rdf"})
    submain._load_install_rdf(err, xpi, None)
    assert err.failed()
    assert not err.get_resource("has_install_rdf")
    assert not err.get_resource("install_rdf")
Exemplo n.º 18
0
 def test(versions):
     err = ErrorBundle()
     err.supported_versions = versions
     parser = MarkupParser(err)
     parser.process(name,
                    data,
                    name.split(".")[-1])
     print err.print_summary(verbose=True)
     assert not err.failed()
     return err
Exemplo n.º 19
0
def test_packed_scripts_ignored_no_scripts():
    """Test that packed scripts are not tested when there are no scripts."""

    x = MockXPI({'foo.js': 'tests/resources/content/one_error.js'})

    err = ErrorBundle()
    err.supported_versions = {}

    content.test_packed_scripts(err, x)
    assert not err.failed()
Exemplo n.º 20
0
def test_valid_chrome_manifest():
    'Chrome manifests must only contain certain elements'

    err = ErrorBundle()
    err.save_resource('chrome.manifest', ChromeManifest('locale foo bar', ''))
    langpack.test_langpack_manifest(err, MockXPI())
    assert not err.failed()

    err.save_resource('chrome.manifest', ChromeManifest('foo bar asdf', ''))
    langpack.test_langpack_manifest(err, MockXPI())
    assert err.failed()
Exemplo n.º 21
0
def test_validate_libs_in_compat_mode():
    xpi = "tests/resources/libraryblacklist/addon_with_mootools.xpi"
    with open(xpi) as data:
        package = XPIManager(data, mode="r", name="addon_with_mootools.xpi")
        err = ErrorBundle(for_appversions=FX9_DEFINITION)
        test_content.test_packed_packages(err, package)
    assert err.get_resource("scripts"), (
        "expected mootools scripts to be marked for proessing")
    eq_(
        err.get_resource("scripts")[0]["scripts"],
        set(["content/mootools.js"]))
Exemplo n.º 22
0
def test_valid_chrome_manifest():
    "Chrome manifests must only contain certain elements"

    err = ErrorBundle()
    err.save_resource("chrome.manifest", ChromeManifest("locale foo bar", ""))
    langpack.test_langpack_manifest(err, MockXPI())
    assert not err.failed()

    err.save_resource("chrome.manifest", ChromeManifest("foo bar asdf", ""))
    langpack.test_langpack_manifest(err, MockXPI())
    assert err.failed()
Exemplo n.º 23
0
def test_validation_timeout():
    tp = submain.test_inner_package
    def slow(*args, **kw):
        time.sleep(1)
    submain.test_inner_package = slow
    err = ErrorBundle()
    submain.prepare_package(err, "tests/resources/main/foo.xpi",
                            timeout=0.1)
    submain.test_inner_package = tp

    assert len(err.errors) == 1
Exemplo n.º 24
0
def _do_test(url, failure=True, listed=False):
    err = ErrorBundle()
    results = detect_opensearch(err, open(url), listed=listed)

    if results.failed():
        print results.print_summary()

    if failure:
        assert err.failed(), 'Expected failure'
    else:
        assert not err.failed(), 'Expected pass'
Exemplo n.º 25
0
def test_prepare_package_extension(test_search):
    'Tests that bad extensions get outright rejections.'

    # Files with an invalid extension raise an error prior to
    # calling `test_search`.
    err = ErrorBundle()
    submain.prepare_package(err, 'foo/bar/test.foo')

    assert not test_search.called

    assert len(err.errors) == 1
    assert err.errors[0]['id'] == ('main', 'prepare_package', 'not_found')

    # Files which do not exist raise an error prior to calling `test_search`.
    err = ErrorBundle()
    submain.prepare_package(err, 'foo/bar/test.xml')

    assert not test_search.called
    assert len(err.errors) == 1
    assert err.errors[0]['id'] == ('main', 'prepare_package', 'not_found')
Exemplo n.º 26
0
def test_unsafe_html():
    'Tests for unsafe HTML in obstract files.'

    err = ErrorBundle(None, True)

    langpack.test_unsafe_html(
        err, None, """
    This is an <b>innocent</b> file.
    Nothing to <a href="#anchor">suspect</a> here.
    <img src="chrome://asdf/locale/asdf" />
    <tag href="#" />""")

    langpack.test_unsafe_html(err, None, "<tag href='foo' />")

    langpack.test_unsafe_html(err, None, "<tag src='foo' />")
    langpack.test_unsafe_html(err, None, "<tag src='/foo/bar' />")

    assert not err.failed()

    langpack.test_unsafe_html(
        err, 'asdf', """
    This is not an <script>innocent</script> file.""")
    assert err.failed()

    err = ErrorBundle()
    langpack.test_unsafe_html(
        err, 'asdf', """
    Nothing to <a href="http://foo.bar/">suspect</a> here.""")
    assert err.failed()

    err = ErrorBundle()
    langpack.test_unsafe_html(err, 'asdf', "src='data:foobar")
    assert err.failed()

    err = ErrorBundle()
    langpack.test_unsafe_html(err, 'asdf', "src='//remote/resource")
    assert err.failed()

    err = ErrorBundle()
    langpack.test_unsafe_html(err, 'asdf', 'href="ftp://foo.bar/')
    assert err.failed()
Exemplo n.º 27
0
def test_unsigned_inner_xpi():
    """Test that inner XPIs need to be signed even if not multi-package."""
    xpi = MockXPI(subpackage=True)

    err = ErrorBundle()
    err.supported_versions = {}
    err.push_state('inner.xpi')
    err.save_resource('is_multipackage', False)

    content.test_signed_xpi(err, xpi)

    assert err.failed()
def test_manifest_ordering():
    err = ErrorBundle(listed=True)
    manifest = ManifestJsonParser(err, INVALID_MANIFEST_JSON)
    err.save_resource('has_manifest_json', True)
    err.save_resource('manifest_json', manifest)
    rdf = RDFParser(err, VALID_INSTALL_RDF.strip())
    err.save_resource('has_install_rdf', True)
    err.save_resource('install_rdf', rdf)

    targetapp.test_targetedapplications(err)

    assert not err.failed()
Exemplo n.º 29
0
def test_skip_blacklisted_file():
    """Ensure blacklisted files are skipped for processing."""

    package_data = open('tests/resources/libraryblacklist/errors.xpi')
    package = XPIManager(package_data, mode='r', name='errors.xpi')
    err = ErrorBundle()

    test_content.test_packed_packages(err, package)

    print err.print_summary()
    assert err.notices
    assert not err.failed()
Exemplo n.º 30
0
def test_strange():
    """Tests that in install.rdf-less package is listed as being a
    dictionary type if it has an XPI extension and otherwise passes
    back a None object."""

    err = ErrorBundle(None, True)

    non_langpack = MockXPILangpack()
    langpack = MockXPILangpack(True)

    assert typedetection.detect_type(err, None, langpack) == PACKAGE_DICTIONARY
    assert typedetection.detect_type(err, None, non_langpack) is None