def test_marking_overlays():
    """
    Mark an overlay, then test that it marks the scripts within the overlay.
    """

    err = ErrorBundle()
    err.supported_versions = {}
    c = ChromeManifest("""
    content ns1 foo/
    overlay chrome://foo chrome://ns1/content/main.xul
    """, "chrome.manifest")
    err.save_resource("chrome.manifest", c)
    err.save_resource("chrome.manifest_nopush", c)

    xpi = MockXPI({"foo/main.xul": "tests/resources/content/script_list.xul"})

    content.test_packed_packages(err, xpi)
    assert not err.failed()

    marked_scripts = err.get_resource("marked_scripts")
    print marked_scripts
    assert marked_scripts

    eq_(marked_scripts, set(["chrome://ns1/foo.js",
                             "chrome://ns1/bar.js",
                             "chrome://asdf/foo.js"]))
Beispiel #2
0
def test_marking_overlays():
    """
    Mark an overlay, then test that it marks the scripts within the overlay.
    """

    err = ErrorBundle()
    err.supported_versions = {}
    c = chrome_manifest("""
    content ns1 foo/
    overlay chrome://foo chrome://ns1/content/main.xul
    """)
    err.save_resource('chrome.manifest', c)
    err.save_resource('chrome.manifest_nopush', c)

    xpi = MockXPI({'foo/main.xul': 'tests/resources/content/script_list.xul'})

    content.test_packed_packages(err, xpi)
    assert not err.failed()

    marked_scripts = err.get_resource('marked_scripts')

    eq_(
        marked_scripts,
        set([
            'chrome://ns1/foo.js', 'chrome://ns1/bar.js',
            'chrome://asdf/foo.js'
        ]))
 def test_structure(structure):
     err = ErrorBundle()
     err.supported_versions = {}
     mock_package = MockXPI(structure)
     content.test_packed_packages(err, mock_package)
     print err.print_summary(verbose=True)
     assert err.failed()
Beispiel #4
0
def test_blacklisted_files():
    """
    Tests the validator's ability to hash each individual file and (based on
    this information) determine whether the addon passes or fails the
    validation process.
    """

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

    test_content.test_packed_packages(err, package)

    print err.print_summary()

    assert err.notices
    assert not err.failed()
    eq_(
        err.metadata.get('identified_files'), {
            'test.js': {
                'path':
                'This file is a false script to facilitate '
                'testing of library blacklisting.'
            }
        })
Beispiel #5
0
 def test_structure(structure):
     err = ErrorBundle()
     err.supported_versions = {}
     mock_package = MockXPI(structure)
     content.test_packed_packages(err, mock_package)
     print err.print_summary(verbose=True)
     assert err.failed()
Beispiel #6
0
def test_marking_overlays_root_package():
    """
    Tests that '/' resolves correctly as a chrome content package.
    """

    err = ErrorBundle()
    err.supported_versions = {}
    manifest = chrome_manifest("""
    content ns1 /
    overlay chrome://foo chrome://ns1/content/main.xul
    """)
    err.save_resource('chrome.manifest', manifest)
    err.save_resource('chrome.manifest_nopush', manifest)

    xpi = MockXPI({'main.xul': 'tests/resources/content/script_list.xul'})

    content.test_packed_packages(err, xpi)
    assert not err.failed()

    marked_scripts = err.get_resource('marked_scripts')

    eq_(
        marked_scripts,
        set([
            'chrome://ns1/foo.js', 'chrome://ns1/bar.js',
            'chrome://asdf/foo.js'
        ]))
Beispiel #7
0
def test_marking_overlays_subdir():
    """
    Mark an overlay in a subdirectory, then test that it marks the scripts
    within the overlay. Make sure it properly figures out relative URLs.
    """

    err = ErrorBundle()
    err.supported_versions = {}
    c = ChromeManifest("""
    content ns1 foo/
    overlay chrome://foo chrome://ns1/content/subdir/main.xul
    """, 'chrome.manifest')
    err.save_resource('chrome.manifest', c)
    err.save_resource('chrome.manifest_nopush', c)

    xpi = MockXPI({'foo/subdir/main.xul':
                       'tests/resources/content/script_list.xul'})

    content.test_packed_packages(err, xpi)
    assert not err.failed()

    marked_scripts = err.get_resource('marked_scripts')
    print marked_scripts
    assert marked_scripts

    eq_(marked_scripts, set(['chrome://ns1/subdir/foo.js', 'chrome://ns1/bar.js',
                             'chrome://asdf/foo.js']))
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"]))
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()
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()
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')
        appversions = {FIREFOX_GUID: version_range('firefox',
                                                   '39.0a1', '39.*')}
        err = ErrorBundle(for_appversions=appversions)
        test_content.test_packed_packages(err, package)
    assert err.get_resource('scripts'), (
                    'expected mootools scripts to be marked for proessing')
    assert err.get_resource('scripts')[0]['scripts'] == set(['content/mootools.js'])
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"]))
def test_xpi_tiererror():
    'Tests that tiers are reset when a subpackage is encountered'

    err = ErrorBundle()
    mock_package = MockXPI(
        {'foo.xpi': 'tests/resources/content/subpackage.jar'})

    err.set_tier(2)
    content.test_packed_packages(err, mock_package)
    assert err.errors[0]['tier'] == 1
    assert err.tier == 2
    assert all(x == 1 for x in content.testendpoint_validator.found_tiers)
def test_jar_case():
    """Test that the capitalization of JARs is preserved."""

    err = ErrorBundle()
    mock_package = MockXPI(
        {'foo.JaR': 'tests/resources/packagelayout/ext_blacklist.xpi'})

    content.test_packed_packages(err, mock_package)

    assert err.failed()
    for message in err.errors + err.warnings:
        assert 'JaR' in message['file'][0]
def test_xpi_tiererror():
    'Tests that tiers are reset when a subpackage is encountered'

    err = ErrorBundle()
    mock_package = MockXPI(
        {'foo.xpi': 'tests/resources/content/subpackage.jar'})

    err.set_tier(2)
    content.test_packed_packages(err, mock_package)
    assert err.errors[0]['tier'] == 1
    assert err.tier == 2
    assert all(x == 1 for x in content.testendpoint_validator.found_tiers)
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()
Beispiel #17
0
def test_langpack():
    'Tests a language pack in the content validator.'

    err = ErrorBundle()
    err.supported_versions = {}
    err.detected_type = PACKAGE_LANGPACK
    mock_package = MockXPI({'foo.dtd': 'tests/resources/content/junk.xpi'})

    content.test_packed_packages(err, mock_package)
    content.testendpoint_langpack.assert_expectation('test_unsafe_html', 1)
    content.testendpoint_langpack.assert_expectation('test_unsafe_html', 0,
                                                     'subpackage')
Beispiel #18
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()
Beispiel #19
0
def test_jar_case():
    """Test that the capitalization of JARs is preserved."""

    err = ErrorBundle()
    mock_package = MockXPI(
        {"foo.JaR": "tests/resources/packagelayout/ext_blacklist.xpi"})

    content.test_packed_packages(err, mock_package)

    assert err.failed()
    for message in err.errors + err.warnings:
        assert "JaR" in message["file"][0]
Beispiel #20
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')
        appversions = {
            FIREFOX_GUID: version_range('firefox', '39.0a1', '39.*')
        }
        err = ErrorBundle(for_appversions=appversions)
        test_content.test_packed_packages(err, package)
    assert err.get_resource('scripts'), (
        'expected mootools scripts to be marked for proessing')
    assert err.get_resource('scripts')[0]['scripts'] == set(
        ['content/mootools.js'])
def test_xpi_subpackage():
    "XPIs should never be subpackages; only nested extensions"

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

    content.testendpoint_validator = \
        MockTestEndpoint(("test_package", ))

    result = content.test_packed_packages(
        err,
        mock_package)

    print result
    assert result == 1
    content.testendpoint_validator.assert_expectation(
        "test_package",
        1)
    content.testendpoint_validator.assert_expectation(
        "test_package",
        0,
        "subpackage")
def test_jar_nonsubpackage():
    "Tests XPI files that are not subpackages."

    err = ErrorBundle()
    err.set_type(PACKAGE_MULTI)
    err.save_resource("is_multipackage", True)
    mock_package = MockXPI(
        {"foo.jar":
             "tests/resources/content/subpackage.jar",
         "chrome/bar.jar":
             "tests/resources/content/subpackage.jar"})

    content.testendpoint_validator = MockTestEndpoint(("test_inner_package",
                                                       "test_package"))

    result = content.test_packed_packages(
                                    err,
                                    mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation(
                                    "test_package",
                                    2)
    content.testendpoint_validator.assert_expectation(
                                    "test_package",
                                    0,
                                    "subpackage")
Beispiel #23
0
def test_css():
    "Tests css files in the content validator."
    
    err = ErrorBundle(None, True)
    mock_package = MockXPIManager(
        {"foo.css":
             "tests/resources/content/junk.xpi"})
                        
    content.testendpoint_css = \
        MockTestEndpoint(("test_css_file", ))
    
    result = content.test_packed_packages(
                                    err,
                                    {"foo.css":
                                      {"extension": "css",
                                       "name_lower": "foo.css"}},
                                    mock_package)
    print result
    assert result == 1
    content.testendpoint_css.assert_expectation(
                                    "test_css_file",
                                    1)
    content.testendpoint_css.assert_expectation(
                                    "test_css_file",
                                    0,
                                    "subpackage")
Beispiel #24
0
def test_langpack():
    "Tests a language pack in the content validator."
    
    err = ErrorBundle(None, True)
    err.set_type(PACKAGE_LANGPACK)
    mock_package = MockXPIManager(
        {"foo.dtd":
             "tests/resources/content/junk.xpi"})
                        
    content.testendpoint_langpack = \
        MockTestEndpoint(("test_unsafe_html", ))
    
    result = content.test_packed_packages(
                                    err,
                                    {"foo.dtd":
                                      {"extension": "dtd",
                                       "name_lower": "foo.dtd"}},
                                    mock_package)
    print result
    assert result == 1
    content.testendpoint_langpack.assert_expectation(
                                    "test_unsafe_html",
                                    1)
    content.testendpoint_langpack.assert_expectation(
                                    "test_unsafe_html",
                                    0,
                                    "subpackage")
def test_jar_subpackage():
    "Tests JAR files that are subpackages."

    err = ErrorBundle()
    err.set_type(PACKAGE_EXTENSION)
    err.supported_versions = {"foo": ["1.2.3"]}
    mock_package = MockXPI(
        {"chrome/subpackage.jar":
             "tests/resources/content/subpackage.jar",
         "subpackage.jar":
             "tests/resources/content/subpackage.jar"})

    content.testendpoint_validator = \
        MockTestEndpoint(("test_inner_package", ))

    result = content.test_packed_packages(
                                    err,
                                    mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation(
                                    "test_inner_package",
                                    2)
    content.testendpoint_validator.assert_expectation(
                                    "test_inner_package",
                                    2,
                                    "subpackage")
    assert err.supported_versions == {"foo": ["1.2.3"]}
Beispiel #26
0
def test_markup():
    "Tests markup files in the content validator."
    
    err = ErrorBundle(None, True)
    mock_package = MockXPIManager(
        {"foo.xml":
             "tests/resources/content/junk.xpi"})
                        
    content.testendpoint_markup = \
        MockMarkupEndpoint(("process", ))
    
    result = content.test_packed_packages(
                                    err,
                                    {"foo.xml":
                                      {"extension": "xml",
                                       "name_lower": "foo.xml"}},
                                    mock_package)
    print result
    assert result == 1
    content.testendpoint_markup.assert_expectation(
                                    "process",
                                    1)
    content.testendpoint_markup.assert_expectation(
                                    "process",
                                    0,
                                    "subpackage")
Beispiel #27
0
def test_jar_subpackage():
    "Tests JAR files that are subpackages."
    
    err = ErrorBundle(None, True)
    mock_package = MockXPIManager(
        {"chrome/subpackage.jar":
             "tests/resources/content/subpackage.jar",
         "nonsubpackage.jar":
             "tests/resources/content/subpackage.jar"})
                        
    content.testendpoint_validator = \
        MockTestEndpoint(("test_inner_package", ))
    
    result = content.test_packed_packages(
                                    err,
                                    {"chrome/subpackage.jar":
                                      {"extension": "jar",
                                       "name_lower": "subpackage.jar"},
                                     "nonsubpackage.jar":
                                      {"extension": "jar",
                                       "name_lower": "subpackage.jar"},
                                       },
                                    mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation(
                                    "test_inner_package",
                                    2)
    content.testendpoint_validator.assert_expectation(
                                    "test_inner_package",
                                    1,
                                    "subpackage")
Beispiel #28
0
def test_xpi_nonsubpackage():
    "Tests XPI files that are not subpackages."
    
    err = ErrorBundle(None, True)
    mock_package = MockXPIManager(
        {"foo.xpi":
             "tests/resources/content/subpackage.jar"})
                        
    content.testendpoint_validator = \
        MockTestEndpoint(("test_package", ))
    
    result = content.test_packed_packages(
                                    err,
                                    {"foo.xpi":
                                      {"extension": "xpi",
                                       "name_lower": "foo.xpi"}},
                                    mock_package)
    print result
    assert result == 1
    content.testendpoint_validator.assert_expectation(
                                    "test_package",
                                    1)
    content.testendpoint_validator.assert_expectation(
                                    "test_package",
                                    0,
                                    "subpackage")
def test_blacklisted_files():
    """
    Tests the validator's ability to hash each individual file and (based on
    this information) determine whether the addon passes or fails the
    validation process.
    """

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

    test_content.test_packed_packages(err, package)

    print err.print_summary()

    assert err.notices
    assert not err.failed()
def test_hidden_files():
    """Tests that hidden files are reported."""

    err = ErrorBundle()
    err.supported_versions = {}
    mock_package = MockXPI({".hidden": "tests/resources/content/junk.xpi"})

    content.test_packed_packages(err, mock_package)
    print err.print_summary(verbose=True)
    assert err.failed()

    err = ErrorBundle()
    mock_package_mac = MockXPI({"dir/__MACOSX/foo":
                                          "tests/resources/content/junk.xpi"})
    content.test_packed_packages(err, mock_package_mac)
    print err.print_summary(verbose=True)
    assert err.failed()
def test_password_in_defaults_prefs():
    """
    Tests that passwords aren't stored in the defaults/preferences/*.js files
    for bug 647109.
    """

    password_js = open("tests/resources/content/password.js").read()
    assert not _do_test_raw(password_js).failed()

    err = ErrorBundle()
    err.supported_versions = {}
    mock_package = MockXPI({"defaults/preferences/foo.js":
                                "tests/resources/content/password.js"})

    content.test_packed_packages(err, mock_package)
    print err.print_summary()
    assert err.failed()
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')
Beispiel #33
0
def test_subpackage_metadata_preserved():
    """Tests that metadata is preserved for sub-packages."""

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

    err1 = ErrorBundle()
    err1.detected_type = PACKAGE_EXTENSION

    err2 = ErrorBundle()
    err2.detected_type = PACKAGE_EXTENSION

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

    assert "sub_packages" in err2.metadata
    eq_(err1.metadata, err2.metadata["sub_packages"].get("thing.xpi"))
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_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()
def test_subpackage_metadata_preserved():
    """Tests that metadata is preserved for sub-packages."""

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

    err1 = ErrorBundle()
    err1.detected_type = PACKAGE_EXTENSION

    err2 = ErrorBundle()
    err2.detected_type = PACKAGE_EXTENSION

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

    assert "sub_packages" in err2.metadata
    eq_(err1.metadata, err2.metadata["sub_packages"]
                           .get("thing.xpi"))
Beispiel #37
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()
def test_blacklisted_files():
    """
    Tests the validator's ability to hash each individual file and (based on
    this information) determine whether the addon passes or fails the
    validation process.
    """

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

    test_content.test_packed_packages(err, package)

    print err.print_summary()

    assert err.notices
    assert not err.failed()
    eq_(err.metadata.get("identified_files"),
        {'test.js': {'path': 'This file is a false script to facilitate '
                             'testing of library blacklisting.'}})
def test_script_scraping():
    """Test that scripts are gathered up during the validation process."""

    err = ErrorBundle()
    err.supported_versions = {}
    xpi = MockXPI({"foo.js": "tests/resources/junk.xpi",
                   "dir/bar.jsm": "tests/resources/junk.xpi"})

    content.test_packed_packages(err, xpi)
    assert not err.failed()

    scripts = err.get_resource("scripts")
    print scripts
    assert scripts

    for bundle in scripts:
        assert "foo.js" in bundle["scripts"]
        assert "dir/bar.jsm" in bundle["scripts"]
        eq_(bundle["package"], xpi)
        eq_(bundle["state"], [])
Beispiel #40
0
def test_script_scraping():
    """Test that scripts are gathered up during the validation process."""

    err = ErrorBundle()
    err.supported_versions = {}
    xpi = MockXPI({'foo.js': 'tests/resources/junk.xpi',
                   'dir/bar.jsm': 'tests/resources/junk.xpi'})

    content.test_packed_packages(err, xpi)
    assert not err.failed()

    scripts = err.get_resource('scripts')
    print scripts
    assert scripts

    for bundle in scripts:
        assert 'foo.js' in bundle['scripts']
        assert 'dir/bar.jsm' in bundle['scripts']
        eq_(bundle['package'], xpi)
        eq_(bundle['state'], [])
def test_markup():
    "Tests markup files in the content validator."

    err = ErrorBundle()
    err.supported_versions = {}
    mock_package = MockXPI({"foo.xml": "tests/resources/content/junk.xpi"})

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 1
    content.testendpoint_markup.assert_expectation("process", 1)
    content.testendpoint_markup.assert_expectation("process", 0, "subpackage")
def test_markup():
    'Tests markup files in the content validator.'

    err = ErrorBundle()
    err.supported_versions = {}
    mock_package = MockXPI({'foo.xml': 'tests/resources/content/junk.xpi'})

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 1
    content.testendpoint_markup.assert_expectation('process', 1)
    content.testendpoint_markup.assert_expectation('process', 0, 'subpackage')
Beispiel #43
0
def test_xpi_tiererror():
    "Tests that tiers are reset when a subpackage is encountered"

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

    err.set_tier(2)
    result = content.test_packed_packages(err, mock_package)
    assert err.errors[0]["tier"] == 1
    assert err.tier == 2
    assert all(x == 1 for x in content.testendpoint_validator.found_tiers)
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"})

    content.testendpoint_validator = MockTestEndpoint(("test_inner_package", ))

    result = content.test_packed_packages(err, mock_package)
    print result
    assert err.failed()
Beispiel #45
0
def test_markup():
    "Tests markup files in the content validator."

    err = ErrorBundle()
    err.supported_versions = {}
    mock_package = MockXPI({"foo.xml": "tests/resources/content/junk.xpi"})

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 1
    content.testendpoint_markup.assert_expectation("process", 1)
    content.testendpoint_markup.assert_expectation("process", 0, "subpackage")
def test_markup():
    'Tests markup files in the content validator.'

    err = ErrorBundle()
    err.supported_versions = {}
    mock_package = MockXPI({'foo.xml': 'tests/resources/content/junk.xpi'})

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 1
    content.testendpoint_markup.assert_expectation('process', 1)
    content.testendpoint_markup.assert_expectation('process', 0, 'subpackage')
Beispiel #47
0
def test_langpack():
    "Tests a language pack in the content validator."

    err = ErrorBundle()
    err.supported_versions = {}
    err.detected_type = PACKAGE_LANGPACK
    mock_package = MockXPI({"foo.dtd": "tests/resources/content/junk.xpi"})

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 1
    content.testendpoint_langpack.assert_expectation("test_unsafe_html", 1)
    content.testendpoint_langpack.assert_expectation("test_unsafe_html", 0,
                                                     "subpackage")
def test_marking_overlays_no_overlay():
    """
    Test that unmarked overlays don't mark scripts as being potentially
    pollutable.
    """

    err = ErrorBundle()
    err.supported_versions = {}
    c = ChromeManifest("""
    content ns1 foo/
    #overlay chrome://foo chrome://ns1/main.xul
    """, "chrome.manifest")
    err.save_resource("chrome.manifest", c)
    err.save_resource("chrome.manifest_nopush", c)

    xpi = MockXPI({"foo/main.xul": "tests/resources/content/script_list.xul"})

    content.test_packed_packages(err, xpi)
    assert not err.failed()

    marked_scripts = err.get_resource("marked_scripts")
    print marked_scripts
    assert not marked_scripts
Beispiel #49
0
def test_xpi_subpackage():
    "XPIs should never be subpackages; only nested extensions"

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

    result = content.test_packed_packages(err, mock_package)

    print result
    assert result == 1
    content.testendpoint_validator.assert_expectation("test_package", 1)
    content.testendpoint_validator.assert_expectation("test_package", 0,
                                                      "subpackage")
Beispiel #50
0
def test_jar_nonsubpackage():
    "Tests XPI files that are not subpackages."

    err = ErrorBundle()
    err.detected_type = PACKAGE_MULTI
    err.save_resource("is_multipackage", True)
    mock_package = MockXPI({
        "foo.jar":
        "tests/resources/content/subpackage.jar",
        "chrome/bar.jar":
        "tests/resources/content/subpackage.jar"
    })

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation("test_package", 2)
    content.testendpoint_validator.assert_expectation("test_package", 0,
                                                      "subpackage")
def test_jar_nonsubpackage():
    'Tests XPI files that are not subpackages.'

    err = ErrorBundle()
    err.detected_type = PACKAGE_MULTI
    err.save_resource('is_multipackage', True)
    mock_package = MockXPI({
        'foo.jar':
        'tests/resources/content/subpackage.jar',
        'chrome/bar.jar':
        'tests/resources/content/subpackage.jar'
    })

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation('test_package', 2)
    content.testendpoint_validator.assert_expectation('test_package', 0,
                                                      'subpackage')
Beispiel #52
0
def test_jar_subpackage():
    "Tests JAR files that are subpackages."

    err = ErrorBundle()
    err.detected_type = PACKAGE_EXTENSION
    err.supported_versions = {"foo": ["1.2.3"]}
    mock_package = MockXPI({
        "chrome/subpackage.jar":
        "tests/resources/content/subpackage.jar",
        "subpackage.jar":
        "tests/resources/content/subpackage.jar"
    })

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation("test_inner_package", 2)
    content.testendpoint_validator.assert_expectation("test_inner_package", 2,
                                                      "subpackage")
    assert err.supported_versions == {"foo": ["1.2.3"]}
def test_jar_subpackage():
    'Tests JAR files that are subpackages.'

    err = ErrorBundle()
    err.detected_type = PACKAGE_EXTENSION
    err.supported_versions = {'foo': ['1.2.3']}
    mock_package = MockXPI({
        'chrome/subpackage.jar':
        'tests/resources/content/subpackage.jar',
        'subpackage.jar':
        'tests/resources/content/subpackage.jar'
    })

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation('test_inner_package', 2)
    content.testendpoint_validator.assert_expectation('test_inner_package', 2,
                                                      'subpackage')
    assert err.supported_versions == {'foo': ['1.2.3']}