Exemple #1
0
def test_packed_scripts_pollution():
    """Test that packed scripts test for pollution properly."""

    x = MockXPI({"foo/bar.js": "tests/resources/content/pollution_error.js"})

    err = ErrorBundle()
    err.supported_versions = {}

    c = ChromeManifest("""
    content ns jar:subpackage.jar!/
    """, "chrome.manifest")

    err.save_resource("chrome.manifest_nopush", c, pushable=False)

    err.save_resource(
        "scripts",
        [{"scripts": ["foo/bar.js"],
          "package": x,
          "state": ["subpackage.jar", "subsubpackage"]}])
    err.save_resource("marked_scripts", set(["chrome://ns/foo/bar.js"]))

    content.test_packed_scripts(err, x)

    eq_(err.package_stack, [])

    assert err.failed()
    assert err.warnings
    assert not err.errors

    eq_(err.warnings[0]["file"],
        ['subpackage.jar', 'subsubpackage', 'foo/bar.js'])
Exemple #2
0
def test_packed_scripts_pollution():
    """Test that packed scripts test for pollution properly."""

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

    err = ErrorBundle()
    err.supported_versions = {}

    c = ChromeManifest("""
    content ns jar:subpackage.jar!/
    """, 'chrome.manifest')

    err.save_resource('chrome.manifest_nopush', c, pushable=False)

    err.save_resource('scripts', [{
        'scripts': ['foo/bar.js'],
        'package': x,
        'state': ['subpackage.jar', 'subsubpackage']
    }])
    err.save_resource('marked_scripts', set(['chrome://ns/foo/bar.js']))

    content.test_packed_scripts(err, x)

    eq_(err.package_stack, [])

    assert err.failed()
    assert err.warnings
    assert not err.errors

    eq_(err.warnings[0]['file'],
        ['subpackage.jar', 'subsubpackage', 'foo/bar.js'])
Exemple #3
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'
        ]))
Exemple #4
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 = chrome_manifest("""
    content ns1 foo/
    overlay chrome://foo chrome://ns1/content/subdir/main.xul
    """)
    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_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()
Exemple #6
0
def test_packed_scripts_no_pollution():
    """
    Test that packed scripts test for pollution without being overzealous.
    """

    x = MockXPI({"foo/bar.js": "tests/resources/content/pollution_error.js"})

    err = ErrorBundle()
    err.supported_versions = {}

    c = ChromeManifest("""
    content ns jar:subpackage.jar!/
    """, "chrome.manifest")

    err.save_resource("chrome.manifest_nopush", c, pushable=False)

    err.save_resource(
        "scripts",
        [{"scripts": ["foo/bar.js"],
          "package": x,
          "state": ["subpackage", "subsubpackage"]}])
    err.save_resource("marked_scripts", set(["chrome://otherns/foo/bar.js"]))

    content.test_packed_scripts(err, x)

    eq_(err.package_stack, [])

    assert not err.failed()
Exemple #7
0
def test_godlikea():
    """Test that packages with a godlikea chrome namespaceget rejected."""

    err = ErrorBundle()
    xpi = MockXPI({"chrome/godlikea.jar": True})
    packagelayout.test_godlikea(err, xpi)
    assert err.failed()
    assert err.errors
Exemple #8
0
    def test_too_much_garbage(self):
        """Tests that hidden files are reported."""
        self.setup_err()
        mock_package = MockXPI(
            {".junky": "tests/resources/content/junk.xpi"},
            default_size=50 * 1024)

        content.test_packed_packages(self.err, mock_package)
        self.assert_failed(with_warnings=True)

        mock_package = MockXPI(
            {".junky": "tests/resources/content/junk.xpi",
             ".morejunk": "tests/resources/content/junk.xpi",},
            default_size=50 * 1024)

        content.test_packed_packages(self.err, mock_package)
        self.assert_failed(with_warnings=True, with_errors=True)
 def test_structure(structure):
     self.setup_err()
     mock_package = MockXPI(
         dict([(structure, "tests/resources/content/junk.xpi")]))
     content.test_packed_packages(self.err, mock_package)
     print structure
     print self.err.print_summary(verbose=True)
     self.assert_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_markup(self):
        "Tests markup files in the content validator."
        self.setup_err()
        mock_package = MockXPI({"foo.xml": "tests/resources/content/junk.xpi"})

        eq_(self._run_test(mock_package), 1)
        content.testendpoint_markup.assert_expectation("process", 1)
        content.testendpoint_markup.assert_expectation("process", 0,
                                                       "subpackage")
Exemple #12
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()
Exemple #13
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 test_css(self):
        "Tests css files in the content validator."

        self.setup_err()
        mock_package = MockXPI({"foo.css": "tests/resources/content/junk.xpi"})

        eq_(self._run_test(mock_package), 1)
        content.testendpoint_css.assert_expectation("test_css_file", 1)
        content.testendpoint_css.assert_expectation("test_css_file", 0,
                                                    "subpackage")
Exemple #15
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_js(self):
        """Test that JS files are properly tested in the content validator."""

        self.setup_err()
        mock_package = MockXPI({"foo.js": "tests/resources/content/junk.xpi"})

        eq_(self._run_test(mock_package), 1)
        content.testendpoint_js.assert_expectation("test_js_file", 1)
        content.testendpoint_js.assert_expectation("test_js_file", 0,
                                                   "subpackage")
def test_get_manager():
    'Tests that the proper XPI manager is returned for a locale description'

    # Test that jarred packages are simply returned
    assert _get_locale_manager(None, 'foo', {'jarred': False}) == 'foo'

    # Test that cached unjarred packages are fetched from the cache
    l10ncomp.LOCALE_CACHE = {'foo': 'bar'}
    assert _get_locale_manager(None, None, {
        'jarred': True,
        'path': 'foo'
    }) == 'bar'

    # Test that when a broken path is referenced, a warning is thrown
    l10ncomp.LOCALE_CACHE = {}
    err = ErrorBundle()
    assert _get_locale_manager(err, MockXPI(), {
        'jarred': True,
        'path': 'foo'
    }) is None
    assert err.failed()
    assert not l10ncomp.LOCALE_CACHE

    # Save the XPIManager that the L10n module is using and replace it
    xm = l10ncomp.XPIManager
    l10ncomp.XPIManager = MockManager

    # Test that the appropriate XPI is returned for a given input
    l10ncomp.LOCALE_CACHE = {}
    err = ErrorBundle()
    xpi = MockManager('testcase1')
    print xpi.read('bar.jar')
    result = _get_locale_manager(err, xpi, {'jarred': True, 'path': 'bar.jar'})
    assert isinstance(result, MockManager)
    print result.value
    assert result.value == 'bar.jar:testcase1'
    assert result.path == 'bar.jar'
    assert l10ncomp.LOCALE_CACHE['bar.jar'] == result

    # Test that no_cache works
    l10ncomp.LOCALE_CACHE = {}
    err = ErrorBundle()
    xpi = MockManager('testcase2')
    result = _get_locale_manager(err,
                                 xpi, {
                                     'jarred': True,
                                     'path': 'foo.jar'
                                 },
                                 no_cache=True)
    assert not l10ncomp.LOCALE_CACHE

    # Restore everything to normal
    l10ncomp.LOCALE_CACHE = {}
    l10ncomp.XPIManager = xm
Exemple #18
0
def test_get_manager():
    "Tests that the proper XPI manager is returned for a locale description"

    # Test that jarred packages are simply returned
    assert _get_locale_manager(None, "foo", {"jarred": False}) == "foo"

    # Test that cached unjarred packages are fetched from the cache
    l10ncomp.LOCALE_CACHE = {"foo": "bar"}
    assert _get_locale_manager(None, None, {
        "jarred": True,
        "path": "foo"
    }) == "bar"

    # Test that when a broken path is referenced, a warning is thrown
    l10ncomp.LOCALE_CACHE = {}
    err = ErrorBundle()
    assert _get_locale_manager(err, MockXPI(), {
        "jarred": True,
        "path": "foo"
    }) is None
    assert err.failed()
    assert not l10ncomp.LOCALE_CACHE

    # Save the XPIManager that the L10n module is using and replace it
    xm = l10ncomp.XPIManager
    l10ncomp.XPIManager = MockManager

    # Test that the appropriate XPI is returned for a given input
    l10ncomp.LOCALE_CACHE = {}
    err = ErrorBundle()
    xpi = MockManager("testcase1")
    print xpi.read("bar.jar")
    result = _get_locale_manager(err, xpi, {"jarred": True, "path": "bar.jar"})
    assert isinstance(result, MockManager)
    print result.value
    assert result.value == "bar.jar:testcase1"
    assert result.path == "bar.jar"
    assert l10ncomp.LOCALE_CACHE["bar.jar"] == result

    # Test that no_cache works
    l10ncomp.LOCALE_CACHE = {}
    err = ErrorBundle()
    xpi = MockManager("testcase2")
    result = _get_locale_manager(err,
                                 xpi, {
                                     "jarred": True,
                                     "path": "foo.jar"
                                 },
                                 no_cache=True)
    assert not l10ncomp.LOCALE_CACHE

    # Restore everything to normal
    l10ncomp.LOCALE_CACHE = {}
    l10ncomp.XPIManager = xm
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)
Exemple #20
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]
Exemple #21
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_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')
Exemple #23
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_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')
Exemple #25
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)
Exemple #26
0
def test_java_jar_detection():
    """
    Test that Java archives are flagged as such so that they do not generate
    hundreds or thousands of errors.
    """

    classes = ("c%d.class" % i for i in xrange(1000))
    mock_xpi = MockXPI(dict(zip(classes, repeat(""))))
    err = ErrorBundle(None, True)
    packagelayout.test_blacklisted_files(err, mock_xpi)

    assert not err.failed()
    assert err.notices
Exemple #27
0
def test_populate_chrome_manifest():
    """Ensure that the chrome manifest is populated if available."""

    err = MockErrorHandler(None)
    package_contents = {"chrome.manifest":
            "tests/resources/chromemanifest/chrome.manifest"}
    package = MockXPI(package_contents)

    submain.populate_chrome_manifest(err, MockXPI())
    assert not err.pushable_resources

    submain.populate_chrome_manifest(err, package)
    assert err.pushable_resources
    assert "chrome.manifest" in err.pushable_resources
    print err.pushable_resources
    assert isinstance(err.pushable_resources["chrome.manifest"],
                      ChromeManifest)

    assert err.resources
    assert "chrome.manifest_nopush" in err.resources
    print err.resources
    assert isinstance(err.resources["chrome.manifest_nopush"], ChromeManifest)
Exemple #28
0
def test_unsigned_inner_jar():
    """Test that inner packages don't need to be signed if not multipackage."""
    xpi = MockXPI(subpackage=True)
    xpi.filename = 'mock_jar.jar'

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

    content.test_signed_xpi(err, xpi)

    assert not err.failed()
Exemple #29
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")
Exemple #30
0
def _do_test(unpack=False, contents=None, set_type=0, is_ff4=False):
    "Runs the tests. Handy as hell."

    if not contents:
        contents = []

    err = ErrorBundle(None, True)
    if set_type:
        err.detected_type = set_type
    err.save_resource("em:unpack", unpack)
    err.save_resource("ff4", is_ff4)
    packagelayout.test_emunpack(
        err, MockXPI(dict(zip(contents, [True for c in contents]))))
    return err