示例#1
0
    def test_whitelist(self):
        """Test that whitelisted files are properly skipped tested by the
        content validator."""

        self.setup_err()
        # Build a fake package with a js file that would not validate if it
        # wasn't whitelisted.
        mock_package = MockXPI({"foo.js": "tests/resources/content/error.js"})
        
        # Build the mock whitelist. Convert line-endings to unix-style before
        # building the hash, it should still validate properly as the code that
        # validates the package converts every js file to unix-style endings
        # first.
        ok_('\r\n' in mock_package.read('foo.js'))
        foo_js = mock_package.read('foo.js').replace('\r\n', '\n')
        hashes_whitelist = [hashlib.sha256(foo_js).hexdigest()]

        with patch("appvalidator.testcases.content.hashes_whitelist",
                   hashes_whitelist):
            eq_(self._run_test(mock_package), 0)
            self.assert_passes()

        # Prove that it would fail otherwise.
        eq_(self._run_test(mock_package), 1)
        self.assert_failed()
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()
示例#3
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()
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()
示例#5
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()
示例#6
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'
        ]))
示例#7
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'
        ]))
示例#8
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'])
示例#9
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()
示例#10
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()
示例#11
0
    def test_whitelist(self):
        """Test that whitelisted files are properly skipped tested by the
        content validator."""

        self.setup_err()
        # Build a fake package with a js file that would not validate if it
        # wasn't whitelisted.
        mock_package = MockXPI({"foo.js": "tests/resources/content/error.js"})
        # Build the mock whitelist.
        foo_js = mock_package.read('foo.js')
        hashes_whitelist = [hashlib.sha256(foo_js).hexdigest()]

        with patch("appvalidator.testcases.content.hashes_whitelist",
                   hashes_whitelist):
            eq_(self._run_test(mock_package), 0)
            self.assert_passes()

        # Prove that it would fail otherwise.
        eq_(self._run_test(mock_package), 1)
        self.assert_failed()
示例#12
0
    def test_whitelist(self):
        """Test that whitelisted files are properly skipped tested by the
        content validator."""

        self.setup_err()
        # Build a fake package with a js file that would not validate if it
        # wasn't whitelisted.
        mock_package = MockXPI({"foo.js": "tests/resources/content/error.js"})
        # Build the mock whitelist.
        foo_js = mock_package.read('foo.js')
        hashes_whitelist = [hashlib.sha256(foo_js).hexdigest()]

        with patch("appvalidator.testcases.content.hashes_whitelist",
                   hashes_whitelist):
            eq_(self._run_test(mock_package), 0)
            self.assert_passes()

        # Prove that it would fail otherwise.
        eq_(self._run_test(mock_package), 1)
        self.assert_failed()
示例#13
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
示例#14
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")
示例#15
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]